ವಿಷಯಕ್ಕೆ ಹೋಗಿ
ರಚಿತ ಔಟ್‌ಪುಟ್‌ಗಳು

ರಚಿತ ಔಟ್‌ಪುಟ್‌ಗಳು

ಉತ್ತರವನ್ನು JSON ಆಗಿ ಕೇಳಿ: ಯಾವುದೇ JSON ಆಬ್ಜೆಕ್ಟ್, ಅಥವಾ ನೀವು ಕಳುಹಿಸುವ 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 ಆಬ್ಜೆಕ್ಟ್ {"type": "json_object"} ಉತ್ತರ ನಿಗದಿತ ರೂಪವಿಲ್ಲದ JSON. ನಿಮಗೆ ಯಾವ ಕೀಗಳು ಬೇಕೆಂದು ಪ್ರಾಂಪ್ಟ್‌ನಲ್ಲಿ ಹೇಳಿ.
JSON schema {"type": "json_schema", "json_schema": {"name": "…", "schema": {…}}} ಉತ್ತರ ನೀವು ಕಳುಹಿಸುವ schema ಅನ್ನು ಅನುಸರಿಸುತ್ತದೆ: ಅದರ ಕೀಗಳು, ವಿಧಗಳು ಮತ್ತು ಅಗತ್ಯ ಫೀಲ್ಡ್‌ಗಳು.
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 ಗೆ ಒಂದು ಲೇಬಲ್. ಹೋಸ್ಟ್ ಮಾಡಿದ ಓಪನ್-ವೇಟ್ ಮಾಡೆಲ್‌ಗಳು
json_schema.strict boolean true ಉತ್ತರ schema ಅನ್ನು ನಿಖರವಾಗಿ ಅನುಸರಿಸಬೇಕೇ. Shannon ಮಾಡೆಲ್‌ಗಳು ಪ್ರತಿ schema ಅನ್ನು strict ಆಗಿ ಅನ್ವಯಿಸುತ್ತವೆ. ಹೋಸ್ಟ್ ಮಾಡಿದ ಓಪನ್-ವೇಟ್ ಮಾಡೆಲ್‌ಗಳು

JSON ಆಬ್ಜೆಕ್ಟ್ ಮೋಡ್‌ಗೆ schema ಬೇಕಿಲ್ಲ. ಪ್ರಾಂಪ್ಟ್‌ನಲ್ಲಿ ಕೀಗಳನ್ನು ಹೆಸರಿಸಿ:

ವಿನಂತಿ ಬಾಡಿ
{
  "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-W4A16-AUTOROUND-REAP — —
inkling-W4A16-AUTOROUND-REAP ಹೌದು —

GET /v1/models ಪ್ರತಿ id ಗೆ ಅದನ್ನೇ ವರದಿ ಮಾಡುತ್ತದೆ: ಪ್ರತಿ ಮಾಡೆಲ್‌ನಲ್ಲಿ capabilities.json_schema, ಮತ್ತು ಹೋಸ್ಟ್ ಮಾಡಿದ ಓಪನ್-ವೇಟ್ ಮಾಡೆಲ್‌ಗಳಲ್ಲಿ capabilities.response_format. ಮಾಡೆಲ್‌ಗಳು ಮತ್ತು ಬೆಲೆ

ಬೆಂಬಲಿತ schema ಕೀವರ್ಡ್‌ಗಳು

ಮಾಡೆಲ್ ನಿಮ್ಮ schema ದಿಂದ ಏನನ್ನು ಪಡೆಯುತ್ತದೆ ಎಂಬುದು ಮಾಡೆಲ್ ಮತ್ತು ಎಂಡ್‌ಪಾಯಿಂಟ್ ಮೇಲೆ ಅವಲಂಬಿತ:

ಮಾಡೆಲ್‌ಗಳು /v1/chat/completions /v1/responses
Shannon ಮಾಡೆಲ್‌ಗಳು ಕೆಳಗಿನ ಕೀವರ್ಡ್ ಉಪಗಣ, strict ಆಗಿ ಅನ್ವಯಿಸಲಾಗುತ್ತದೆ. ನೀವು ಕಳುಹಿಸಿದಂತೆಯೇ schema, strict ಆಗಿ ಅನ್ವಯಿಸಲಾಗುತ್ತದೆ.
ಹೋಸ್ಟ್ ಮಾಡಿದ ಓಪನ್-ವೇಟ್ ಮಾಡೆಲ್‌ಗಳು ನೀವು ಕಳುಹಿಸಿದಂತೆಯೇ 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 json_schema ಕೀ ಅಡಿಯಲ್ಲಿ ಅಲ್ಲ, name ಮತ್ತು strict ಪಕ್ಕದಲ್ಲಿ ನೇರವಾಗಿ format ನಲ್ಲಿ ಇರುತ್ತದೆ. JSON ಆಬ್ಜೆಕ್ಟ್ ಮೋಡ್‌ಗಾಗಿ {"format": {"type": "json_object"}} ಕಳುಹಿಸಿ.

ವಿನಂತಿ ಬಾಡಿ
{
  "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 ಐಟಂನ 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 ಆಗಿ ಟೂಲ್

Messages ಫಾರ್ಮ್ಯಾಟ್‌ಗೆ ರಚನಾತ್ಮಕ-ಔಟ್‌ಪುಟ್ ಫೀಲ್ಡ್ ಇಲ್ಲ. ಅದೇ ಮಾಡೆಲ್‌ಗಳಿಂದ JSON ಪಡೆಯಲು, ಅದೇ ಕೀಯೊಂದಿಗೆ /v1/chat/completions ಅಥವಾ /v1/responses ಅನ್ನು ಕರೆಯಿರಿ.

/v1/messages ನಲ್ಲಿಯೇ ಇರಲು, ಆಬ್ಜೆಕ್ಟ್ ಅನ್ನು ಟೂಲ್ ಆಗಿ ವಿವರಿಸಿ: ನಿಮ್ಮ schema ಅನ್ನು input_schema ನಲ್ಲಿ ಇಟ್ಟು tool_choice ನಲ್ಲಿ ಟೂಲ್ ಅನ್ನು ಹೆಸರಿಸಿ. ಆಗ tool_use ಬ್ಲಾಕ್‌ನ input ನಿಮ್ಮ ಆಬ್ಜೆಕ್ಟ್, ಈಗಾಗಲೇ ಪಾರ್ಸ್ ಆಗಿರುತ್ತದೆ. ಹೆಸರಿಸಿದ tool_choice ಅನ್ನು ಹೋಸ್ಟ್ ಮಾಡಿದ ಓಪನ್-ವೇಟ್ ಮಾಡೆಲ್‌ಗಳು ಅನ್ವಯಿಸುತ್ತವೆ.

ವಿನಂತಿ ಬಾಡಿ
{
  "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"}
    }
  ]
}

ಬ್ಲಾಕ್ ಓದುವ ಮೊದಲು stop_reason tool_use ಎಂದು ಪರಿಶೀಲಿಸಿ. ಫಂಕ್ಷನ್ ಕಾಲಿಂಗ್

JSON ಹೇಗೆ ಬರುತ್ತದೆ

  • JSON ಒಂದು string. ಉತ್ತರದಲ್ಲಿ ಅದರ ಪಕ್ಕದಲ್ಲಿ ಪಾರ್ಸ್ ಮಾಡಿದ ಆಬ್ಜೆಕ್ಟ್ ಇಲ್ಲ: message.content ಮೇಲೆ ನಿಮ್ಮ JSON ಪಾರ್ಸರ್ ಅನ್ನು ಚಲಾಯಿಸಿ.
  • stream: true ಜೊತೆ JSON delta.content ತುಣುಕುಗಳಲ್ಲಿ ಬರುತ್ತದೆ. ಅವನ್ನು ಜೋಡಿಸಿ ಮತ್ತು stream ಮುಗಿದ ನಂತರ ಒಮ್ಮೆ ಪಾರ್ಸ್ ಮಾಡಿ; ಒಂದು ತುಣುಕು ತಾನಾಗಿ ಮಾನ್ಯ JSON ಅಲ್ಲ.
  • ಹೋಸ್ಟ್ ಮಾಡಿದ ಓಪನ್-ವೇಟ್ ಮಾಡೆಲ್ response_format ವಿನಂತಿಗೆ ರೀಸನಿಂಗ್ ಪಠ್ಯವಿಲ್ಲದೆ ಉತ್ತರಿಸುತ್ತದೆ: reasoning_content null.

ನೀವು ಪಡೆದದ್ದನ್ನು ಪರಿಶೀಲಿಸಿ

schema ಮಾಡೆಲ್ ಹೇಗೆ ಬರೆಯುತ್ತದೆ ಎಂಬುದಕ್ಕೆ ಮಾರ್ಗದರ್ಶನ ನೀಡುತ್ತದೆ. API ಮುಗಿದ ಉತ್ತರವನ್ನು ನಿಮ್ಮ schema ಜೊತೆ ಹೋಲಿಸುವುದಿಲ್ಲ, ಆದ್ದರಿಂದ ಅಂತಿಮ ಪರಿಶೀಲನೆಯನ್ನು ನಿಮ್ಮ ಕೋಡ್ ಮಾಡುತ್ತದೆ:

  • ಮೇಲ್ಭಾಗದ ಮಾದರಿ ಮಾಡುವಂತೆ ದೋಷ ಹ್ಯಾಂಡ್ಲರ್ ಒಳಗೆ ಪಾರ್ಸ್ ಮಾಡಿ.
  • ಪಾರ್ಸ್ ಮಾಡಿದ ಆಬ್ಜೆಕ್ಟ್ ಅನ್ನು ನಿಮ್ಮ ಸ್ವಂತ ಕೋಡ್‌ನಲ್ಲಿ ಅದೇ schema ಯೊಂದಿಗೆ ಮೌಲ್ಯೀಕರಿಸಿ, ಉದಾಹರಣೆಗೆ JSON Schema ಲೈಬ್ರರಿ, Pydantic ಅಥವಾ Zod ನೊಂದಿಗೆ.
  • ಉದ್ದದ ಉತ್ತರ JSON ಪೂರ್ಣಗೊಳ್ಳುವ ಮೊದಲೇ ಕೊನೆಗೊಳ್ಳಬಹುದು. stream ಮಾಡದ ಉತ್ತರ 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 ಕಳುಹಿಸಿದ್ದೀರಿ.
422 invalid_request_error Failed to deserialize the JSON body into the target type: … response_format ಗೆ type ಇಲ್ಲ, ಅಥವಾ ಅದು JSON ಆಬ್ಜೆಕ್ಟ್ ಅಲ್ಲ.

ಎರಡೂ 400 ಉತ್ತರಗಳನ್ನು ನಿಮ್ಮ ಬ್ಯಾಲೆನ್ಸ್‌ನಿಂದ ಏನನ್ನಾದರೂ ಕಡಿತಗೊಳಿಸುವ ಮೊದಲೇ ಕಳುಹಿಸಲಾಗುತ್ತದೆ. ದೋಷ ನಿರ್ವಹಣೆ