Skip to content

Commit 2794c31

Browse files
Merge pull request #160 from rijnb/main
Add debug info
2 parents 83e5b4f + 4feb248 commit 2794c31

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

utils/server/openAiClient.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export const ChatCompletionStream = async (
138138
reasoningEffort: string
139139
) => {
140140
const configuration = createOpenAiConfiguration(apiKey, modelId, dangerouslyAllowBrowser)
141-
const openai = createOpenAiClient(configuration)
141+
const openAiClient = createOpenAiClient(configuration)
142142

143143
if (messages.length === 0) {
144144
throw new Error("No messages in history")
@@ -148,8 +148,9 @@ export const ChatCompletionStream = async (
148148
const isReasoningModel = isOpenAIReasoningModel(modelId)
149149

150150
// Ask OpenAI for a streaming chat completion given the prompt
151+
console.debug(`Using ${currentHost === OPENAI_API_HOST ? "primary" : "backup"} host: ${currentHost}`)
151152
try {
152-
const response = await openai.chat.completions
153+
const response = await openAiClient.chat.completions
153154
.create({
154155
model: modelId,
155156
messages: [
@@ -185,11 +186,12 @@ export const ChatCompletionStream = async (
185186
switchToBackupHost()
186187

187188
// Retry the request with the backup host,
188-
const newConfiguration = createOpenAiConfiguration(apiKey, modelId, dangerouslyAllowBrowser)
189-
const newOpenai = createOpenAiClient(newConfiguration)
189+
const backupConfiguration = createOpenAiConfiguration(apiKey, modelId, dangerouslyAllowBrowser)
190+
const backupOpenAiClient = createOpenAiClient(backupConfiguration)
190191

192+
console.debug(`Using ${currentHost === OPENAI_API_HOST ? "primary" : "backup"} host: ${currentHost}`)
191193
try {
192-
const response = await newOpenai.chat.completions
194+
const response = await backupOpenAiClient.chat.completions
193195
.create({
194196
model: modelId,
195197
messages: [

0 commit comments

Comments
 (0)