From 79cf5dbf6817c1de9cb951966b790da9775d5f81 Mon Sep 17 00:00:00 2001 From: centdix Date: Thu, 28 Aug 2025 14:37:27 +0000 Subject: [PATCH] cleaning --- .../src/lib/components/copilot/chat/anthropic.ts | 13 ++++++------- frontend/src/lib/components/copilot/lib.ts | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/frontend/src/lib/components/copilot/chat/anthropic.ts b/frontend/src/lib/components/copilot/chat/anthropic.ts index 6640b8f8f1..cd487dd3c4 100644 --- a/frontend/src/lib/components/copilot/chat/anthropic.ts +++ b/frontend/src/lib/components/copilot/chat/anthropic.ts @@ -46,11 +46,10 @@ export interface AnthropicStreamEvent { } export function convertOpenAIToAnthropicMessages(messages: ChatCompletionMessageParam[]): { - system?: string | Array<{ type: 'text'; text: string; cache_control?: { type: 'ephemeral' } }> + system: Array<{ type: 'text'; text: string; cache_control?: { type: 'ephemeral' } }> | undefined messages: AnthropicMessage[] } { let system: - | string | Array<{ type: 'text'; text: string; cache_control?: { type: 'ephemeral' } }> | undefined const anthropicMessages: AnthropicMessage[] = [] @@ -176,6 +175,7 @@ export function convertOpenAIToolsToAnthropic( } export async function* convertAnthropicStreamToOpenAI( + model: string, response: Response ): AsyncIterable { if (!response.body) { @@ -210,7 +210,7 @@ export async function* convertAnthropicStreamToOpenAI( id: messageId, object: 'chat.completion.chunk', created: Math.floor(Date.now() / 1000), - model: event.message?.model || 'claude-3-5-sonnet-20241022', + model, choices: [ { index: 0, @@ -233,7 +233,7 @@ export async function* convertAnthropicStreamToOpenAI( id: messageId, object: 'chat.completion.chunk', created: Math.floor(Date.now() / 1000), - model: 'claude-3-5-sonnet-20241022', + model, choices: [ { index: 0, @@ -243,7 +243,6 @@ export async function* convertAnthropicStreamToOpenAI( ] } } else if (event.delta?.type === 'thinking_delta') { - // For thinking delta, we can either include as content or skip it // For now, skip thinking content as it's internal to the model } else if (event.delta?.type === 'input_json_delta' && currentToolCall) { currentToolCall.args += event.delta.partial_json @@ -255,7 +254,7 @@ export async function* convertAnthropicStreamToOpenAI( id: messageId, object: 'chat.completion.chunk', created: Math.floor(Date.now() / 1000), - model: 'claude-3-5-sonnet-20241022', + model, choices: [ { index: 0, @@ -292,7 +291,7 @@ export async function* convertAnthropicStreamToOpenAI( id: messageId, object: 'chat.completion.chunk', created: Math.floor(Date.now() / 1000), - model: 'claude-3-5-sonnet-20241022', + model, choices: [ { index: 0, diff --git a/frontend/src/lib/components/copilot/lib.ts b/frontend/src/lib/components/copilot/lib.ts index da9e85a020..ab65e06244 100644 --- a/frontend/src/lib/components/copilot/lib.ts +++ b/frontend/src/lib/components/copilot/lib.ts @@ -638,7 +638,7 @@ export async function getCompletion( const anthropicRequest: AnthropicRequest = { model: config.model, - max_tokens: config.max_tokens || 4096, + max_tokens: config.max_tokens as number, // config always has a max_tokens for anthropic messages: anthropicMessages, stream: true, ...(system && { system }), @@ -665,7 +665,7 @@ export async function getCompletion( throw new Error(`Anthropic API request failed: ${response.status} ${response.statusText}`) } - return convertAnthropicStreamToOpenAI(response) + return convertAnthropicStreamToOpenAI(config.model, response) } // For other providers, use the existing OpenAI client