概念

输入类型

输入是有类型的,可以是文字、图片、文档、录音、短片或一组段落。每个输入都可以作为值或 URL 提供。

7 typescontent · url
Using Python?

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

形状

{ type, content?, url?, mime? }
{"type": ..., "content": ..., "url": ..., "mime": ...}
类型类型类型携带内容
文字文字文字文字字符串, 内容
图像图像图像图像一张图片:url,或内容中的 base64
视频视频一段短片:url,或内容中的 base64
音频一段录音:url,或内容中的 base64
语音音频是要转录而不是描述的音频
单行排行或比较的文字,而不是作为文字
filea 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 时,类型由服务器获取的内容推断得出。使用 content 中的 base64 时——无论是你自己的字节,还是刚刚读取的文件——都没有可供推断的依据,需要自行设置 mime。

顺序是意思

输入按您给它们提供的顺序读取。在材料之前先回答问题,如果您想要阅读时要记住这个问题,然后是您想要一个未提前的描述。

段落不仅仅是更多的文字

几个 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]},
])