mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-07 08:02:40 +00:00
cleaning
This commit is contained in:
@@ -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<OpenAI.Chat.Completions.ChatCompletionChunk> {
|
||||
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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user