import json, os
from openai import OpenAI
client = OpenAI(base_url="https://api.aban.ai/v1", api_key=os.environ["NOQTE_API_KEY"])
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the weather for a city",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},
},
}]
messages = [{"role": "user", "content": "هوای تهران چطور است؟"}]
first = client.chat.completions.create(model="noqte-1.2", messages=messages, tools=tools)
call = first.choices[0].message.tool_calls[0]
print(call.function.name, json.loads(call.function.arguments))
messages += [
first.choices[0].message.model_dump(exclude_none=True),
{"role": "tool", "tool_call_id": call.id, "content": "آفتابی، ۲۱ درجه"},
]
final = client.chat.completions.create(model="noqte-1.2", messages=messages, tools=tools)
print(final.choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.aban.ai/v1", apiKey: process.env.NOQTE_API_KEY });
const tools = [{
type: "function",
function: {
name: "get_weather",
description: "Get the weather for a city",
parameters: { type: "object", properties: { city: { type: "string" } }, required: ["city"] },
},
}];
const messages = [{ role: "user", content: "هوای تهران چطور است؟" }];
const first = await client.chat.completions.create({ model: "noqte-1.2", messages, tools });
const call = first.choices[0].message.tool_calls[0];
console.log(call.function.name, JSON.parse(call.function.arguments));
messages.push(first.choices[0].message, {
role: "tool",
tool_call_id: call.id,
content: "آفتابی، ۲۱ درجه",
});
const final = await client.chat.completions.create({ model: "noqte-1.2", messages, tools });
console.log(final.choices[0].message.content);