Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
why does it work now
perf3ctdaccadd5e03c
diff --git a/src/services/llm/providers/openai_service.ts b/src/services/llm/providers/openai_service.tsindex fcf7d71f51..799ba9c1f6 100644--- a/src/services/llm/providers/openai_service.ts+++ b/src/services/llm/providers/openai_service.ts@@ -66,12 +66,25 @@ export class OpenAIService extends BaseAIService {params.tool_choice = providerOptions.tool_choice as OpenAI.Chat.ChatCompletionToolChoiceOption;}+ // Log the request parameters+ console.log('OpenAI API Request:', JSON.stringify({+ endpoint: 'chat.completions.create',+ model: params.model,+ messages: params.messages,+ temperature: params.temperature,+ max_tokens: params.max_tokens,+ stream: params.stream,+ tools: params.tools,+ tool_choice: params.tool_choice+ }, null, 2));+// If streaming is requestedif (providerOptions.stream) {params.stream = true;// Get stream from OpenAI SDKconst stream = await client.chat.completions.create(params);+ console.log('OpenAI API Stream Started');// Create a closure to hold accumulated tool callslet accumulatedToolCalls: any[] = [];@@ -90,6 +103,9 @@ export class OpenAIService extends BaseAIService {// Process the streamif (Symbol.asyncIterator in stream) {for await (const chunk of stream as AsyncIterable<OpenAI.Chat.ChatCompletionChunk>) {+ // Log each chunk received from OpenAI+ console.log('OpenAI API Stream Chunk:', JSON.stringify(chunk, null, 2));+const content = chunk.choices[0]?.delta?.content || '';const isDone = !!chunk.choices[0]?.finish_reason;@@ -153,12 +169,17 @@ export class OpenAIService extends BaseAIService {await callback(streamChunk);if (isDone) {+ console.log('OpenAI API Stream Complete. Final text length:', completeText.length);+ if (accumulatedToolCalls.length > 0) {+ console.log('OpenAI API Tool Calls:', JSON.stringify(accumulatedToolCalls, null, 2));+ }break;}}} else {// Fallback for non-iterable responseconsole.warn('Stream is not iterable, falling back to non-streaming response');+ console.log('OpenAI API Non-iterable Stream Response:', JSON.stringify(stream, null, 2));if ('choices' in stream) {const content = stream.choices[0]?.message?.content || '';@@ -168,6 +189,7 @@ export class OpenAIService extends BaseAIService {const toolCalls = stream.choices[0]?.message?.tool_calls;if (toolCalls) {response.tool_calls = toolCalls;+ console.log('OpenAI API Tool Calls in Non-iterable Response:', JSON.stringify(toolCalls, null, 2));}await callback({@@ -198,6 +220,9 @@ export class OpenAIService extends BaseAIService {const completion = await client.chat.completions.create(params);+ // Log the full response from OpenAI+ console.log('OpenAI API Response:', JSON.stringify(completion, null, 2));+if (!('choices' in completion)) {throw new Error('Unexpected response format from OpenAI API');}