உள்ளடக்கத்துக்குச் செல்
கட்டமைக்கப்பட்ட வெளியீடுகள்

கட்டமைக்கப்பட்ட வெளியீடுகள்

பதிலை JSON ஆகக் கேளுங்கள்: ஏதேனும் JSON object, அல்லது நீங்கள் அனுப்பும் schema-வைப் பின்பற்றும் 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-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-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 object {"type": "json_object"} பதில் குறிப்பிட்ட வடிவம் இல்லாத JSON. எந்த keys வேண்டும் என்பதை prompt-ல் கூறவும்.
JSON schema {"type": "json_schema", "json_schema": {"name": "…", "schema": {…}}} பதில் நீங்கள் அனுப்பும் schema-வைப் பின்பற்றும்: அதன் keys, வகைகள் மற்றும் கட்டாயப் புலங்கள்.
Strict "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 வடிவத்தில் உள்ளது போல, schema-வுக்கான ஒரு லேபிள். ஹோஸ்ட் செய்யப்பட்ட open-weight மாடல்கள்
json_schema.strict boolean true பதில் schema-வை அப்படியே பின்பற்ற வேண்டுமா என்பது. Shannon மாடல்கள் ஒவ்வொரு schema-வையும் strict ஆகச் செயல்படுத்தும். ஹோஸ்ட் செய்யப்பட்ட open-weight மாடல்கள்

JSON object முறைக்கு schema தேவையில்லை. keys-ஐ prompt-ல் பெயரிடவும்:

கோரிக்கை body
{
  "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-*) ஆம் ஆம்
கீழே பெயரிடப்பட்டவை தவிர, ஹோஸ்ட் செய்யப்பட்ட open-weight மாடல்கள் ஆம் ஆம்
Laguna-S-2.1-W4A16-AUTOROUND-REAP — —
inkling-W4A16-AUTOROUND-REAP ஆம் —

GET /v1/models ஒவ்வொரு id-க்கும் இதையே தெரிவிக்கிறது: ஒவ்வொரு மாடலிலும் capabilities.json_schema, ஹோஸ்ட் செய்யப்பட்ட open-weight மாடல்களில் capabilities.response_format. மாடல்கள் & விலை

ஆதரிக்கப்படும் schema திறவுச்சொற்கள்

உங்கள் schema-வில் மாடல் எதைப் பெறுகிறது என்பது மாடலையும் endpoint-ஐயும் பொறுத்தது:

மாடல்கள் /v1/chat/completions /v1/responses
Shannon மாடல்கள் கீழே உள்ள திறவுச்சொல் துணைக்கணம், strict ஆகச் செயல்படுத்தப்படும். நீங்கள் அனுப்பும் schema அப்படியே, strict ஆகச் செயல்படுத்தப்படும்.
ஹோஸ்ட் செய்யப்பட்ட open-weight மாடல்கள் நீங்கள் அனுப்பும் schema அப்படியே. நீங்கள் அனுப்பாவிட்டால் strict true ஆகும். நீங்கள் அனுப்பும் schema அப்படியே. நீங்கள் அனுப்பாவிட்டால் 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 schema-வின் மேல்மட்டத்தில் உள்ள $defs அல்லது definitions-ல் இருந்து தீர்க்கப்படும். $ref-க்கு அருகில் எழுதப்பட்ட description போன்ற திறவுச்சொற்கள் வைத்துக்கொள்ளப்படும். பொருந்தும் வரையறை இல்லாத குறிப்பு {"type": "object"} ஆகப் படிக்கப்படும்.
allOf உறுப்புகள் ஒரே schema ஆக இணைக்கப்படும். இரண்டு உறுப்புகள் ஒரே திறவுச்சொல்லை அமைத்தால், பின்னதே செல்லுபடியாகும்.
oneOf anyOf ஆகப் படிக்கப்படும்.
தம்மையே குறிப்பிடும் schemas 24 நிலைகள் வரை விரிவாக்கப்படும். அதற்கும் ஆழமான நிலை {"type": "object"} ஆகப் படிக்கப்படும்.
துணைக்கணத்திற்கு வெளியே மற்ற ஒவ்வொரு திறவுச்சொல்லும், எடுத்துக்காட்டாக additionalProperties, const, multipleOf, uniqueItems, exclusiveMinimum, exclusiveMaximum, patternProperties, prefixItems, minProperties, maxProperties, not மற்றும் if / then / else. இவை மாடல் பெறும் schema-வின் பகுதியாகாது.

/v1/responses-ல்: text.format என்ற புலம் வழியாக

/v1/responses அதே கோரிக்கையை text.format ஆக எழுதுகிறது. schema நேரடியாக format-க்குள், name மற்றும் strict அருகில் இருக்கும்; json_schema key-ன் கீழ் அல்ல. JSON object முறைக்கு {"format": {"type": "json_object"}} அனுப்பவும்.

கோரிக்கை body
{
  "model": "Kimi-K3-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 item-ன் 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-ல்: schema ஆகச் செயல்படும் ஒரு கருவி (tool)

Messages வடிவத்தில் structured-output புலம் இல்லை. அதே மாடல்களிலிருந்து JSON பெற, அதே key உடன் /v1/chat/completions அல்லது /v1/responses-ஐ அழைக்கவும்.

/v1/messages-லேயே இருக்க, object-ஐ ஒரு tool ஆக விவரிக்கவும்: உங்கள் schema-வை input_schema-ல் வைத்து, tool_choice-ல் tool-ஐப் பெயரிடவும். அப்போது tool_use block-ன் input ஏற்கெனவே parse செய்யப்பட்ட உங்கள் object ஆகும். பெயரிடப்பட்ட tool_choice-ஐ ஹோஸ்ட் செய்யப்பட்ட open-weight மாடல்கள் செயல்படுத்தும்.

கோரிக்கை body
{
  "model": "Kimi-K3-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"}
    }
  ]
}

block-ஐப் படிக்கும் முன் stop_reason tool_use என்பதைச் சோதிக்கவும். செயல்பாடு அழைப்பு

JSON எவ்வாறு வருகிறது

  • JSON ஒரு string. அதனுடன் parse செய்யப்பட்ட object எதுவும் பதிலில் இல்லை: message.content-ல் உங்கள் JSON parser-ஐ இயக்கவும்.
  • stream: true உடன் JSON delta.content துண்டுகளாக வரும். அவற்றை இணைத்து, stream முடிந்த பிறகு ஒரு முறை parse செய்யவும்; தனித் துண்டு செல்லுபடியாகும் JSON அல்ல.
  • ஹோஸ்ட் செய்யப்பட்ட open-weight மாடல் response_format கோரிக்கைக்கு reasoning உரை இல்லாமல் பதிலளிக்கும்: reasoning_content null ஆகும்.

நீங்கள் பெறுவதைச் சரிபார்க்கவும்

schema மாடல் எழுதும் முறையை வழிநடத்துகிறது. API முடிந்த பதிலை உங்கள் schema-வுடன் ஒப்பிடுவதில்லை; எனவே இறுதிச் சோதனையை உங்கள் குறியீடு செய்கிறது:

  • மேலே உள்ள மாதிரி செய்வது போல, பிழை கையாளியின் உள்ளே parse செய்யவும்.
  • parse செய்யப்பட்ட object-ஐ அதே schema-வுடன் உங்கள் சொந்தக் குறியீட்டில் சரிபார்க்கவும், எடுத்துக்காட்டாக JSON Schema library, Pydantic அல்லது Zod மூலம்.
  • JSON முழுமையடையும் முன் நீண்ட பதில் முடிந்துவிடலாம். stream செய்யப்படாத பதில் finish_reason-ஐ stop அல்லது tool_calls என்று மட்டுமே தெரிவிக்கும்; எனவே parse பிழையே அதற்கான அறிகுறி. மீண்டும் கேளுங்கள், அல்லது சிறிய object-ஐக் கேளுங்கள்.

பிழைகள்

நிலை வகை செய்தி எப்போது
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 அனுப்பினீர்கள்.
422 invalid_request_error Failed to deserialize the JSON body into the target type: … response_format-ல் type இல்லை, அல்லது அது JSON object அல்ல.

இந்த இரண்டு 400 பதில்களும் உங்கள் balance-ல் இருந்து எதுவும் கழிக்கப்படுவதற்கு முன்பே அனுப்பப்படுகின்றன. கையாளுவதில் பிழை