ಫಂಕ್ಷನ್ ಕಾಲಿಂಗ್
ವಿನಂತಿಯಲ್ಲಿ ನಿಮ್ಮ ಫಂಕ್ಷನ್ಗಳನ್ನು ವಿವರಿಸಿ, ಮಾಡೆಲ್ ತಾನು ಮಾಡಿಸಲು ಬಯಸುವ ಕರೆಗಳೊಂದಿಗೆ ಉತ್ತರಿಸುತ್ತದೆ. ನಿಮ್ಮ ಕೋಡ್ ಅವನ್ನು ಚಲಾಯಿಸಿ ಫಲಿತಾಂಶಗಳನ್ನು ಹಿಂತಿರುಗಿಸುತ್ತದೆ: API ಟೂಲ್ ಕರೆಗಳನ್ನು ಹಿಂತಿರುಗಿಸುತ್ತದೆ, ಟೂಲ್ ಅನ್ನು ತಾನೇ ಚಲಾಯಿಸುವುದಿಲ್ಲ.
POST https://api.shannon-ai.com/v1/chat/completions
ಈ ಪುಟದ ಮಾದರಿಗಳು /v1/chat/completions ಅನ್ನು ಬಳಸುತ್ತವೆ. ಅದೇ ಲೂಪ್ /v1/responses ಮತ್ತು /v1/messages ನಲ್ಲಿಯೂ ನಡೆಯುತ್ತದೆ; ಯಾವುದಾದರೂ ಫಾರ್ಮ್ಯಾಟ್ ಒಂದು ವಿಷಯವನ್ನು ಬೇರೆ ರೀತಿ ಬರೆದರೆ, ಕೆಳಗಿನ ವಿಭಾಗಗಳು ಮೂರನ್ನೂ ತೋರಿಸುತ್ತವೆ.
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"]
}
}
}]
}' ಮೊದಲ ಉತ್ತರ ಪ್ರಶ್ನೆಗೆ ಉತ್ತರಿಸುವುದಿಲ್ಲ. ಅದು ಕರೆಯನ್ನು ಕೇಳುತ್ತದೆ:
{
"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}
}
} ನೀವು ಫಲಿತಾಂಶವನ್ನು ಕಳುಹಿಸಿದ ನಂತರ, ಮುಂದಿನ ಉತ್ತರ ಸಾಮಾನ್ಯ ಉತ್ತರ: message.content ಪಠ್ಯವನ್ನು ಹೊಂದಿರುತ್ತದೆ ಮತ್ತು finish_reason stop ಆಗಿರುತ್ತದೆ.
ಲೂಪ್, ಹೆಜ್ಜೆ ಹೆಜ್ಜೆಯಾಗಿ
| ಹೆಜ್ಜೆ | ಯಾರು | ಏನಾಗುತ್ತದೆ |
|---|---|---|
| 1 | ನೀವು | messages ಅನ್ನು tools ಜೊತೆ ಕಳುಹಿಸಿ, ಅಂದರೆ ಮಾಡೆಲ್ ಕೇಳಬಹುದಾದ ಫಂಕ್ಷನ್ಗಳ ಪಟ್ಟಿ. |
| 2 | ಮಾಡೆಲ್ | ಉತ್ತರ tool_calls ಮತ್ತು finish_reason: "tool_calls" ಹೊತ್ತಿರುತ್ತದೆ. ಪ್ರತಿ ಕರೆ ಒಂದು ಫಂಕ್ಷನ್ ಅನ್ನು ಹೆಸರಿಸಿ ಅದರ arguments ಅನ್ನು ನೀಡುತ್ತದೆ. |
| 3 | ನೀವು | ಪ್ರತಿ ಕರೆಯ arguments ಅನ್ನು ಪಾರ್ಸ್ ಮಾಡಿ ನಿಮ್ಮ ಫಂಕ್ಷನ್ ಅನ್ನು ಚಲಾಯಿಸಿ. |
| 4 | ನೀವು | assistant ಸಂದೇಶವನ್ನು ಮತ್ತು ಪ್ರತಿ ಕರೆಗೆ ಒಂದು tool ಸಂದೇಶವನ್ನು messages ಗೆ ಸೇರಿಸಿ, ನಂತರ ಅದೇ tools ಜೊತೆ ವಿನಂತಿಯನ್ನು ಮತ್ತೆ ಕಳುಹಿಸಿ. |
| 5 | ಮಾಡೆಲ್ | ಮಾಡೆಲ್ finish_reason: "stop" ಜೊತೆ ಪಠ್ಯದಲ್ಲಿ ಉತ್ತರಿಸುತ್ತದೆ, ಅಥವಾ ಇನ್ನಷ್ಟು ಕರೆಗಳನ್ನು ಕೇಳುತ್ತದೆ. ಆ ಸಂದರ್ಭದಲ್ಲಿ ಹೆಜ್ಜೆ 3 ಕ್ಕೆ ಹಿಂತಿರುಗಿ. |
ಒಂದು ವಿನಂತಿ ಎಂದರೆ ಮಾಡೆಲ್ನ ಒಂದು ಟರ್ನ್. API ವಿನಂತಿಗಳ ನಡುವೆ ಸಂಭಾಷಣೆಯನ್ನು ಉಳಿಸಿಕೊಳ್ಳುವುದಿಲ್ಲ ಮತ್ತು ಸುತ್ತುಗಳ ಸಂಖ್ಯೆಯನ್ನು ನಿಗದಿಪಡಿಸುವುದಿಲ್ಲ: ನಿಮ್ಮ ಕೋಡ್ messages ಅನ್ನು ಹಿಡಿದಿಟ್ಟುಕೊಂಡು ಯಾವಾಗ ನಿಲ್ಲಿಸಬೇಕೆಂದು ನಿರ್ಧರಿಸುತ್ತದೆ.
ಟೂಲ್ಗಳನ್ನು ವ್ಯಾಖ್ಯಾನಿಸುವುದು
tools ಪ್ರತಿ ಫಂಕ್ಷನ್ಗೆ ಒಂದು ನಮೂದಿರುವ array. ಕ್ಯಾಟಲಾಗ್ನ ಪ್ರತಿ ಮಾಡೆಲ್ ಇದನ್ನು ಸ್ವೀಕರಿಸುತ್ತದೆ; GET /v1/models ಪ್ರತಿ id ಗೆ capabilities.tools: true ಎಂದು ವರದಿ ಮಾಡುತ್ತದೆ.
| ಫೀಲ್ಡ್ | ವಿಧ | ವಿವರಣೆ |
|---|---|---|
type | string | ಯಾವಾಗಲೂ function. |
function.name | string | ಮಾಡೆಲ್ ಈ ಫಂಕ್ಷನ್ ಅನ್ನು ಕೇಳುವಾಗ ಬಳಸುವ ಹೆಸರು. ಕಡ್ಡಾಯ. |
function.description | string | ಫಂಕ್ಷನ್ ಏನು ಮಾಡುತ್ತದೆ, ಸರಳ ಭಾಷೆಯಲ್ಲಿ. |
function.parameters | object | arguments ಗಳು ಮೇಲ್ಭಾಗದಲ್ಲಿ type: "object" ಇರುವ JSON Schema ಆಗಿ. ಕೆಳಗಿನ Schema ಕೀವರ್ಡ್ಗಳು ನೋಡಿ. |
ಪ್ರತಿ ಎಂಡ್ಪಾಯಿಂಟ್ ಟೂಲ್ ಅನ್ನು ತನ್ನದೇ ರೀತಿಯಲ್ಲಿ ಬರೆಯುತ್ತದೆ. ನೀವು ಕರೆಯುವ ಎಂಡ್ಪಾಯಿಂಟ್ಗೆ ಸೇರಿದ್ದನ್ನು ಕಳುಹಿಸಿ:
{
"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 ಮಾಡೆಲ್ ಟೂಲ್ ಅನ್ನು ಕರೆಯಬಹುದೇ ಅಥವಾ ಕರೆಯಲೇಬೇಕೇ ಎಂದು ಹೇಳುತ್ತದೆ. ಇದನ್ನು tools ಜೊತೆಗೆ ಮಾತ್ರ ಓದಲಾಗುತ್ತದೆ.
| ಮೌಲ್ಯ | ವಿವರಣೆ | ಅನ್ವಯಿಸುವವರು |
|---|---|---|
"auto" | ಪಠ್ಯದಲ್ಲಿ ಉತ್ತರಿಸಬೇಕೇ ಅಥವಾ ಟೂಲ್ ಕರೆಯಬೇಕೇ ಎಂದು ಮಾಡೆಲ್ ನಿರ್ಧರಿಸುತ್ತದೆ. ಇದು ಡೀಫಾಲ್ಟ್. | ಎಲ್ಲಾ ಮಾಡೆಲ್ಗಳು |
"required" | ಉತ್ತರ ಕನಿಷ್ಠ ಒಂದು ಟೂಲ್ ಅನ್ನು ಕರೆಯುತ್ತದೆ. | ಹೋಸ್ಟ್ ಮಾಡಿದ ಓಪನ್-ವೇಟ್ ಮಾಡೆಲ್ಗಳು |
{"type": "function", "function": {"name": "get_weather"}} | ಉತ್ತರ ಈ ಫಂಕ್ಷನ್ ಅನ್ನು ಕರೆಯುತ್ತದೆ. ಹೆಸರು tools ನಲ್ಲಿರುವ ಫಂಕ್ಷನ್ಗಳಲ್ಲಿ ಒಂದಾಗಿರಬೇಕು. ಇತರ ಫಂಕ್ಷನ್ಗಳ ಕರೆಗಳನ್ನು ಉತ್ತರದಿಂದ ಬಿಡಲಾಗುತ್ತದೆ. | ಹೋಸ್ಟ್ ಮಾಡಿದ ಓಪನ್-ವೇಟ್ ಮಾಡೆಲ್ಗಳು |
Shannon ಮಾಡೆಲ್ಗಳು (shannon-*) auto ನಂತೆ ಪ್ರತಿ ವಿನಂತಿಯಲ್ಲೂ ನಿರ್ಧರಿಸುತ್ತವೆ.
required ಅಥವಾ ಹೆಸರಿಸಿದ ಫಂಕ್ಷನ್ನೊಂದಿಗೆ, tool_calls ಓದುವ ಮೊದಲು finish_reason ಓದಿ. ಮಾಡೆಲ್ ಯಾವುದೇ ಕರೆ ಮಾಡದಿದ್ದರೆ, ಉತ್ತರ finish_reason: "stop" ಇರುವ ಪಠ್ಯ ಉತ್ತರವಾಗಿರುತ್ತದೆ.
| ಅರ್ಥ | /v1/chat/completions | /v1/responses | /v1/messages |
|---|---|---|---|
| ಮಾಡೆಲ್ ನಿರ್ಧರಿಸುತ್ತದೆ | "auto" | "auto" | {"type": "auto"} |
| ಕನಿಷ್ಠ ಒಂದು ಟೂಲ್ ಅನ್ನು ಕರೆಯಿರಿ | "required" | "required" | {"type": "any"} |
| ಹೆಸರಿಸಿದ ಒಂದು ಫಂಕ್ಷನ್ ಅನ್ನು ಕರೆಯಿರಿ | {"type": "function", "function": {"name": "get_weather"}} | {"type": "function", "name": "get_weather"} | {"type": "tool", "name": "get_weather"} |
ಹೊಂದಾಣಿಕೆಗಾಗಿ ಸ್ವೀಕರಿಸಲಾಗುತ್ತದೆ: tool_choice: "none" ಮತ್ತು parallel_tool_calls. ಟೂಲ್ ಕರೆಗಳಿಲ್ಲದ ಟರ್ನ್ಗಾಗಿ, tools ಇಲ್ಲದೆ ವಿನಂತಿಯನ್ನು ಕಳುಹಿಸಿ.
ಉತ್ತರದಲ್ಲಿ ಟೂಲ್ ಕರೆಗಳು
| ಫೀಲ್ಡ್ | ವಿಧ | ವಿವರಣೆ |
|---|---|---|
finish_reason | string | ಉತ್ತರ ಕನಿಷ್ಠ ಒಂದು ಕರೆಯನ್ನು ಹೊತ್ತಿದ್ದರೆ tool_calls. |
message.tool_calls | array | ಪ್ರತಿ ಕರೆಗೆ ಒಂದು ನಮೂದು. ಮಾಡೆಲ್ ಕರೆಯನ್ನು ಕೇಳಿದಾಗ ಮಾತ್ರ ಈ ಫೀಲ್ಡ್ ಇರುತ್ತದೆ. |
tool_calls[].id | string | call_ ನಂತರ 32 ಹೆಕ್ಸಾಡೆಸಿಮಲ್ ಅಕ್ಷರಗಳು. ಫಲಿತಾಂಶದೊಂದಿಗೆ ಅದನ್ನು tool_call_id ಆಗಿ ಹಿಂತಿರುಗಿಸಿ. |
tool_calls[].type | string | ಯಾವಾಗಲೂ function. |
tool_calls[].function.name | string | ಚಲಾಯಿಸಬೇಕಾದ ಫಂಕ್ಷನ್. |
tool_calls[].function.arguments | string | arguments JSON string ಆಗಿ, ಯಾವುದೂ ಇಲ್ಲದಿದ್ದರೆ "{}". ಬಳಸುವ ಮೊದಲು ಅದನ್ನು ಪಾರ್ಸ್ ಮಾಡಿ. |
message.content | string | null | ಉತ್ತರದಲ್ಲಿ ಕರೆಗಳು ಮಾತ್ರ ಇದ್ದಾಗ null. ಹೋಸ್ಟ್ ಮಾಡಿದ ಓಪನ್-ವೇಟ್ ಮಾಡೆಲ್ಗಳು ಕರೆಗಳ ಜೊತೆ ಪಠ್ಯವನ್ನೂ ಹಿಂತಿರುಗಿಸಬಹುದು; Shannon ಮಾಡೆಲ್ಗಳು null ಹಿಂತಿರುಗಿಸುತ್ತವೆ. |
ಪ್ರತಿ ಫಾರ್ಮ್ಯಾಟ್ನಲ್ಲಿ ಅದೇ ಕರೆ. /v1/responses ನಲ್ಲಿ ಅದು output ನ function_call ಐಟಂ, arguments JSON string ಆಗಿ. /v1/messages ನಲ್ಲಿ ಅದು tool_use ಕಂಟೆಂಟ್ ಬ್ಲಾಕ್, ಅದರ input JSON ಆಬ್ಜೆಕ್ಟ್, ಅದರ id toolu_ ನಿಂದ ಆರಂಭವಾಗುತ್ತದೆ, ಮತ್ತು stop_reason 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"}
}
]
} ಒಂದು ಟರ್ನ್ನಲ್ಲಿ ಹಲವು ಕರೆಗಳು
ಒಂದು ಉತ್ತರ ಹಲವು ಕರೆಗಳನ್ನು ಹೊತ್ತಿರಬಹುದು. ಅವೆಲ್ಲವನ್ನೂ ಚಲಾಯಿಸಿ, ಮುಂದಿನ ವಿನಂತಿಯಲ್ಲಿ ಪ್ರತಿ ಕರೆಗೆ ಒಂದು ಫಲಿತಾಂಶವನ್ನು, ಪ್ರತಿಯೊಂದೂ ತನ್ನದೇ tool_call_id ಜೊತೆ, ಕಳುಹಿಸಿ.
ಹೋಸ್ಟ್ ಮಾಡಿದ ಓಪನ್-ವೇಟ್ ಮಾಡೆಲ್ಗಳು ಪ್ರತಿ ಭಿನ್ನ ಕರೆಯನ್ನು ಒಮ್ಮೆ ಹಿಂತಿರುಗಿಸುತ್ತವೆ: ಒಂದೇ ಹೆಸರು ಮತ್ತು ಒಂದೇ arguments ಇರುವ ಎರಡು ಕರೆಗಳು ಒಂದಾಗಿ ಬರುತ್ತವೆ.
Stream ಮಾಡಿದ ಟೂಲ್ ಕರೆಗಳು
stream: true ಜೊತೆ, ಕರೆ ಒಂದೇ ತುಣುಕಾಗಿ ಬರುತ್ತದೆ: chunk ಸಂಪೂರ್ಣ arguments string ಅನ್ನು ಹೊಂದಿರುತ್ತದೆ, ಆದ್ದರಿಂದ ಜೋಡಿಸಬೇಕಾದ ತುಣುಕುಗಳಿಲ್ಲ. index ಟರ್ನ್ನ ಕರೆಗಳನ್ನು 0 ಯಿಂದ ಎಣಿಸುತ್ತದೆ.
{
"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
}
]
} | ಎಂಡ್ಪಾಯಿಂಟ್ | ಏನು ಬರುತ್ತದೆ |
|---|---|
/v1/chat/completions | ಪ್ರತಿ ಕರೆಗೆ ಒಂದು chat.completion.chunk, ಕರೆ delta.tool_calls[0] ನಲ್ಲಿ. ಕೊನೆಯ chunk finish_reason: "tool_calls" ಮತ್ತು usage ಹೊಂದಿರುತ್ತದೆ. |
/v1/responses | ಪ್ರತಿ ಕರೆಗೆ: response.output_item.added (ಖಾಲಿ arguments ಇರುವ function_call ಐಟಂ), response.function_call_arguments.delta (ಸಂಪೂರ್ಣ string), response.function_call_arguments.done, response.output_item.done. |
/v1/messages | ಪ್ರತಿ ಕರೆಗೆ: content_block_start (ಖಾಲಿ input ಇರುವ tool_use ಬ್ಲಾಕ್), ಒಂದು content_block_delta ಅದರ input_json_delta.partial_json ಸಂಪೂರ್ಣ arguments ಪಠ್ಯ, content_block_stop. ನಂತರ message_delta stop_reason: "tool_use" ಅನ್ನು ಹೊತ್ತಿರುತ್ತದೆ. |
shannon-1.6-lite, shannon-1.6-pro, shannon-2-lite, shannon-2-pro ಮತ್ತು shannon-coder-1 ನಲ್ಲಿ, tools ಹೊತ್ತ stream ಮಾಡಿದ ವಿನಂತಿ ತನ್ನ ಉತ್ತರ ಪಠ್ಯವನ್ನು ಟರ್ನ್ನ ಕೊನೆಯಲ್ಲಿ ಒಂದೇ content delta ದಲ್ಲಿ ನೀಡುತ್ತದೆ. ಸ್ಟ್ರೀಮಿಂಗ್
ಫಲಿತಾಂಶಗಳನ್ನು ಹಿಂತಿರುಗಿಸುವುದು
ಎರಡನೇ ವಿನಂತಿ ಸಂಭಾಷಣೆಯನ್ನು ಪುನರಾವರ್ತಿಸಿ ಎರಡು ವಿಷಯಗಳನ್ನು ಸೇರಿಸುತ್ತದೆ: ಕರೆಗಳನ್ನು ಕೇಳಿದ assistant ಟರ್ನ್, ಮತ್ತು ಪ್ರತಿ ಕರೆಗೆ ಒಂದು ಫಲಿತಾಂಶ.
{
"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\"}"
}
]
}
]
} - assistant ಟರ್ನ್ ಅನ್ನು ನೀವು ಸ್ವೀಕರಿಸಿದಂತೆಯೇ, ಫಲಿತಾಂಶಗಳ ಮೊದಲು ಹಿಂತಿರುಗಿಸಿ. ಪ್ರತಿ ಫಲಿತಾಂಶವನ್ನು id ಮೂಲಕ ಅದರ ಕರೆಗೆ ಹೊಂದಿಸಲಾಗುತ್ತದೆ:
/v1/chat/completionsನಲ್ಲಿtool_call_id,/v1/responsesನಲ್ಲಿcall_id,/v1/messagesನಲ್ಲಿtool_use_id. - ಫಲಿತಾಂಶ ಪಠ್ಯ. ಆಬ್ಜೆಕ್ಟ್ ಅನ್ನು
contentಗೆ (/v1/responsesನಲ್ಲಿoutput) JSON string ಆಗಿ ಸೀರಿಯಲೈಸ್ ಮಾಡಿ./v1/messagesನಲ್ಲಿtool_resultಬ್ಲಾಕ್ನcontentಒಂದು string ಅಥವಾ ಪಠ್ಯ ಬ್ಲಾಕ್ಗಳ ಪಟ್ಟಿ. - assistant ಟರ್ನ್ನಲ್ಲಿ,
function.argumentsಬಂದಂತೆಯೇ JSON string ಆಗಿ ಉಳಿಯುತ್ತದೆ. - ಸಂಭಾಷಣೆ ಟೂಲ್ ಫಲಿತಾಂಶದೊಂದಿಗೆ ಕೊನೆಗೊಳ್ಳಬಹುದು. ಹೊಸ user ಸಂದೇಶ ಬೇಕಿಲ್ಲ: ಮಾಡೆಲ್ ಫಲಿತಾಂಶದಿಂದ ಮುಂದುವರಿಯುತ್ತದೆ.
- ನಿಮ್ಮ ಫಂಕ್ಷನ್ ವಿಫಲವಾದರೆ, ವೈಫಲ್ಯವನ್ನು ಫಲಿತಾಂಶ ಪಠ್ಯವಾಗಿ ಕಳುಹಿಸಿ. ಆಗ ಮಾಡೆಲ್ ಅದನ್ನು ವರದಿ ಮಾಡಬಹುದು ಅಥವಾ ಬೇರೊಂದು ಕರೆಯನ್ನು ಕೇಳಬಹುದು.
Schema ಕೀವರ್ಡ್ಗಳು
parameters (/v1/messages ನಲ್ಲಿ input_schema) ಒಂದು JSON Schema. Shannon 3 ಕುಟುಂಬ (shannon-3, shannon-3-pro, shannon-3.1, shannon-3.1-pro) ಮತ್ತು ಹೋಸ್ಟ್ ಮಾಡಿದ ಓಪನ್-ವೇಟ್ ಮಾಡೆಲ್ಗಳು ಅದನ್ನು ನೀವು ಕಳುಹಿಸಿದಂತೆಯೇ ಪಡೆಯುತ್ತವೆ.
shannon-1.6-lite, shannon-1.6-pro, shannon-2-lite, shannon-2-pro ಮತ್ತು shannon-coder-1 ಮೂರೂ ಎಂಡ್ಪಾಯಿಂಟ್ಗಳಲ್ಲಿ ಈ ಉಪಗಣವನ್ನು ಪಡೆಯುತ್ತವೆ:
| ನಿರ್ವಹಣೆ | ಕೀವರ್ಡ್ಗಳು |
|---|---|
| ಕಳುಹಿಸಿದಂತೆಯೇ ಓದಲಾಗುತ್ತದೆ | ಕೆಳಗಿನ ಸಾಲುಗಳಲ್ಲಿ ಹೆಸರಿಸದ ಪ್ರತಿ ಕೀವರ್ಡ್, ಉದಾಹರಣೆಗೆ type, properties, required, items, enum, description, minimum, maximum, anyOf ಮತ್ತು allOf, schema ಯ ಪ್ರತಿ ಹಂತದಲ್ಲಿ. |
format | int32, int64, float, double, byte, date, date-time ಮತ್ತು enum ಮೌಲ್ಯಗಳಿಗೆ ಓದಲಾಗುತ್ತದೆ. |
oneOf | anyOf ಎಂದು ಓದಲಾಗುತ್ತದೆ. |
| ಈ ಮಾಡೆಲ್ಗಳು ಪಡೆಯುವ schema ಯ ಭಾಗವಲ್ಲ | $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 ಮತ್ತು exclusiveMaximum; format ನ ಇತರ ಮೌಲ್ಯಗಳು. |
ವರ್ತನೆ ಮತ್ತು ಮಿತಿಗಳು
- API ಟೂಲ್ಗಳ ಗರಿಷ್ಠ ಸಂಖ್ಯೆಯನ್ನಾಗಲಿ ಸುತ್ತುಗಳ ಗರಿಷ್ಠ ಸಂಖ್ಯೆಯನ್ನಾಗಲಿ ನಿಗದಿಪಡಿಸುವುದಿಲ್ಲ.
- ವಿನಂತಿ ಬಾಡಿ 32 MiB ವರೆಗೆ ಇರಬಹುದು, ಮತ್ತು ಫಲಿತಾಂಶಗಳೊಂದಿಗಿನ ಸಂಭಾಷಣೆ ಮಾಡೆಲ್ನ ಕಾಂಟೆಕ್ಸ್ಟ್ ವಿಂಡೋಗೆ ಹೊಂದಬೇಕು.
- ವಿನಂತಿ
toolsಹೊತ್ತಿರುವಾಗ,shannon-1.6-lite,shannon-1.6-pro,shannon-2-liteಮತ್ತುshannon-2-proಡೀಫಾಲ್ಟ್temperature0.2 ಬಳಸುತ್ತವೆ. ಬೇರೆ ಮೌಲ್ಯಕ್ಕಾಗಿtemperatureಕಳುಹಿಸಿ. - ಪ್ರತಿ ಸುತ್ತು ತನ್ನದೇ ವಿನಂತಿ: ಅದು ನಿಮ್ಮ ಬ್ಯಾಲೆನ್ಸ್ನಿಂದ ಬಳಸುತ್ತದೆ ಮತ್ತು ಬೇರೆ ಯಾವುದೇ ವಿನಂತಿಯಂತೆ ಫ್ಲಡ್ ಪ್ರೊಟೆಕ್ಷನ್ಗೆ ಎಣಿಕೆಯಾಗುತ್ತದೆ. ಮಿತಿಗಳು ಮತ್ತು ಬ್ಯಾಲೆನ್ಸ್
ದೋಷಗಳು
ಟೂಲ್ ಕರೆ ಸ್ಥಿತಿ 200 ಇರುವ ಸಾಮಾನ್ಯ ಉತ್ತರ. ಈ ದೋಷಗಳು ವಿನಂತಿಗೇ ಸಂಬಂಧಿಸಿವೆ:
| ಸ್ಥಿತಿ | ವಿಧ | ಸಂದೇಶ | ಯಾವಾಗ |
|---|---|---|---|
400 | invalid_request_error | unknown model: <id> | model ಪ್ರಕಟಿತ ಪಟ್ಟಿಯ id ಅಲ್ಲ. |
422 | invalid_request_error | Failed to deserialize the JSON body into the target type: … | tools array ಅಲ್ಲ, ಅಥವಾ ಬೇರೊಂದು ಫೀಲ್ಡ್ಗೆ ತಪ್ಪಾದ JSON ವಿಧವಿದೆ. |
413 | invalid_request_error | Failed to buffer the request body: … | ವಿನಂತಿ ಬಾಡಿ 32 MiB ಗಿಂತ ದೊಡ್ಡದಾಗಿದೆ. ದೋಷವು code: "request_too_large" ಹೊತ್ತಿರುತ್ತದೆ. |
arguments ಗಳನ್ನು ಮಾಡೆಲ್ ಬರೆಯುತ್ತದೆ. ಫಂಕ್ಷನ್ ಚಲಾಯಿಸುವ ಮೊದಲು, ಯಾವುದೇ ಹೊರಗಿನ ಇನ್ಪುಟ್ ಅನ್ನು ಪರಿಶೀಲಿಸುವಂತೆ, ಅವನ್ನು ನಿಮ್ಮ schema ವಿರುದ್ಧ ಪರಿಶೀಲಿಸಿ.
ದೃಢೀಕರಣ, ಬ್ಯಾಲೆನ್ಸ್ ಮತ್ತು ಸರ್ವರ್ ದೋಷಗಳು ಪ್ರತಿ ವಿನಂತಿಗೂ ಒಂದೇ ಆಗಿವೆ. ದೋಷ ನಿರ್ವಹಣೆ