కంటెంట్‌కు వెళ్లండి
నిర్మిత అవుట్‌పుట్‌లు

నిర్మిత అవుట్‌పుట్‌లు

సమాధానాన్ని JSON గా అడగండి: ఏదైనా JSON ఆబ్జెక్ట్, లేదా మీరు పంపే స్కీమాను అనుసరించే JSON. సమాధానాన్ని వ్యక్తి కాకుండా ఒక ప్రోగ్రామ్ చదివేటప్పుడు దీన్ని ఉపయోగించండి.

POST https://api.shannon-ai.com/v1/chat/completions

import json
from openai import OpenAI

client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.shannon-ai.com/v1")

response = client.chat.completions.create(
    model="Kimi-K3-uncensored-3BIT-REAP",
    messages=[
        {"role": "user", "content": "Extract the person: John Doe, 30 years old, engineer."}
    ],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "person",
            "strict": True,
            "schema": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "age": {"type": "integer"},
                    "occupation": {"type": "string"},
                },
                "required": ["name", "age", "occupation"],
            },
        },
    },
)

# The JSON arrives as text in message.content: parse it, then check it.
try:
    person = json.loads(response.choices[0].message.content)
except json.JSONDecodeError:
    person = None  # ask again, or report the failure

print(person)

JSON అనేది choices[0].message.content లోని సమాధాన టెక్స్ట్:

200 JSON
{
  "id": "chatcmpl-0c4e7a1b9d2f4e6a8b3c5d7e9f1a2b3c",
  "object": "chat.completion",
  "created": 1791590400,
  "model": "Kimi-K3-uncensored-3BIT-REAP",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "{\"name\":\"John Doe\",\"age\":30,\"occupation\":\"engineer\"}",
        "reasoning_content": null
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 96,
    "completion_tokens": 19,
    "total_tokens": 115,
    "prompt_tokens_details": {"cached_tokens": 0},
    "completion_tokens_details": {"reasoning_tokens": 0}
  }
}

response_format లో ఉండే మోడ్‌లు ఏమిటి

response_format అనేది /v1/chat/completions లోని ఒక ఫీల్డ్. అది లేకపోతే సమాధానం సాధారణ టెక్స్ట్.

మోడ్ విలువ మీరు పొందేది
JSON ఆబ్జెక్ట్ {"type": "json_object"} సమాధానం నిర్దేశిత ఆకృతి లేని JSON. మీకు ఏ కీలు కావాలో ప్రాంప్ట్‌లో చెప్పండి.
JSON స్కీమా {"type": "json_schema", "json_schema": {"name": "…", "schema": {…}}} సమాధానం మీరు పంపే స్కీమాను అనుసరిస్తుంది: దాని కీలు, రకాలు మరియు తప్పనిసరి ఫీల్డ్‌లు.
స్ట్రిక్ట్ "strict": true json_schema లోని ఒక ఫీల్డ్, మూడవ మోడ్ కాదు. మీరు false పంపితే తప్ప అది true.
ఫీల్డ్ రకం డిఫాల్ట్ వివరణ వర్తింపజేసేవి
type string json_object లేదా json_schema. response_format లోపల తప్పనిసరి. text అంగీకరించబడుతుంది మరియు సాధారణ టెక్స్ట్ సమాధానం ఇస్తుంది. ఆ మోడ్‌ను అంగీకరించే ప్రతి మోడల్
json_schema.schema object సమాధానం అనుసరించే JSON Schema. type విలువ json_schema అయినప్పుడల్లా దీన్ని పంపండి. ఆ మోడ్‌ను అంగీకరించే ప్రతి మోడల్
json_schema.name string OpenAI ఫార్మాట్‌లో లాగా, స్కీమాకు ఒక లేబుల్. హోస్ట్ చేసిన ఓపెన్-వెయిట్ మోడల్స్
json_schema.strict boolean true సమాధానం స్కీమాను ఖచ్చితంగా అనుసరించాలా అనేది. Shannon మోడల్స్ ప్రతి స్కీమాను strict గా అమలు చేస్తాయి. హోస్ట్ చేసిన ఓపెన్-వెయిట్ మోడల్స్

JSON ఆబ్జెక్ట్ మోడ్‌కు స్కీమా అవసరం లేదు. ప్రాంప్ట్‌లో కీలను పేర్కొనండి:

రిక్వెస్ట్ బాడీ
{
  "model": "shannon-3",
  "messages": [
    {
      "role": "user",
      "content": "Name the capital of France. Answer as JSON with the keys city and country."
    }
  ],
  "response_format": {"type": "json_object"}
}

ప్రతి మోడల్‌కు మద్దతు

మోడల్ json_object json_schema
ప్రతి Shannon మోడల్ (shannon-*) అవును అవును
హోస్ట్ చేసిన ఓపెన్-వెయిట్ మోడల్స్, కింద పేర్కొన్నవి తప్ప అవును అవును
Laguna-S-2.1-uncensored-W4A16-AUTOROUND-REAP — —
inkling-uncensored-W4A16-AUTOROUND-REAP అవును —
LongCat-2.0-uncensored-W4A4 — —
LongCat-2.0-uncensored-NVFP4 — —

GET /v1/models ప్రతి id కు ఇదే తెలియజేస్తుంది: ప్రతి మోడల్‌లో capabilities.json_schema, మరియు హోస్ట్ చేసిన ఓపెన్-వెయిట్ మోడల్స్‌లో capabilities.response_format. మోడల్స్ & ధరలు

మద్దతు ఉన్న స్కీమా కీవర్డ్స్

మీ స్కీమాలో మోడల్‌కు ఏమి అందుతుందనేది మోడల్ మరియు ఎండ్‌పాయింట్‌ను బట్టి ఉంటుంది:

మోడల్స్ /v1/chat/completions /v1/responses
Shannon మోడల్స్ కింది కీవర్డ్ ఉపసమితి, strict గా అమలు చేయబడుతుంది. మీరు పంపిన స్కీమా అలాగే, strict గా అమలు చేయబడుతుంది.
హోస్ట్ చేసిన ఓపెన్-వెయిట్ మోడల్స్ మీరు పంపిన స్కీమా అలాగే. మీరు పంపకపోతే strict విలువ true. మీరు పంపిన స్కీమా అలాగే. మీరు పంపకపోతే strict విలువ true.

/v1/chat/completions లో Shannon మోడల్స్ యొక్క కీవర్డ్ ఉపసమితి:

కీవర్డ్ ఎలా చదవబడుతుంది
చదివే కీవర్డ్స్ type, format, title, description, nullable, enum, items, properties, required, minItems, maxItems, minimum, maximum, minLength, maxLength, pattern, anyOf, default
$ref స్కీమా పై స్థాయిలోని $defs లేదా definitions నుండి పరిష్కరించబడుతుంది. $ref పక్కన రాసిన description వంటి కీవర్డ్స్ ఉంచబడతాయి. సరిపోయే డెఫినిషన్ లేని రిఫరెన్స్‌ను {"type": "object"} గా చదువుతారు.
allOf సభ్యులు ఒకే స్కీమాగా విలీనం చేయబడతాయి. రెండు సభ్యులు ఒకే కీవర్డ్‌ను సెట్ చేస్తే, తర్వాతిది లెక్కలోకి వస్తుంది.
oneOf anyOf గా చదవబడుతుంది.
తమను తాము సూచించుకునే స్కీమాలు 24 స్థాయిల వరకు విస్తరించబడతాయి. అంతకంటే లోతైన స్థాయిని {"type": "object"} గా చదువుతారు.
ఉపసమితి వెలుపల మిగతా ప్రతి కీవర్డ్, ఉదాహరణకు additionalProperties, const, multipleOf, uniqueItems, exclusiveMinimum, exclusiveMaximum, patternProperties, prefixItems, minProperties, maxProperties, not మరియు if / then / else. ఇవి మోడల్‌కు అందే స్కీమాలో భాగం కావు.

/v1/responses లో ఇదే విధానం: text.format అనే ఫీల్డ్ ద్వారా

/v1/responses అదే రిక్వెస్ట్‌ను text.format గా రాస్తుంది. స్కీమా నేరుగా format లో, name మరియు strict పక్కన ఉంటుంది; json_schema కీ కింద కాదు. JSON ఆబ్జెక్ట్ మోడ్ కోసం {"format": {"type": "json_object"}} పంపండి.

రిక్వెస్ట్ బాడీ
{
  "model": "Kimi-K3-uncensored-3BIT-REAP",
  "input": "Extract the person: John Doe, 30 years old, engineer.",
  "text": {
    "format": {
      "type": "json_schema",
      "name": "person",
      "strict": true,
      "schema": {
        "type": "object",
        "properties": {
          "name": {"type": "string"},
          "age": {"type": "integer"},
          "occupation": {"type": "string"}
        },
        "required": ["name", "age", "occupation"]
      }
    }
  }
}

JSON అనేది message ఐటమ్‌లోని output_text భాగం యొక్క text:

200 JSON
{
  "output": [
    {
      "id": "msg_7e1d3c5b9a2f4d6e8c0b1a3f5e7d9c2b",
      "type": "message",
      "role": "assistant",
      "status": "completed",
      "content": [
        {
          "type": "output_text",
          "text": "{\"name\":\"John Doe\",\"age\":30,\"occupation\":\"engineer\"}",
          "annotations": []
        }
      ]
    }
  ]
}

ప్రతి మోడల్‌కు మద్దతు మరియు ఎర్రర్‌లు /v1/chat/completions లో ఉన్నవే. Responses API

/v1/messages లో: స్కీమాగా ఒక టూల్

Messages ఫార్మాట్‌లో స్ట్రక్చర్డ్-అవుట్‌పుట్ ఫీల్డ్ లేదు. అవే మోడల్స్ నుండి JSON కోసం, అదే కీతో /v1/chat/completions లేదా /v1/responses ను కాల్ చేయండి.

/v1/messages లోనే ఉండాలంటే, ఆబ్జెక్ట్‌ను ఒక టూల్‌గా వివరించండి: మీ స్కీమాను input_schema లో ఉంచి, tool_choice లో టూల్ పేరు ఇవ్వండి. అప్పుడు tool_use బ్లాక్ యొక్క input మీ ఆబ్జెక్ట్, అప్పటికే పార్స్ చేయబడి ఉంటుంది. పేరు పెట్టిన tool_choice ను హోస్ట్ చేసిన ఓపెన్-వెయిట్ మోడల్స్ అమలు చేస్తాయి.

రిక్వెస్ట్ బాడీ
{
  "model": "Kimi-K3-uncensored-3BIT-REAP",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": "Extract the person: John Doe, 30 years old, engineer."
    }
  ],
  "tools": [
    {
      "name": "record_person",
      "description": "Record the extracted person.",
      "input_schema": {
        "type": "object",
        "properties": {
          "name": {"type": "string"},
          "age": {"type": "integer"},
          "occupation": {"type": "string"}
        },
        "required": ["name", "age", "occupation"]
      }
    }
  ],
  "tool_choice": {"type": "tool", "name": "record_person"}
}
200 JSON
{
  "stop_reason": "tool_use",
  "content": [
    {
      "type": "tool_use",
      "id": "toolu_4b8d2f6a1c3e4a5b9d7f0e2c4a6b8d1f",
      "name": "record_person",
      "input": {"name": "John Doe", "age": 30, "occupation": "engineer"}
    }
  ]
}

బ్లాక్‌ను చదివే ముందు stop_reason విలువ tool_use అని తనిఖీ చేయండి. ఫంక్షన్ కాలింగ్

JSON ఎలా వస్తుంది

  • JSON ఒక string. సమాధానంలో దాని పక్కన పార్స్ చేసిన ఆబ్జెక్ట్ ఉండదు: message.content పై మీ JSON పార్సర్‌ను నడపండి.
  • stream: true తో JSON delta.content ముక్కలుగా వస్తుంది. వాటిని కలిపి, స్ట్రీమ్ ముగిసిన తర్వాత ఒక్కసారి పార్స్ చేయండి; ఒక్క ముక్క మాత్రమే చెల్లుబాటు అయ్యే JSON కాదు.
  • హోస్ట్ చేసిన ఓపెన్-వెయిట్ మోడల్ response_format రిక్వెస్ట్‌కు రీజనింగ్ టెక్స్ట్ లేకుండా సమాధానం ఇస్తుంది: reasoning_content విలువ null.

మీకు అందినదాన్ని తనిఖీ చేయండి

మోడల్ ఎలా రాయాలో స్కీమా మార్గనిర్దేశం చేస్తుంది. పూర్తయిన సమాధానాన్ని API మీ స్కీమాతో పోల్చదు, కాబట్టి తుది తనిఖీని మీ కోడ్ చేయాలి:

  • పైన ఉన్న నమూనా చేసినట్లే, ఎర్రర్ హ్యాండ్లర్ లోపల పార్స్ చేయండి.
  • పార్స్ చేసిన ఆబ్జెక్ట్‌ను అదే స్కీమాతో మీ స్వంత కోడ్‌లో వాలిడేట్ చేయండి, ఉదాహరణకు JSON Schema లైబ్రరీ, Pydantic లేదా Zod తో.
  • JSON పూర్తి కాకముందే పొడవైన సమాధానం ముగియవచ్చు. స్ట్రీమ్ చేయని సమాధానం finish_reason ను stop లేదా tool_calls గా మాత్రమే చూపుతుంది, కాబట్టి పార్స్ ఎర్రర్ రావడమే సంకేతం. మళ్ళీ అడగండి, లేదా చిన్న ఆబ్జెక్ట్ అడగండి.

ఎర్రర్‌లు

స్టేటస్ రకం మెసేజ్ ఎప్పుడు
400 invalid_request_error <id> does not accept response_format ఆ మోడల్ రెండు మోడ్‌లలో ఏదీ అంగీకరించదు.
400 invalid_request_error <id> does not accept response_format json_schema; use json_object ఆ మోడల్ json_object ను అంగీకరిస్తుంది, మీరు json_schema పంపారు.
400 invalid_request_error <id> accepts only response_format json_schema ఆ మోడల్ json_schema ను మాత్రమే అంగీకరిస్తుంది, మీరు json_object పంపారు.
422 invalid_request_error Failed to deserialize the JSON body into the target type: … response_format లో type లేదు, లేదా అది JSON ఆబ్జెక్ట్ కాదు.

ఆ రెండు 400 సమాధానాలు మీ బ్యాలెన్స్ నుండి ఏదైనా తీసుకునే ముందే పంపబడతాయి. ఎరర్ హ్యాండ్లింగ్

SHANNON NVIDIA Inception కార్యక్రమం బ్యాడ్జ్ SHANNON LAB LLC NVIDIA Inception కార్యక్రమంలో సభ్యురాలు.

మీ భాషను ఎంచుకోండి

అన్ని భాషలు సమానమే. మీరు ఉపయోగించాలనుకునే భాషను ఎంచుకోండి.

యూరప్

మధ్యప్రాచ్యం & ఉత్తర ఆఫ్రికా

దక్షిణ ఆసియా

ఆగ్నేయ ఆసియా

తూర్పు ఆసియా

మధ్య ఆసియా & కాకసస్

ఆఫ్రికా

ఓషియానియా

కృత్రిమ & ప్రాచీన భాషలు