ReviewOS

also looking at this

stacks/postline

chore(deps): upgrade vendored Stacks framework to 0.70.163

#29
Merged glennmichael123 wants to merge chore/upgrade-0.70.163 into main
224 files +3516 -874
storage/framework/core/ai/src/drivers/openai/index.tsmodified+33-8
Changes to storage/framework/core/ai/src/drivers/openai/index.ts
@@ -217,6 +217,9 @@ export async function chat(
217217 temperature,
218218 topP,
219219 stop,
220 tools,
221 toolChoice,
222 responseFormat,
220223 } = options
221224
222225 // Normalize content arrays into OpenAI's wire format
@@ -228,20 +231,42 @@ export async function chat(
228231 // Track wall-clock duration for usage reporters (#1878 A-6).
229232 const startedAt = Date.now()
230233
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
231263 const response = await fetchWithRetry(`${config.baseUrl || DEFAULT_BASE_URL}/chat/completions`, {
232264 method: 'POST',
233265 headers: {
234266 'Content-Type': 'application/json',
235267 'Authorization': `Bearer ${config.apiKey}`,
236268 },
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),
245270 })
246271
247272 if (!response.ok) {