البنية
{ type, content?, url?, mime? }{"type": ..., "content": ..., "url": ..., "mime": ...}| النوع | يحمل |
|---|---|
| text | سلسلة نصية في content |
| image | صورة: url، أو base64 في content |
| video | مقطع فيديو: url، أو base64 في content |
| audio | تسجيل صوتي: url، أو base64 في content |
| speech | صوت يُراد تفريغه لا وصفه |
| passages | مقاطع نصية لترتيبها أو مقارنتها، بدلاً من قراءتها كنص واحد |
| file | a document such as a PDF: url only, never content |
طريقتان لتقديم إدخال واحد
import { readFileSync } from "node:fs";
await assistant.generate({
inputs: [
{ type: "text", content: "What changed between these two?" },
{ type: "image", url: "https://example.com/before.png" }, // fetched for you
{ type: "image", content: base64Png, mime: "image/png" }, // already in hand
// A local file is content too — read it yourself, there is no "path" input:
{ type: "image", content: readFileSync("./after.png").toString("base64"), mime: "image/png" },
],
});import base64
from pathlib import Path
assistant.generate(inputs=[
{"type": "text", "content": "What changed between these two?"},
{"type": "image", "url": "https://example.com/before.png"}, # fetched for you
{"type": "image", "content": base64_png, "mime": "image/png"}, # already in hand
# A local file is content too — read it yourself, there is no "path" input:
{"type": "image", "content": base64.b64encode(Path("after.png").read_bytes()).decode(),
"mime": "image/png"},
])عيّن mime عند تمرير محتوى خام
عند استخدام url يُستنتج النوع مما يجلبه الخادم. أما base64 في content — بايتاتك الخاصة، أو ملف قرأته للتو — فلا يوجد منه ما يُستنتج: عيّن mime بنفسك.
الترتيب له معنى
تُقرأ المدخلات بالترتيب الذي تقدمه. ضع السؤال قبل المادة عندما تريد قراءتها مع أخذ السؤال في الحسبان، وضعه بعدها عندما تريد وصفاً غير موجّه أولاً.
passages ليست مجرد نص أكثر
تشكّل عدة مدخلات text جسماً واحداً للقراءة. أما passages فهي مجموعة عناصر مستقلة تُرتّب أو تُقارن — وهذا ما يحتاجه استدعاء إعادة الترتيب.
await reranker.generate({
inputs: [
{ type: "text", content: "Which of these answers the question best?" },
{ type: "passages", content: [chunkA, chunkB, chunkC] },
],
});reranker.generate(inputs=[
{"type": "text", "content": "Which of these answers the question best?"},
{"type": "passages", "content": [chunk_a, chunk_b, chunk_c]},
])