Vocatio functionum
Descripe functiones tuas in petitione et modellum respondet cum vocationibus quas fieri vult. Codex tuus eas exsequitur et eventus remittit: API vocationes tool reddit nec ipsum tool exsequitur.
POST https://api.shannon-ai.com/v1/chat/completions
Exempla in hac pagina /v1/chat/completions utuntur. Idem circulus in /v1/responses et /v1/messages currit; ubi forma aliqua aliter aliquid scribit, sectiones infra omnes tres ostendunt.
import json
from openai import OpenAI
client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.shannon-ai.com/v1")
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name, for example Paris"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["city"],
},
},
}]
def get_weather(city, unit="celsius"):
# Your code: ask a weather service here.
return {"city": city, "temperature": 18, "unit": unit, "conditions": "cloudy"}
messages = [{"role": "user", "content": "What is the weather in Paris right now?"}]
answer = None
for _ in range(5): # the API sets no limit on rounds: set your own
response = client.chat.completions.create(
model="Kimi-K3-3BIT-REAP",
messages=messages,
tools=tools,
)
choice = response.choices[0]
if choice.finish_reason != "tool_calls":
answer = choice.message.content
break
messages.append(choice.message) # the assistant turn with its tool_calls
for call in choice.message.tool_calls:
args = json.loads(call.function.arguments) # arguments is a JSON string
result = get_weather(**args)
messages.append({
"role": "tool",
"tool_call_id": call.id,
"content": json.dumps(result),
})
print(answer) import OpenAI from "openai";
const client = new OpenAI({ apiKey: "YOUR_API_KEY", baseURL: "https://api.shannon-ai.com/v1" });
const tools = [{
type: "function",
function: {
name: "get_weather",
description: "Get the current weather for a city.",
parameters: {
type: "object",
properties: {
city: { type: "string", description: "City name, for example Paris" },
unit: { type: "string", enum: ["celsius", "fahrenheit"] },
},
required: ["city"],
},
},
}];
// Your code: ask a weather service here.
function getWeather({ city, unit = "celsius" }) {
return { city, temperature: 18, unit, conditions: "cloudy" };
}
const messages = [{ role: "user", content: "What is the weather in Paris right now?" }];
let answer = null;
// The API sets no limit on rounds: set your own.
for (let round = 0; round < 5; round++) {
const response = await client.chat.completions.create({
model: "Kimi-K3-3BIT-REAP",
messages,
tools,
});
const choice = response.choices[0];
if (choice.finish_reason !== "tool_calls") {
answer = choice.message.content;
break;
}
messages.push(choice.message); // the assistant turn with its tool_calls
for (const call of choice.message.tool_calls) {
const args = JSON.parse(call.function.arguments); // arguments is a JSON string
messages.push({
role: "tool",
tool_call_id: call.id,
content: JSON.stringify(getWeather(args)),
});
}
}
console.log(answer); # 1. Send the conversation with the tools.
curl https://api.shannon-ai.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "Kimi-K3-3BIT-REAP",
"messages": [
{"role": "user", "content": "What is the weather in Paris right now?"}
],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name, for example Paris"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["city"]
}
}
}]
}'
# 2. Run the function yourself, then send the assistant turn and the result.
# Use the id of the call you received.
curl https://api.shannon-ai.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "Kimi-K3-3BIT-REAP",
"messages": [
{"role": "user", "content": "What is the weather in Paris right now?"},
{"role": "assistant", "content": null, "tool_calls": [{
"id": "call_9f1c2ab34d5e4f60a7b8c9d0e1f2a3b4",
"type": "function",
"function": {"name": "get_weather", "arguments": "{\"city\":\"Paris\"}"}
}]},
{"role": "tool", "tool_call_id": "call_9f1c2ab34d5e4f60a7b8c9d0e1f2a3b4",
"content": "{\"city\":\"Paris\",\"temperature\":18,\"unit\":\"celsius\",\"conditions\":\"cloudy\"}"}
],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name, for example Paris"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["city"]
}
}
}]
}' Prima responsio quaestioni non respondet. Vocationem petit:
{
"id": "chatcmpl-5b0c1d8e7f6a4b3c9d2e1f0a8b7c6d5e",
"object": "chat.completion",
"created": 1791590400,
"model": "Kimi-K3-3BIT-REAP",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"reasoning_content": "The user asks for the current weather in Paris. I should call get_weather.",
"tool_calls": [
{
"id": "call_9f1c2ab34d5e4f60a7b8c9d0e1f2a3b4",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\":\"Paris\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
],
"usage": {
"prompt_tokens": 312,
"completion_tokens": 58,
"total_tokens": 370,
"prompt_tokens_details": {"cached_tokens": 0},
"completion_tokens_details": {"reasoning_tokens": 31}
}
} Postquam eventum misisti, responsio proxima est responsio ordinaria: message.content textum tenet et finish_reason est stop.
Circulus, gradatim
| Gradus | Quis | Quid fiat |
|---|---|---|
| 1 | Tu | Mitte messages una cum tools, indice functionum quas modellum petere potest. |
| 2 | Modellum | Responsio fert tool_calls et finish_reason: "tool_calls". Quaeque vocatio functionem nominat et argumenta eius dat. |
| 3 | Tu | Analyse arguments cuiusque vocationis et exsequere functionem tuam. |
| 4 | Tu | Adde nuntium assistentis et unum nuntium tool per vocationem ad messages, deinde mitte petitionem iterum cum eisdem tools. |
| 5 | Modellum | Modellum textu respondet cum finish_reason: "stop", aut plures vocationes petit. Hoc in casu redi ad gradum 3. |
Una petitio est unus turnus modelli. API nullam conversationem inter petitiones servat nec numerum rotarum ponit: codex tuus messages tenet et decernit quando desinat.
Tools definire
tools est array cum una inscriptione per functionem. Omne modellum catalogi eum accipit; GET /v1/models pro omni id capabilities.tools: true nuntiat.
| Campus | Genus | Descriptio |
|---|---|---|
type | string | Semper function. |
function.name | string | Nomen quo modellum utitur cum hanc functionem petit. Necessarium. |
function.description | string | Quid functio faciat, simplici sermone. |
function.parameters | object | Argumenta ut JSON Schema cum type: "object" in summo. Vide Verba clavis schematis infra. |
Quisque endpoint suam scripturam tool habet. Mitte eam quae ad endpoint pertinet quem vocas:
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name, for example Paris"
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["city"]
}
}
} {
"type": "function",
"name": "get_weather",
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name, for example Paris"
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["city"]
}
} {
"name": "get_weather",
"description": "Get the current weather for a city.",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name, for example Paris"
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["city"]
}
} tool_choice
tool_choice dicit num modellum tool vocare possit vel debeat. Legitur tantum una cum tools.
| Valor | Descriptio | Applicatur a |
|---|---|---|
"auto" | Modellum decernit utrum textu respondeat an tool vocet. Hoc est default. | Omnia modelli |
"required" | Responsio saltem unum tool vocat. | Modelli open-weight hosted |
{"type": "function", "function": {"name": "get_weather"}} | Responsio hanc functionem vocat. Nomen unum ex functionibus in tools esse debet. Vocationes ad alias functiones e responsione omittuntur. | Modelli open-weight hosted |
Modelli Shannon (shannon-*) in omni petitione decernunt, sicut cum auto.
Cum required vel functione nominata, lege finish_reason antequam tool_calls legis. Cum modellum nullam vocationem producit, responsio est textus cum finish_reason: "stop".
| Significatio | /v1/chat/completions | /v1/responses | /v1/messages |
|---|---|---|---|
| Modellum decernit | "auto" | "auto" | {"type": "auto"} |
| Saltem unum tool vocare | "required" | "required" | {"type": "any"} |
| Unam functionem nominatam vocare | {"type": "function", "function": {"name": "get_weather"}} | {"type": "function", "name": "get_weather"} | {"type": "tool", "name": "get_weather"} |
Propter compatibilitatem accepta: tool_choice: "none" et parallel_tool_calls. Pro vice sine vocationibus tool, mitte petitionem sine tools.
Vocationes tool in responsione
| Campus | Genus | Descriptio |
|---|---|---|
finish_reason | string | tool_calls cum responsio saltem unam vocationem fert. |
message.tool_calls | array | Una inscriptio per vocationem. Campus adest tantum cum modellum vocationem petivit. |
tool_calls[].id | string | call_ quod 32 notae hexadecimales sequuntur. Remitte id ut tool_call_id cum eventu. |
tool_calls[].type | string | Semper function. |
tool_calls[].function.name | string | Functio exsequenda. |
tool_calls[].function.arguments | string | Argumenta ut JSON string, "{}" cum nulla sunt. Analyse ante usum. |
message.content | string | null | null cum responsio solas vocationes continet. Modelli open-weight hosted textum iuxta vocationes reddere possunt; modelli Shannon null reddunt. |
Eadem vocatio in qualibet forma. In /v1/responses est elementum function_call ipsius output, cum arguments ut JSON string. In /v1/messages est content block tool_use cuius input est objectum JSON, id eius a toolu_ incipit, et stop_reason est tool_use.
{
"finish_reason": "tool_calls",
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_9f1c2ab34d5e4f60a7b8c9d0e1f2a3b4",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\":\"Paris\"}"
}
}
]
}
} {
"output": [
{
"id": "fc_3d2c1b0a9f8e4d7c6b5a4f3e2d1c0b9a",
"type": "function_call",
"call_id": "call_9f1c2ab34d5e4f60a7b8c9d0e1f2a3b4",
"name": "get_weather",
"arguments": "{\"city\":\"Paris\"}",
"status": "completed"
}
]
} {
"stop_reason": "tool_use",
"content": [
{
"type": "tool_use",
"id": "toolu_9f1c2ab34d5e4f60a7b8c9d0e1f2a3b4",
"name": "get_weather",
"input": {"city": "Paris"}
}
]
} Plures vocationes in uno turno
Responsio plures vocationes ferre potest. Exsequere omnes et mitte unum eventum per vocationem, quemque cum suo tool_call_id, in petitione proxima.
Modelli open-weight hosted quamque vocationem distinctam semel reddunt: duae vocationes cum eodem nomine et eisdem argumentis ut una adveniunt.
Vocationes tool streamed
Cum stream: true, vocatio una parte advenit: chunk totum string arguments tenet, itaque nulla fragmenta iungenda sunt. index vocationes turni a 0 numerat.
{
"id": "chatcmpl-5b0c1d8e7f6a4b3c9d2e1f0a8b7c6d5e",
"object": "chat.completion.chunk",
"created": 1791590400,
"model": "Kimi-K3-3BIT-REAP",
"choices": [
{
"index": 0,
"delta": {
"tool_calls": [
{
"index": 0,
"id": "call_9f1c2ab34d5e4f60a7b8c9d0e1f2a3b4",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\":\"Paris\"}"
}
}
]
},
"finish_reason": null
}
]
} | Endpoint | Quid adveniat |
|---|---|
/v1/chat/completions | Unum chat.completion.chunk per vocationem, cum vocatione in delta.tool_calls[0]. Ultimum chunk habet finish_reason: "tool_calls" et usage. |
/v1/responses | Per vocationem: response.output_item.added (elementum function_call cum arguments vacuis), response.function_call_arguments.delta (totus string), response.function_call_arguments.done, response.output_item.done. |
/v1/messages | Per vocationem: content_block_start (block tool_use cum input vacuo), unum content_block_delta cuius input_json_delta.partial_json est totus textus argumentorum, content_block_stop. message_delta deinde fert stop_reason: "tool_use". |
In shannon-1.6-lite, shannon-1.6-pro, shannon-2-lite, shannon-2-pro et shannon-coder-1, petitio streamed quae tools fert textum responsionis in uno delta content in fine turni dat. Fluens
Eventus remittere
Secunda petitio conversationem repetit et duo addit: turnum assistentis qui vocationes petivit, et unum eventum per vocationem.
{
"messages": [
{"role": "user", "content": "What is the weather in Paris right now?"},
{
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_9f1c2ab34d5e4f60a7b8c9d0e1f2a3b4",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\":\"Paris\"}"
}
}
]
},
{
"role": "tool",
"tool_call_id": "call_9f1c2ab34d5e4f60a7b8c9d0e1f2a3b4",
"content": "{\"city\":\"Paris\",\"temperature\":18,\"unit\":\"celsius\",\"conditions\":\"cloudy\"}"
}
]
} {
"input": [
{"role": "user", "content": "What is the weather in Paris right now?"},
{
"type": "function_call",
"call_id": "call_9f1c2ab34d5e4f60a7b8c9d0e1f2a3b4",
"name": "get_weather",
"arguments": "{\"city\":\"Paris\"}"
},
{
"type": "function_call_output",
"call_id": "call_9f1c2ab34d5e4f60a7b8c9d0e1f2a3b4",
"output": "{\"city\":\"Paris\",\"temperature\":18,\"unit\":\"celsius\",\"conditions\":\"cloudy\"}"
}
]
} {
"messages": [
{"role": "user", "content": "What is the weather in Paris right now?"},
{
"role": "assistant",
"content": [
{
"type": "tool_use",
"id": "toolu_9f1c2ab34d5e4f60a7b8c9d0e1f2a3b4",
"name": "get_weather",
"input": {"city": "Paris"}
}
]
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "toolu_9f1c2ab34d5e4f60a7b8c9d0e1f2a3b4",
"content": "{\"city\":\"Paris\",\"temperature\":18,\"unit\":\"celsius\",\"conditions\":\"cloudy\"}"
}
]
}
]
} - Remitte turnum assistentis ut accepisti, ante eventus. Quisque eventus cum sua vocatione per id coniungitur:
tool_call_idin/v1/chat/completions,call_idin/v1/responses,tool_use_idin/v1/messages. - Eventus est textus. Serialise objectum in JSON string pro
content(outputin/v1/responses). In/v1/messagescontentblockitool_resultest string vel index text blocks. - In turno assistentis,
function.argumentsmanet JSON string, prorsus ut advenit. - Conversatio cum eventu tool finire potest. Nullus novus nuntius user necessarius est: modellum ab eventu pergit.
- Cum functio tua deficit, mitte defectum ut textum eventus. Modellum tunc eum nuntiare potest aut aliam vocationem petere.
Verba clavis schematis
parameters (input_schema in /v1/messages) est JSON Schema. Familia Shannon 3 (shannon-3, shannon-3-pro, shannon-3.1, shannon-3.1-pro) et modelli open-weight hosted eum accipiunt ut mittis.
shannon-1.6-lite, shannon-1.6-pro, shannon-2-lite, shannon-2-pro et shannon-coder-1 hanc partem accipiunt, in omnibus tribus endpoints:
| Tractatio | Verba clavis |
|---|---|
| Legitur ut missum | Omne verbum clavis quod in lineis infra non nominatur, exempli gratia type, properties, required, items, enum, description, minimum, maximum, anyOf et allOf, in omni gradu schematis. |
format | Legitur pro valoribus int32, int64, float, double, byte, date, date-time et enum. |
oneOf | Legitur ut anyOf. |
| Non pars schematis quod hi modelli accipiunt | $schema, $id, $ref, $defs, $comment, definitions, additionalProperties, unevaluatedProperties, patternProperties, propertyNames, examples, default, title, const, not, if, then, else, contains, minContains, maxContains, dependentRequired, dependentSchemas, dependencies, readOnly, writeOnly, deprecated, contentEncoding, contentMediaType, contentSchema, multipleOf, uniqueItems; exclusiveMinimum et exclusiveMaximum cum numeri sunt; alii valores format. |
Mores et limites
- API nullum maximum numerum tools nec maximum numerum rotarum ponit.
- Corpus petitionis ad 32 MiB esse potest, et conversatio cum eventibus suis in context window modelli capi debet.
- Cum petitio
toolsfert,shannon-1.6-lite,shannon-1.6-pro,shannon-2-liteetshannon-2-protemperaturedefaultum 0.2 utuntur. Mittetemperatureut aliud valorem ponas. - Omnis rota est petitio propria: de saldo tuo trahit et ad defensionem inundationis computatur sicut quaevis alia petitio. Limites et saldum
Errores
Vocatio tool est responsio normalis cum statu 200. Hi errores ad ipsam petitionem pertinent:
| Status | Genus | Nuntius | Quando |
|---|---|---|---|
400 | invalid_request_error | unknown model: <id> | model non est id catalogi publicati. |
422 | invalid_request_error | Failed to deserialize the JSON body into the target type: … | tools non est array, vel alius campus typum JSON falsum habet. |
413 | invalid_request_error | Failed to buffer the request body: … | Corpus petitionis maius est quam 32 MiB. Error fert code: "request_too_large". |
Modellum argumenta scribit. Eas contra schema tuum inspice antequam functionem exsequeris, sicut quemvis input externum inspiceres.
Errores authenticationis, saldi et servientis eidem sunt ac pro omni petitione. Tractatio errorum