also looking at this
chore(deps): upgrade vendored Stacks framework to 0.70.163
#29
224 files
+3516
-874
| @@ -217,6 +217,9 @@ export async function chat( | ||
| 217 | 217 | temperature, |
| 218 | 218 | topP, |
| 219 | 219 | stop, |
| 220 | tools, | |
| 221 | toolChoice, | |
| 222 | responseFormat, | |
| 220 | 223 | } = options |
| 221 | 224 | |
| 222 | 225 | // Normalize content arrays into OpenAI's wire format |
| @@ -228,20 +231,42 @@ export async function chat( | ||
| 228 | 231 | // Track wall-clock duration for usage reporters (#1878 A-6). |
| 229 | 232 | const startedAt = Date.now() |
| 230 | 233 | |
| 234 | const body: Record<string, unknown> = { | |
| 235 | model, | |
| 236 | max_tokens: maxTokens, | |
| 237 | temperature, | |
| 238 | top_p: topP, | |
| 239 | stop, | |
| 240 | messages: normalizedMessages, | |
| 241 | } | |
| 242 | ||
| 243 | if (tools?.length) { | |
| 244 | body.tools = tools.map(tool => ({ | |
| 245 | type: 'function', | |
| 246 | function: { | |
| 247 | name: tool.name, | |
| 248 | description: tool.description, | |
| 249 | parameters: tool.parameters ?? { type: 'object', properties: {} }, | |
| 250 | }, | |
| 251 | })) | |
| 252 | } | |
| 253 | ||
| 254 | if (toolChoice !== undefined) { | |
| 255 | body.tool_choice = typeof toolChoice === 'object' | |
| 256 | ? { type: 'function', function: { name: toolChoice.name } } | |
| 257 | : toolChoice | |
| 258 | } | |
| 259 | ||
| 260 | if (responseFormat && responseFormat.type !== 'text') | |
| 261 | body.response_format = responseFormat | |
| 262 | ||
| 231 | 263 | const response = await fetchWithRetry(`${config.baseUrl || DEFAULT_BASE_URL}/chat/completions`, { |
| 232 | 264 | method: 'POST', |
| 233 | 265 | headers: { |
| 234 | 266 | 'Content-Type': 'application/json', |
| 235 | 267 | 'Authorization': `Bearer ${config.apiKey}`, |
| 236 | 268 | }, |
| 237 | body: JSON.stringify({ | |
| 238 | model, | |
| 239 | max_tokens: maxTokens, | |
| 240 | temperature, | |
| 241 | top_p: topP, | |
| 242 | stop, | |
| 243 | messages: normalizedMessages, | |
| 244 | }), | |
| 269 | body: JSON.stringify(body), | |
| 245 | 270 | }) |
| 246 | 271 | |
| 247 | 272 | if (!response.ok) { |