From 91f1918b734d0291d43fe3b5009f40067c6dd4d4 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 26 Apr 2023 21:27:58 +0900 Subject: [PATCH] test: improve test data for better results --- src/utils/openai.ts | 12 ++++++++---- tests/utils.ts | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/utils/openai.ts b/src/utils/openai.ts index 8c5c449..2cdfc0d 100644 --- a/src/utils/openai.ts +++ b/src/utils/openai.ts @@ -104,7 +104,11 @@ const sanitizeMessage = (message: string) => message.trim().replace(/[\n\r]/g, ' const deduplicateMessages = (array: string[]) => Array.from(new Set(array)); -const getPrompt = (locale: string, diff: string, length: number) => `Write a git commit message in present tense for the following diff without prefacing it with anything. Do not be needlessly verbose and make sure the answer is concise and to the point. The response must be no longer than ${length} characters. The response must be in the language ${locale}:\n${diff}`; +const getPrompt = ( + locale: string, + diff: string, + maxLength: number, +) => `Write a git commit message in present tense for the following diff without prefacing it with anything. Do not be needlessly verbose and make sure the answer is concise and to the point. The response must be no longer than ${maxLength} characters. The response must be in the language ${locale}:\n${diff}`; const generateStringFromLength = (length: number) => { let result = ''; @@ -129,14 +133,14 @@ export const generateCommitMessage = async ( locale: string, diff: string, completions: number, - length: number, + maxLength: number, timeout: number, proxy?: string, ) => { - const prompt = getPrompt(locale, diff, length); + const prompt = getPrompt(locale, diff, maxLength); // Padded by 5 for more room for the completion. - const stringFromLength = generateStringFromLength(length + 5); + const stringFromLength = generateStringFromLength(maxLength + 5); // The token limit is shared between the prompt and the completion. const maxTokens = getTokens(stringFromLength + prompt, model); diff --git a/tests/utils.ts b/tests/utils.ts index 12df58f..2359141 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -75,7 +75,7 @@ export const createFixture = async ( export const files = Object.freeze({ '.aicommits': `OPENAI_KEY=${process.env.OPENAI_KEY}`, - 'data.json': 'Lorem ipsum dolor sit amet '.repeat(10), + 'data.json': Array.from({ length: 10 }, (_, i) => `${i}. Lorem ipsum dolor sit amet`).join('\n'), }); export const assertOpenAiToken = () => {