# الفترة

Canonical URL: https://developers.iagenify.com/ar/sdk/ref/models/schema/
Language: ar

`api.models.create({ schema })`

منح الدورة JSON Shema و هو يجيب على الأشياء بدلا من النثر. هذا ما يحول النموذج إلى شيء يمكن لباقي شفرتك أن تتصل به.

Status: set at creation · changes the default output · JSON Schema

بدون مخطط تحصل على النص، ومن يستهلك عليه أن يقرأ الإنجليزية. مع واحد، تحصل على قيمة -- والفرق ليس من السهل، هو ما إذا كان يمكن كتابة الدالة التالية على الإطلاق.

## 1 {#setting}

```javascript
const extractor = await api.models.create({
  model: "gemini-3.5-flash",
  settings: { temperature: 0 },
  schema: {
    type: "object",
    properties: {
      supplier: { type: "string" },
      total:    { type: "number", description: "Amount including tax" },
      currency: { type: "string", description: "ISO 4217, e.g. EUR" },
      dueDate:  { type: "string", description: "ISO 8601 date" },
      lines: {
        type: "array",
        items: {
          type: "object",
          properties: { label: { type: "string" }, amount: { type: "number" } },
          required: ["label", "amount"],
        },
      },
    },
    required: ["supplier", "total", "currency"],
  },
});

const { outputs } = await extractor.generate({
  inputs: [{ type: "text", content: "Extract this invoice." },
           { type: "file", url: "https://example.com/invoice.pdf" }],
});

outputs[0].content;   // an object, not a string
```

## يغير ما ستجيب عليه الجلسة بالافتراض {#default}

جلسة مع بيان موجز للأجوبة JSON إلا إذا طلب نداء شيئا آخر؛ جلسة بدون نص واحد يجيب. يمكنك تجاوز المكالمة.

```javascript
await extractor.generate({ inputs });                          // JSON — the schema
await extractor.generate({ inputs, outputs: [{ type: "text" }] }); // prose, this once
```

## الوصفات ليست وثائق {#descriptions}

وهي تُقرأ بالنموذج، وهي حيث يتم تسوية الغموض. `total` :: تدعو إلى فرض ضريبة؛ `total` [النفقات غير المدفوعة لا تشمل الضريبة.

| الحقل | بدون وصف | مع واحد مع واحد |
| --- | --- | --- |
| (المجموع | قد يختلف كل نداء قبل أو بعد الضريبة. | ’’ المبلغ بما في ذلك الضريبة ’’ - تمت تسويته. |
| ألف - | أي شكل يحبه النموذج | « ISO ( متى ٢٤ : ٢٨ ) — يمكن ان يُحلَّق . |
| الوضع | نص حر، غير مُحَرّر. | ا_عْطِى المُعَيَّنَةَ. |

```javascript
{
  status: { type: "string", enum: ["paid", "pending", "overdue"] },
  confidence: { type: "number", description: "0 to 1. Below 0.5 means the document was unclear." }
}
```

> **اسأل عن عدم اليقين، لا تُخَمَّده**
>
> نموذج يملأ كل حقل من المجالات التي تعطى له، رقم ثقة، أو حقل قابل للإلغاء مع "البطل عندما لا تقول الوثيقة، هو كيف يمكنك أن تقول قراءة من تخمين - ويكلف بضعة علامات.

## معاينة عليه على سبيل {#validate}

الشكل مطلوب بقوة ، ويجب ان تفحصه قبل ان تعمل عليه ، بنفس الطريقة التي تتحقق بها من رد اي خدمة لا تتحكم فيها .

```javascript
const invoice = outputs[0].content;

if (typeof invoice?.total !== "number" || !invoice.currency) {
  throw new Error("the extraction did not come back in the expected shape");
}
```

## A شكل لـ نداء واحد فقط {#per-call}

لا داعي لأن تفتحوا جلسة لتتكوَّنوا على شكلها ، فاسألوا عنها عند الاتصال بها ، مفيدة عندما يريد كل سؤال سؤالا مختلفا .

```javascript
await assistant.generate({
  inputs: [{ type: "text", content: "Three risks of shipping on a Friday." }],
  outputs: [{ type: "json", schema: {
    type: "object",
    properties: { risks: { type: "array", items: { type: "string" } } },
    required: ["risks"],
  } }],
});
```

## حافظ عليه حجم الجواب {#size}

تم إرسال المخطط مع كل نداء، لذا فإن الكبير هو تكلفة دائمة لكل إجابة. اسأل عن الحقول التي ستستخدمها؛ مخطط مع ثلاثين حقل اختياري لم تقرأها أبداً يدفع ثمنها ثلاثين مرة أكثر.

- [أنواع المخرجات](/ar/sdk/concepts/outputs): كل شيء يمكن أن يُردّ عليه النداء، وكيف يتم كتابة ثنائي.
- [generate()](/ar/sdk/ref/assistant-session/generate): يسأل، وما يعود.

```python
extractor = api.models.create(
    model="gemini-3.5-flash",
    settings={"temperature": 0},
    schema={
        "type": "object",
        "properties": {
            "supplier": {"type": "string"},
            "total": {"type": "number", "description": "Amount including tax"},
            "currency": {"type": "string", "description": "ISO 4217, e.g. EUR"},
            "dueDate": {"type": "string", "description": "ISO 8601 date"},
            "lines": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {"label": {"type": "string"}, "amount": {"type": "number"}},
                    "required": ["label", "amount"],
                },
            },
        },
        "required": ["supplier", "total", "currency"],
    },
)

outputs = extractor.generate(inputs=[
    {"type": "text", "content": "Extract this invoice."},
    {"type": "file", "url": "https://example.com/invoice.pdf"},
])["outputs"]

outputs[0]["content"]   # an object, not a string
```

```python
extractor.generate(inputs=inputs)                              # JSON — the schema
extractor.generate(inputs=inputs, outputs=[{"type": "text"}])  # prose, this once
```

```python
{
    "status": {"type": "string", "enum": ["paid", "pending", "overdue"]},
    "confidence": {"type": "number", "description": "0 to 1. Below 0.5 means the document was unclear."},
}
```

```python
invoice = outputs[0]["content"]

if not isinstance(invoice, dict) or not isinstance(invoice.get("total"), (int, float)) or not invoice.get("currency"):
    raise ValueError("the extraction did not come back in the expected shape")
```

```python
assistant.generate(
    inputs=[{"type": "text", "content": "Three risks of shipping on a Friday."}],
    outputs=[{"type": "json", "schema": {
        "type": "object",
        "properties": {"risks": {"type": "array", "items": {"type": "string"}}},
        "required": ["risks"],
    }}],
)
```
