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

Method createMessage

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

Source from the content-addressed store, hash-verified

123 }
124
125 override async *createMessage(
126 systemPrompt: string,
127 messages: Anthropic.Messages.MessageParam[],
128 metadata?: ApiHandlerCreateMessageMetadata,
129 ): ApiStream {
130 const {
131 id: model,
132 info,
133 maxTokens: max_tokens,
134 temperature,
135 reasoningEffort: reasoning_effort,
136 reasoning: thinking,
137 } = await this.fetchModel()
138
139 const openAiMessages: OpenAI.Chat.ChatCompletionMessageParam[] = [
140 { role: "system", content: systemPrompt },
141 ...convertToOpenAiMessages(messages),
142 ]
143
144 // Map extended efforts to OpenAI Chat Completions-accepted values (omit unsupported)
145 const allowedEffort = (["low", "medium", "high"] as const).includes(reasoning_effort as any)
146 ? (reasoning_effort as OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming["reasoning_effort"])
147 : undefined
148
149 const completionParams: RequestyChatCompletionParamsStreaming = {
150 messages: openAiMessages,
151 model,
152 max_tokens,
153 temperature,
154 ...(allowedEffort && { reasoning_effort: allowedEffort }),
155 ...(thinking && { thinking }),
156 stream: true,
157 stream_options: { include_usage: true },
158 requesty: { trace_id: metadata?.taskId, extra: { mode: metadata?.mode } },
159 tools: this.convertToolsForOpenAI(metadata?.tools),
160 tool_choice: metadata?.tool_choice,
161 }
162
163 let stream
164 try {
165 // With streaming params type, SDK returns an async iterable stream
166 stream = await this.client.chat.completions.create(completionParams)
167 } catch (error) {
168 throw handleOpenAIError(error, this.providerName)
169 }
170 let lastUsage: any = undefined
171
172 for await (const chunk of stream) {
173 const delta = chunk.choices[0]?.delta
174
175 if (delta?.content) {
176 yield { type: "text", text: delta.content }
177 }
178
179 const reasoningText = extractReasoningFromDelta(delta)
180 if (reasoningText) {
181 yield { type: "reasoning", text: reasoningText }
182 }

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