Skip to content

Commit

Permalink
Merge pull request #70 from shin202/hotfix/migration-openai-v3-to-v4
Browse files Browse the repository at this point in the history
migration openai from v3 to v4
  • Loading branch information
shin202 authored Sep 24, 2023
2 parents 2a965b8 + 45217e6 commit 79a755f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/services/ChatGPTService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {ChatCompletionRequestMessage, Configuration, OpenAIApi} from "openai";
import OpenAi from "openai";
import {Chat} from "openai/resources";
import ChatCompletionMessageParam = Chat.ChatCompletionMessageParam;
import MessageController from "../controllers/MessageController";
import {ChatMode, IChatModes, IUserModel} from "../types/types";

Expand Down Expand Up @@ -39,12 +41,11 @@ class ChatGPTService {

const oldMessages = await MessageController.getUserMessage(user, chatMode);

const configuration = new Configuration({
const openAi = new OpenAi({
apiKey: OPENAI_KEY,
});

const openai = new OpenAIApi(configuration);
const messages: ChatCompletionRequestMessage[] = [
const messages: ChatCompletionMessageParam[] = [
{role: "system", content: `${this.CHAT_MODES[chatMode].rolePlayDescription}`}
]

Expand All @@ -58,18 +59,18 @@ class ChatGPTService {
}

messages.push(
{ role: "user", content: message }
{role: "user", content: message}
);

const completion = await openai.createChatCompletion({
const completion = await openAi.chat.completions.create({
model: "gpt-3.5-turbo",
messages: messages,
temperature: 0.2,
top_p: 1,
max_tokens: 1000,
})
});

return completion.data.choices[0]?.message?.content!;
return completion.choices[0].message.content!;
}
}

Expand Down

2 comments on commit 79a755f

@MaelHan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Got this error friend !

@shin202
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Got this error friend !
Using "git pull" command to get the latest codes, don't modify it manually.

Please sign in to comment.