MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / createMessage

Method createMessage

src/api/providers/unbound.ts:114–193  ·  view source on GitHub ↗
(
		systemPrompt: string,
		messages: Anthropic.Messages.MessageParam[],
		metadata?: ApiHandlerCreateMessageMetadata,
	)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

fetchModelMethod · 0.95
processUsageMetricsMethod · 0.95
convertToOpenAiMessagesFunction · 0.90
handleOpenAIErrorFunction · 0.90
createMethod · 0.45

Tested by

no test coverage detected