(
messages,
onChunk,
onComplete,
onError,
modelId,
generationConfig = {},
)
| 287 | }; |
| 288 | |
| 289 | export const sendMessage = async ( |
| 290 | messages, |
| 291 | onChunk, |
| 292 | onComplete, |
| 293 | onError, |
| 294 | modelId, |
| 295 | generationConfig = {}, |
| 296 | ) => { |
| 297 | const selectedModelId = modelId || "openai-large"; |
| 298 | const { maxTokens = 2000, temperature = 0.7, topP = 1 } = generationConfig; |
| 299 | const isClaude = selectedModelId.includes("claude"); |
| 300 | const finalTemperature = isClaude ? 1 : temperature; |
| 301 | const chartRequested = containsChartRequest(messages); |
| 302 | |
| 303 | const tools = [ |
| 304 | { |
| 305 | type: "function", |
| 306 | function: { |
| 307 | name: "create_chart", |
| 308 | description: |
| 309 | "Create a chart or graph visualization from data points.", |
| 310 | parameters: { |
| 311 | type: "object", |
| 312 | properties: { |
| 313 | title: { |
| 314 | type: "string", |
| 315 | description: "Title displayed above the chart.", |
| 316 | }, |
| 317 | data: { |
| 318 | type: "array", |
| 319 | items: { type: "object" }, |
| 320 | description: "Array of data objects.", |
| 321 | }, |
| 322 | series: { |
| 323 | type: "array", |
| 324 | items: { |
| 325 | type: "object", |
| 326 | properties: { |
| 327 | key: { type: "string" }, |
| 328 | name: { type: "string" }, |
| 329 | color: { type: "string" }, |
| 330 | }, |
| 331 | required: ["key", "name"], |
| 332 | }, |
| 333 | }, |
| 334 | xKey: { type: "string" }, |
| 335 | xLabel: { type: "string" }, |
| 336 | yLabel: { type: "string" }, |
| 337 | }, |
| 338 | required: ["title", "data", "series", "xKey"], |
| 339 | }, |
| 340 | }, |
| 341 | }, |
| 342 | ]; |
| 343 | |
| 344 | try { |
| 345 | if (abortController) abortController.abort(); |
| 346 | abortController = new AbortController(); |
no test coverage detected