API reference
Tools
Let EON call your functions.
Describe functions in tools. When EON wants one, the reply has tool_calls. Run the function yourself, send the result back as a tool message, and EON finishes the answer.
const tools = [{
type: 'function',
function: {
name: 'get_weather',
description: 'Current weather for a city',
parameters: {
type: 'object',
properties: { city: { type: 'string' } },
required: ['city'],
},
},
}]
const messages = [{ role: 'user', content: 'Do I need a jacket in Provo?' }]
const first = await eon.chat.completions.create({ model: 'eon', messages, tools })
const call = first.choices[0].message.tool_calls?.[0]
if (call) {
const args = JSON.parse(call.function.arguments)
const weather = await getWeather(args.city) // your code
messages.push(first.choices[0].message)
messages.push({ role: 'tool', tool_call_id: call.id, content: JSON.stringify(weather) })
const final = await eon.chat.completions.create({ model: 'eon', messages, tools })
console.log(final.choices[0].message.content)
}