* 🐛 fix(api.ts): return message content instead of whole response object
* 🚀 chore(generateCommitMessageFromGitDiff.ts): filter out null promises and update TODO comment * 🚀 chore(tsconfig.json): update target to ES2020 and remove ES5 from lib
This commit is contained in:
+2
-3
@@ -1,7 +1,6 @@
|
||||
import { intro, outro } from '@clack/prompts';
|
||||
import {
|
||||
ChatCompletionRequestMessage,
|
||||
ChatCompletionResponseMessage,
|
||||
Configuration as OpenAiApiConfiguration,
|
||||
OpenAIApi
|
||||
} from 'openai';
|
||||
@@ -43,7 +42,7 @@ class OpenAi {
|
||||
|
||||
public generateCommitMessage = async (
|
||||
messages: Array<ChatCompletionRequestMessage>
|
||||
): Promise<ChatCompletionResponseMessage | undefined> => {
|
||||
): Promise<string | undefined> => {
|
||||
try {
|
||||
const { data } = await this.openAI.createChatCompletion({
|
||||
model: 'gpt-3.5-turbo',
|
||||
@@ -55,7 +54,7 @@ class OpenAi {
|
||||
|
||||
const message = data.choices[0].message;
|
||||
|
||||
return message;
|
||||
return message?.content;
|
||||
} catch (error) {
|
||||
console.error('openAI api error', { error });
|
||||
throw error;
|
||||
|
||||
@@ -92,17 +92,18 @@ export const generateCommitMessageWithChatCompletion = async (
|
||||
|
||||
const diffByFiles = diff.split(separator).slice(1);
|
||||
|
||||
const commitMessagePromises = diffByFiles.map((fileDiff) => {
|
||||
// TODO: split by files
|
||||
if (INIT_MESSAGES_PROMPT_LENGTH + fileDiff.length >= MAX_REQ_TOKENS)
|
||||
return null;
|
||||
const commitMessagePromises = diffByFiles
|
||||
.map((fileDiff) => {
|
||||
// TODO: split by files
|
||||
if (fileDiff.length >= MAX_REQ_TOKENS) return null;
|
||||
|
||||
const messages = generateCommitMessageChatCompletionPrompt(
|
||||
separator + fileDiff
|
||||
);
|
||||
const messages = generateCommitMessageChatCompletionPrompt(
|
||||
separator + fileDiff
|
||||
);
|
||||
|
||||
return api.generateCommitMessage(messages);
|
||||
});
|
||||
return api.generateCommitMessage(messages);
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
const commitMessages = await Promise.all(commitMessagePromises);
|
||||
|
||||
@@ -116,7 +117,7 @@ export const generateCommitMessageWithChatCompletion = async (
|
||||
if (!commitMessage)
|
||||
return { error: GenerateCommitMessageErrorEnum.emptyMessage };
|
||||
|
||||
return commitMessage.content;
|
||||
return commitMessage;
|
||||
} catch (error) {
|
||||
return { error: GenerateCommitMessageErrorEnum.internalError };
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"target": "ES2020",
|
||||
"lib": ["ES5", "ES6"],
|
||||
|
||||
"module": "ESNext",
|
||||
|
||||
Reference in New Issue
Block a user