( systemPrompt: string, messages: Anthropic.Messages.MessageParam[], metadata?: ApiHandlerCreateMessageMetadata, )
| 112 | } |
| 113 | |
| 114 | override async *createMessage( |
| 115 | systemPrompt: string, |
| 116 | messages: Anthropic.Messages.MessageParam[], |
| 117 | metadata?: ApiHandlerCreateMessageMetadata, |
| 118 | ): ApiStream { |
| 119 | const { |
| 120 | id: model, |
| 121 | info, |
| 122 | maxTokens: max_tokens, |
| 123 | temperature, |
| 124 | reasoningEffort: reasoning_effort, |
| 125 | reasoning: thinking, |
| 126 | } = await this.fetchModel() |
| 127 | |
| 128 | const openAiMessages: OpenAI.Chat.ChatCompletionMessageParam[] = [ |
| 129 | { role: "system", content: systemPrompt }, |
| 130 | ...convertToOpenAiMessages(messages), |
| 131 | ] |
| 132 | |
| 133 | // Map extended efforts to OpenAI Chat Completions-accepted values (omit unsupported) |
| 134 | const allowedEffort = (["low", "medium", "high"] as const).includes(reasoning_effort as any) |
| 135 | ? (reasoning_effort as OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming["reasoning_effort"]) |
| 136 | : undefined |
| 137 | |
| 138 | const completionParams: UnboundChatCompletionParamsStreaming = { |
| 139 | messages: openAiMessages, |
| 140 | model, |
| 141 | max_tokens, |
| 142 | temperature, |
| 143 | ...(allowedEffort && { reasoning_effort: allowedEffort }), |
| 144 | ...(thinking && { thinking }), |
| 145 | stream: true, |
| 146 | stream_options: { include_usage: true }, |
| 147 | unbound_metadata: { originApp: "zoo-code", taskId: metadata?.taskId, mode: metadata?.mode }, |
| 148 | tools: this.convertToolsForOpenAI(metadata?.tools), |
| 149 | tool_choice: metadata?.tool_choice, |
| 150 | } |
| 151 | |
| 152 | let stream |
| 153 | try { |
| 154 | stream = await this.client.chat.completions.create(completionParams) |
| 155 | } catch (error) { |
| 156 | throw handleOpenAIError(error, this.providerName) |
| 157 | } |
| 158 | let lastUsage: any = undefined |
| 159 | |
| 160 | for await (const chunk of stream) { |
| 161 | const delta = chunk.choices[0]?.delta |
| 162 | |
| 163 | if (delta?.content) { |
| 164 | yield { type: "text", text: delta.content } |
| 165 | } |
| 166 | |
| 167 | const reasoningText = extractReasoningFromDelta(delta) |
| 168 | if (reasoningText) { |
| 169 | yield { type: "reasoning", text: reasoningText } |
| 170 | } |
| 171 |
nothing calls this directly
no test coverage detected