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