({ apiKey, baseURL, model, messages, tools })
| 4 | } |
| 5 | |
| 6 | export async function chat({ apiKey, baseURL, model, messages, tools }) { |
| 7 | const res = await fetch(getChatCompletionsUrl(baseURL), { |
| 8 | method: "POST", |
| 9 | headers: { |
| 10 | "Content-Type": "application/json", |
| 11 | "Authorization": `Bearer ${apiKey}`, |
| 12 | }, |
| 13 | body: JSON.stringify({ model, messages, tools }), |
| 14 | }); |
| 15 | if (!res.ok) { |
| 16 | const text = await res.text(); |
| 17 | throw new Error(`OpenAI error ${res.status}: ${text}`); |
| 18 | } |
| 19 | return await res.json(); |
| 20 | } |
no test coverage detected