Skip to content

Commit

Permalink
move openAI instantiation back outside do while loop
Browse files Browse the repository at this point in the history
  • Loading branch information
pmarsh-scottlogic committed Feb 19, 2024
1 parent 241d42c commit dff646f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions backend/src/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ async function chatGptCallFunction(

async function chatGptChatCompletion(
chatHistory: ChatMessage[],
chatModel: ChatModel
chatModel: ChatModel,
openAI: OpenAI
) {
const updatedChatHistory = [...chatHistory];

Expand All @@ -250,7 +251,7 @@ async function chatGptChatCompletion(
console.debug('Calling OpenAI chat completion...');

try {
const chat_completion = await getOpenAI().chat.completions.create({
const chat_completion = await openAI.chat.completions.create({
model: chatModel.id,
temperature: chatModel.configuration.temperature,
top_p: chatModel.configuration.topP,
Expand Down Expand Up @@ -366,9 +367,13 @@ async function getFinalReplyAfterAllToolCalls(
let wonLevel = false;

let gptReply: ChatGptReply | null = null;

const openAI = getOpenAI();
do {
gptReply = await chatGptChatCompletion(updatedChatHistory, chatModel);
gptReply = await chatGptChatCompletion(
updatedChatHistory,
chatModel,
openAI
);
updatedChatHistory = gptReply.chatHistory;

if (gptReply.completion?.tool_calls) {
Expand Down

0 comments on commit dff646f

Please sign in to comment.