ਸਮੱਗਰੀ ਤੇ ਜਾਓ
ਫੰਕਸ਼ਨ ਕਾਲਿੰਗ

ਫੰਕਸ਼ਨ ਕਾਲਿੰਗ

ਰਿਕੁਐਸਟ ਵਿੱਚ ਆਪਣੇ ਫੰਕਸ਼ਨਾਂ ਦਾ ਵਰਣਨ ਕਰੋ ਅਤੇ ਮਾਡਲ ਉਨ੍ਹਾਂ ਕਾਲਾਂ ਨਾਲ ਜਵਾਬ ਦਿੰਦਾ ਹੈ ਜੋ ਉਹ ਕਰਵਾਉਣਾ ਚਾਹੁੰਦਾ ਹੈ। ਤੁਹਾਡਾ ਕੋਡ ਉਨ੍ਹਾਂ ਨੂੰ ਚਲਾਉਂਦਾ ਹੈ ਅਤੇ ਨਤੀਜੇ ਵਾਪਸ ਭੇਜਦਾ ਹੈ: 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)

ਪਹਿਲਾ ਜਵਾਬ ਸਵਾਲ ਦਾ ਉੱਤਰ ਨਹੀਂ ਦਿੰਦਾ। ਇਹ ਇੱਕ ਕਾਲ ਮੰਗਦਾ ਹੈ:

200 JSON
{
  "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 ਨੂੰ parse ਕਰੋ ਅਤੇ ਆਪਣਾ ਫੰਕਸ਼ਨ ਚਲਾਓ।
4 ਤੁਸੀਂ assistant message ਅਤੇ ਹਰ ਕਾਲ ਲਈ ਇੱਕ tool message ਨੂੰ messages ਵਿੱਚ ਜੋੜੋ, ਫਿਰ ਉਹੀ tools ਲੈ ਕੇ ਰਿਕੁਐਸਟ ਦੁਬਾਰਾ ਭੇਜੋ।
5 ਮਾਡਲ ਮਾਡਲ finish_reason: "stop" ਨਾਲ ਟੈਕਸਟ ਵਿੱਚ ਜਵਾਬ ਦਿੰਦਾ ਹੈ, ਜਾਂ ਹੋਰ ਕਾਲਾਂ ਮੰਗਦਾ ਹੈ। ਉਸ ਸੂਰਤ ਵਿੱਚ ਕਦਮ 3 ਉੱਤੇ ਵਾਪਸ ਜਾਓ।

ਇੱਕ ਰਿਕੁਐਸਟ ਮਾਡਲ ਦਾ ਇੱਕ turn ਹੈ। API ਰਿਕੁਐਸਟਾਂ ਦੇ ਵਿਚਕਾਰ ਕੋਈ ਗੱਲਬਾਤ ਨਹੀਂ ਰੱਖਦੀ ਅਤੇ ਗੇੜਾਂ ਦੀ ਕੋਈ ਗਿਣਤੀ ਤੈਅ ਨਹੀਂ ਕਰਦੀ: ਤੁਹਾਡਾ ਕੋਡ messages ਸੰਭਾਲਦਾ ਹੈ ਅਤੇ ਫੈਸਲਾ ਕਰਦਾ ਹੈ ਕਿ ਕਦੋਂ ਰੁਕਣਾ ਹੈ।

ਟੂਲ ਪਰਿਭਾਸ਼ਿਤ ਕਰਨਾ

tools ਇੱਕ array ਹੈ ਜਿਸ ਵਿੱਚ ਹਰ ਫੰਕਸ਼ਨ ਲਈ ਇੱਕ ਐਂਟਰੀ ਹੁੰਦੀ ਹੈ। ਕੈਟਾਲਾਗ ਦਾ ਹਰ ਮਾਡਲ ਇਸ ਨੂੰ ਸਵੀਕਾਰ ਕਰਦਾ ਹੈ; GET /v1/models ਹਰ id ਲਈ capabilities.tools: true ਦੱਸਦਾ ਹੈ।

ਫੀਲਡ ਕਿਸਮ ਵੇਰਵਾ
type string ਹਮੇਸ਼ਾ function।
function.name string ਉਹ ਨਾਂ ਜੋ ਮਾਡਲ ਇਸ ਫੰਕਸ਼ਨ ਨੂੰ ਮੰਗਣ ਵੇਲੇ ਵਰਤਦਾ ਹੈ। ਲਾਜ਼ਮੀ।
function.description string ਫੰਕਸ਼ਨ ਕੀ ਕਰਦਾ ਹੈ, ਸਾਦੀ ਭਾਸ਼ਾ ਵਿੱਚ।
function.parameters object arguments ਇੱਕ JSON Schema ਵਜੋਂ ਜਿਸ ਦੇ ਸਿਖਰ ਉੱਤੇ type: "object" ਹੈ। ਹੇਠਾਂ Schema ਕੀਵਰਡ ਵੇਖੋ।

ਹਰ endpoint ਦੀ ਟੂਲ ਲਿਖਣ ਦੀ ਆਪਣੀ ਸ਼ਕਲ ਹੈ। ਉਹ ਭੇਜੋ ਜੋ ਉਸ endpoint ਦੀ ਹੈ ਜਿਸ ਨੂੰ ਤੁਸੀਂ ਕਾਲ ਕਰਦੇ ਹੋ:

{
  "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"]
    }
  }
}

tool_choice

tool_choice ਦੱਸਦਾ ਹੈ ਕਿ ਮਾਡਲ ਟੂਲ ਕਾਲ ਕਰ ਸਕਦਾ ਹੈ ਜਾਂ ਉਸ ਨੂੰ ਕਰਨਾ ਹੀ ਪਵੇਗਾ। ਇਹ ਸਿਰਫ਼ tools ਦੇ ਨਾਲ ਹੀ ਪੜ੍ਹਿਆ ਜਾਂਦਾ ਹੈ।

ਮੁੱਲ ਵੇਰਵਾ ਲਾਗੂ ਕਰਨ ਵਾਲੇ
"auto" ਮਾਡਲ ਫੈਸਲਾ ਕਰਦਾ ਹੈ ਕਿ ਟੈਕਸਟ ਵਿੱਚ ਜਵਾਬ ਦੇਣਾ ਹੈ ਜਾਂ ਟੂਲ ਕਾਲ ਕਰਨਾ ਹੈ। ਇਹ ਡਿਫਾਲਟ ਹੈ। ਸਾਰੇ ਮਾਡਲ
"required" ਜਵਾਬ ਘੱਟੋ-ਘੱਟ ਇੱਕ ਟੂਲ ਨੂੰ ਕਾਲ ਕਰਦਾ ਹੈ। ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ
{"type": "function", "function": {"name": "get_weather"}} ਜਵਾਬ ਇਸ ਫੰਕਸ਼ਨ ਨੂੰ ਕਾਲ ਕਰਦਾ ਹੈ। ਨਾਂ tools ਵਿਚਲੇ ਫੰਕਸ਼ਨਾਂ ਵਿੱਚੋਂ ਇੱਕ ਹੋਣਾ ਚਾਹੀਦਾ ਹੈ। ਹੋਰ ਫੰਕਸ਼ਨਾਂ ਦੀਆਂ ਕਾਲਾਂ ਜਵਾਬ ਵਿੱਚੋਂ ਛੱਡ ਦਿੱਤੀਆਂ ਜਾਂਦੀਆਂ ਹਨ। ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ

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। ਬਿਨਾਂ ਟੂਲ ਕਾਲਾਂ ਵਾਲੇ turn ਲਈ, ਰਿਕੁਐਸਟ 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 ਵਜੋਂ, ਜੇ ਕੋਈ ਨਾ ਹੋਣ ਤਾਂ "{}"। ਵਰਤਣ ਤੋਂ ਪਹਿਲਾਂ ਇਸ ਨੂੰ parse ਕਰੋ।
message.content string | null ਜਦੋਂ ਜਵਾਬ ਵਿੱਚ ਸਿਰਫ਼ ਕਾਲਾਂ ਹੋਣ ਤਾਂ null। ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ ਕਾਲਾਂ ਦੇ ਨਾਲ ਟੈਕਸਟ ਵੀ ਵਾਪਸ ਕਰ ਸਕਦੇ ਹਨ; Shannon ਮਾਡਲ null ਵਾਪਸ ਕਰਦੇ ਹਨ।

ਹਰ ਫਾਰਮੈਟ ਵਿੱਚ ਉਹੀ ਕਾਲ। /v1/responses ਉੱਤੇ ਇਹ output ਦੀ function_call ਆਈਟਮ ਹੈ, ਜਿਸ ਦੇ arguments JSON string ਹਨ। /v1/messages ਉੱਤੇ ਇਹ tool_use content block ਹੈ ਜਿਸ ਦਾ input JSON object ਹੈ, ਇਸ ਦੀ 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\"}"
        }
      }
    ]
  }
}

ਇੱਕ turn ਵਿੱਚ ਕਈ ਕਾਲਾਂ

ਇੱਕ ਜਵਾਬ ਵਿੱਚ ਕਈ ਕਾਲਾਂ ਹੋ ਸਕਦੀਆਂ ਹਨ। ਉਨ੍ਹਾਂ ਸਭ ਨੂੰ ਚਲਾਓ ਅਤੇ ਅਗਲੀ ਰਿਕੁਐਸਟ ਵਿੱਚ ਹਰ ਕਾਲ ਲਈ ਇੱਕ ਨਤੀਜਾ ਭੇਜੋ, ਹਰ ਇੱਕ ਆਪਣੇ tool_call_id ਨਾਲ।

ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ ਹਰ ਵੱਖਰੀ ਕਾਲ ਨੂੰ ਇੱਕ ਵਾਰ ਵਾਪਸ ਕਰਦੇ ਹਨ: ਇੱਕੋ ਨਾਂ ਅਤੇ ਇੱਕੋ arguments ਵਾਲੀਆਂ ਦੋ ਕਾਲਾਂ ਇੱਕ ਵਜੋਂ ਪਹੁੰਚਦੀਆਂ ਹਨ।

stream ਕੀਤੀਆਂ ਟੂਲ ਕਾਲਾਂ

stream: true ਨਾਲ ਕਾਲ ਇੱਕੋ ਟੁਕੜੇ ਵਿੱਚ ਪਹੁੰਚਦੀ ਹੈ: chunk ਵਿੱਚ ਪੂਰੀ arguments string ਹੁੰਦੀ ਹੈ, ਇਸ ਲਈ ਜੋੜਨ ਲਈ ਕੋਈ ਟੁਕੜੇ ਨਹੀਂ ਹੁੰਦੇ। index turn ਦੀਆਂ ਕਾਲਾਂ ਨੂੰ 0 ਤੋਂ ਗਿਣਦਾ ਹੈ।

data: ਇੱਕ chunk, ਫਾਰਮੈਟ ਕੀਤਾ ਹੋਇਆ
{
  "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 block), ਇੱਕ 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 ਕੀਤੀ ਰਿਕੁਐਸਟ ਆਪਣੇ ਜਵਾਬ ਦਾ ਟੈਕਸਟ turn ਦੇ ਅੰਤ ਵਿੱਚ ਇੱਕ content delta ਵਿੱਚ ਦਿੰਦੀ ਹੈ। ਸਟ੍ਰੀਮਿੰਗ

ਨਤੀਜੇ ਵਾਪਸ ਭੇਜਣਾ

ਦੂਜੀ ਰਿਕੁਐਸਟ ਗੱਲਬਾਤ ਨੂੰ ਦੁਹਰਾਉਂਦੀ ਹੈ ਅਤੇ ਦੋ ਚੀਜ਼ਾਂ ਜੋੜਦੀ ਹੈ: ਉਹ assistant turn ਜਿਸ ਨੇ ਕਾਲਾਂ ਮੰਗੀਆਂ, ਅਤੇ ਹਰ ਕਾਲ ਲਈ ਇੱਕ ਨਤੀਜਾ।

{
  "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\"}"
    }
  ]
}
  • assistant turn ਨੂੰ ਨਤੀਜਿਆਂ ਤੋਂ ਪਹਿਲਾਂ ਉਸੇ ਤਰ੍ਹਾਂ ਵਾਪਸ ਭੇਜੋ ਜਿਵੇਂ ਤੁਹਾਨੂੰ ਮਿਲਿਆ ਸੀ। ਹਰ ਨਤੀਜਾ id ਨਾਲ ਆਪਣੀ ਕਾਲ ਨਾਲ ਮਿਲਾਇਆ ਜਾਂਦਾ ਹੈ: /v1/chat/completions ਉੱਤੇ tool_call_id, /v1/responses ਉੱਤੇ call_id, /v1/messages ਉੱਤੇ tool_use_id।
  • ਨਤੀਜਾ ਟੈਕਸਟ ਹੁੰਦਾ ਹੈ। content (/v1/responses ਉੱਤੇ output) ਲਈ object ਨੂੰ JSON string ਵਿੱਚ ਬਦਲੋ। /v1/messages ਉੱਤੇ tool_result block ਦਾ content ਇੱਕ string ਜਾਂ text blocks ਦੀ ਸੂਚੀ ਹੁੰਦਾ ਹੈ।
  • assistant turn ਵਿੱਚ function.arguments JSON string ਹੀ ਰਹਿੰਦਾ ਹੈ, ਬਿਲਕੁਲ ਉਸੇ ਤਰ੍ਹਾਂ ਜਿਵੇਂ ਇਹ ਪਹੁੰਚਿਆ ਸੀ।
  • ਗੱਲਬਾਤ ਟੂਲ ਦੇ ਨਤੀਜੇ ਨਾਲ ਖਤਮ ਹੋ ਸਕਦੀ ਹੈ। ਨਵੇਂ user message ਦੀ ਲੋੜ ਨਹੀਂ: ਮਾਡਲ ਨਤੀਜੇ ਤੋਂ ਅੱਗੇ ਚੱਲਦਾ ਹੈ।
  • ਜਦੋਂ ਤੁਹਾਡਾ ਫੰਕਸ਼ਨ ਅਸਫਲ ਹੋ ਜਾਵੇ, ਤਾਂ ਅਸਫਲਤਾ ਨੂੰ ਨਤੀਜੇ ਦੇ ਟੈਕਸਟ ਵਜੋਂ ਭੇਜੋ। ਫਿਰ ਮਾਡਲ ਇਸ ਦੀ ਰਿਪੋਰਟ ਕਰ ਸਕਦਾ ਹੈ ਜਾਂ ਹੋਰ ਕਾਲ ਮੰਗ ਸਕਦਾ ਹੈ।

Schema ਕੀਵਰਡ

parameters (/v1/messages ਉੱਤੇ input_schema) ਇੱਕ JSON Schema ਹੈ। Shannon 3 ਪਰਿਵਾਰ (shannon-3, shannon-3-pro, shannon-3.1, shannon-3.1-pro) ਅਤੇ ਹੋਸਟ ਕੀਤੇ open-weight ਮਾਡਲ ਇਸ ਨੂੰ ਉਸੇ ਤਰ੍ਹਾਂ ਪ੍ਰਾਪਤ ਕਰਦੇ ਹਨ ਜਿਵੇਂ ਤੁਸੀਂ ਭੇਜਦੇ ਹੋ।

shannon-1.6-lite, shannon-1.6-pro, shannon-2-lite, shannon-2-pro ਅਤੇ shannon-coder-1 ਤਿੰਨਾਂ endpoints ਉੱਤੇ ਇਹ ਉਪ-ਸਮੂਹ ਪ੍ਰਾਪਤ ਕਰਦੇ ਹਨ:

ਸਲੂਕ ਕੀਵਰਡ
ਜਿਵੇਂ ਭੇਜਿਆ ਤਿਵੇਂ ਪੜ੍ਹਿਆ ਜਾਂਦਾ ਹੈ ਹਰ ਕੀਵਰਡ ਜਿਸ ਦਾ ਨਾਂ ਹੇਠਾਂ ਦੀਆਂ ਕਤਾਰਾਂ ਵਿੱਚ ਨਹੀਂ ਲਿਆ ਗਿਆ, ਉਦਾਹਰਣ ਵਜੋਂ 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 ਟੂਲਾਂ ਦੀ ਕੋਈ ਵੱਧ ਤੋਂ ਵੱਧ ਗਿਣਤੀ ਅਤੇ ਗੇੜਾਂ ਦੀ ਕੋਈ ਵੱਧ ਤੋਂ ਵੱਧ ਗਿਣਤੀ ਤੈਅ ਨਹੀਂ ਕਰਦੀ।
  • ਰਿਕੁਐਸਟ body 32 MiB ਤੱਕ ਹੋ ਸਕਦੀ ਹੈ, ਅਤੇ ਨਤੀਜਿਆਂ ਸਮੇਤ ਗੱਲਬਾਤ ਨੂੰ ਮਾਡਲ ਦੀ ਕਾਂਟੈਕਸਟ ਵਿੰਡੋ ਵਿੱਚ ਸਮਾਉਣਾ ਚਾਹੀਦਾ ਹੈ।
  • ਜਦੋਂ ਰਿਕੁਐਸਟ ਵਿੱਚ tools ਹੋਵੇ, ਤਾਂ shannon-1.6-lite, shannon-1.6-pro, shannon-2-lite ਅਤੇ shannon-2-pro ਡਿਫਾਲਟ temperature 0.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: … ਰਿਕੁਐਸਟ body 32 MiB ਤੋਂ ਵੱਡੀ ਹੈ। ਗਲਤੀ ਵਿੱਚ code: "request_too_large" ਹੁੰਦਾ ਹੈ।

arguments ਮਾਡਲ ਲਿਖਦਾ ਹੈ। ਫੰਕਸ਼ਨ ਚਲਾਉਣ ਤੋਂ ਪਹਿਲਾਂ ਉਨ੍ਹਾਂ ਨੂੰ ਆਪਣੀ schema ਨਾਲ ਜਾਂਚੋ, ਜਿਵੇਂ ਤੁਸੀਂ ਕਿਸੇ ਵੀ ਬਾਹਰੀ ਇਨਪੁਟ ਨੂੰ ਜਾਂਚੋਗੇ।

ਪ੍ਰਮਾਣਿਕਤਾ, ਬੈਲੇਂਸ ਅਤੇ ਸਰਵਰ ਦੀਆਂ ਗਲਤੀਆਂ ਉਹੀ ਹਨ ਜੋ ਹਰ ਰਿਕੁਐਸਟ ਲਈ ਹੁੰਦੀਆਂ ਹਨ। ਗਲਤੀਆਂ