المفاهيم

أنواع الإخراج

النتيجة قائمة من المخرجات. وطلب بنية محددة هو ما يحول النص إلى شيء يمكنك التعامل معه من دون تحليل الإنجليزية.

outputs[]schema
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

ما الذي يعود

{
  outputs: [{ type, content, mime?, description? }],
  usage:   { credits, inputTokens, outputTokens },
  model:   "gemini-3.5-flash",
  service: "text-to-text"
}
{
    "outputs": [{"type": ..., "content": ..., "mime": ..., "description": ...}],
    "usage": {"credits": ..., "inputTokens": ..., "outputTokens": ...},
    "model": "gemini-3.5-flash",
    "service": "text-to-text",
}
النوعما يحمله content
textسلسلة نصية
jsonسلسلة JSON — حلّلها
image · audio · videobase64 مع تعيين mime
embeddingمصفوفة أرقام

طلب بنية محددة

هناك طريقتان، ولكل منهما وظيفة مختلفة. يحدد schema في الجلسة شكل كل إجابة تقدمها. أما outputs في استدعاء واحد فيحدد شكل ذلك الاستدعاء.

// Every answer from this session has this shape
const extractor = await api.models.create({
  model: "gemini-3.5-flash",
  memory: false,
  schema: {
    type: "object",
    properties: { company: { type: "string" }, amount: { type: "number" } },
    required: ["company", "amount"],
  },
});

const { outputs } = await extractor.generate({ inputs });
const invoice = JSON.parse(outputs[0].content);
import json

# Every answer from this session has this shape
extractor = api.models.create(
    model="gemini-3.5-flash",
    memory=False,
    schema={
        "type": "object",
        "properties": {"company": {"type": "string"}, "amount": {"type": "number"}},
        "required": ["company", "amount"],
    },
)

outputs = extractor.generate(inputs=inputs)["outputs"]
invoice = json.loads(outputs[0]["content"])
// Just this call, and more than one thing at a time
await assistant.generate({
  inputs: [{ type: "text", content: "Describe the product, then illustrate it." }],
  outputs: [
    { type: "text",  description: "One paragraph of copy" },
    { type: "image", description: "A square product shot on a plain background" },
  ],
});
# Just this call, and more than one thing at a time
assistant.generate(
    inputs=[{"type": "text", "content": "Describe the product, then illustrate it."}],
    outputs=[
        {"type": "text", "description": "One paragraph of copy"},
        {"type": "image", "description": "A square product shot on a plain background"},
    ],
)

كتابة البيانات الثنائية

const [picture] = result.outputs.filter((o) => o.type === "image");

await fs.writeFile("product.png", Buffer.from(picture.content, "base64"));

// or keep it on a storage, through the SDK
const file = api.files.create({
  name: "product.png",
  content: picture.content,
  mimeType: picture.mime,
});
await file.save({ path: "./product.png" });
import base64
from pathlib import Path

picture = next(o for o in result["outputs"] if o["type"] == "image")

Path("product.png").write_bytes(base64.b64decode(picture["content"]))

# or keep it on a storage, through the SDK
file = api.files.create(
    name="product.png",
    content=base64.b64decode(picture["content"]),
    mime_type=picture.get("mime"),
)
file.save(path="./product.png")
تعامل مع content باعتباره base64 لا نصاً

تمرير محتوى ثنائي عبر أي شيء يفترض UTF-8 يفسده. فك ترميزه إلى بايتات في أقرب فرصة.