参数
inputsarray必填你给的东西,你看 投入类型.
outputsarray想要回来的东西 默认为会话的形状 JSON 其有计划,案文则有。
将一个阵列本身作为输入,作为普通案件简表。
await assistant.generate({ inputs: [{ type: "text", content: "Hello" }] });
await assistant.generate([{ type: "text", content: "Hello" }]); // the sameassistant.generate(inputs=[{"type": "text", "content": "Hello"}])
assistant.generate([{"type": "text", "content": "Hello"}]) # the same返回值
{
ok: true,
outputs: [{ type: "text", content: "…" }],
usage: {
credits: 3, // what you were actually charged
preAuthorized: 5, // what was held before the call; the difference came back
estimated: false, // true when the provider reported no usage and it was estimated
inputTokens: 1840,
outputTokens: 77,
cachedTokens: 1320, // input served from cache, charged at a fraction
thinkingTokens: 54
},
model: "gemini-3.5-flash", // what you asked for
servedModel: "gemini-3.5-flash", // what actually answered
service: "text-to-text",
settings: { }, // on video and image: the definition, length and sound billed
timing: { startTime, endTime, durationMs }
}{
"ok": True,
"outputs": [{"type": "text", "content": "…"}],
"usage": {
"credits": 3, # what you were actually charged
"preAuthorized": 5, # what was held before the call; the difference came back
"estimated": False, # True when the provider reported no usage and it was estimated
"inputTokens": 1840,
"outputTokens": 77,
"cachedTokens": 1320, # input served from cache, charged at a fraction
"thinkingTokens": 54,
},
"model": "gemini-3.5-flash", # what you asked for
"servedModel": "gemini-3.5-flash", # what actually answered
"service": "text-to-text",
"settings": {}, # on video and image: the definition, length and sound billed
"timing": {"startTime": ..., "endTime": ..., "durationMs": ...},
}其中一个是意图,另一个是答案。通常匹配;如果没有,则使用模式解释结果和成本。
阅读成本
usage.credits 真正的收费,在对供应商报告的内容发出呼吁后解决。 preAuthorized 先前所持的;未使用的任何物品都回来了。 estimated: true 表示提供者没有报告任何,数额是得出——值得记录,因为没有衡量数字的情况就是这种情况。
const { usage } = await assistant.generate({ inputs });
await ledger.record({
user: userId,
credits: usage.credits,
estimated: usage.estimated,
cached: usage.cachedTokens ?? 0,
ms: /* from timing */ undefined,
});result = assistant.generate(inputs=inputs)
usage = result["usage"]
ledger.record(
user=user_id,
credits=usage["credits"],
estimated=usage.get("estimated"),
cached=usage.get("cachedTokens", 0),
ms=(result.get("timing") or {}).get("durationMs"),
)没有关于这一呼吁的最后期限
故意。服务器不会停止,因为你停止听——它完成了工作并开账单——所以一分钟后放弃意味着要支付一个你从未见过的答案。视频需要几分钟;文字过一分钟的时间足够多。
- 工作所约束的,是给提供者设定的产出上限,而不是客户方的计时器。
- 自行通过
timeout如果你真的想要的话 了解客户的作为 并且不会停止 - 显示进度而不是让呼叫者等无事等待,使用 转.
之后保留的内容
在有记忆的会话中,两种信息都储存在模型和答案上,既包括你的信息,也包括答案,二进制信息不储存:生成的图像或文件是参照而不是字节保存的。
结果将一首字节交给您。 如果您不保存它们, 对话将记住文件已经生成, 并且无法再给你 。
错误
| 代码 | 状态 | 触发条件 |
|---|---|---|
| inputs_required | 400 | 缺少或空输入 。 |
| discussion_not_found | 404 | 此账户的届会不使用此ID 。 |
| context_too_large | 400 | 比模型的窗户大一点 任何借方之前都拒绝 |
| not_enough_credits | 402 | 被提升为未足够 的批评, 携带什么 需要。 |
| generation_failed | 502 | 供应商拒绝 信息是供应商的 被编辑 |
这正是这里缺少的会话答案所在,之所以保留它是因为融合与融合是相匹配的。 session_not_found.
import { NotEnoughCredits, IaGenifyError } from "iagenify";
try {
const { outputs } = await assistant.generate({ inputs });
return outputs;
} catch (err) {
if (err instanceof NotEnoughCredits) {
return { error: `Needs ${err.required} credits, ${err.available} available.` };
}
if (err instanceof IaGenifyError && err.code === "context_too_large") {
return { error: "This conversation is too long. Start a new one." };
}
if (err instanceof IaGenifyError && err.code === "generation_failed") {
// The provider's own message, cleaned. Useful to you; usually not to your users.
console.error("generation failed:", err.message);
return { error: "That could not be generated." };
}
throw err;
}from iagenify import IaGenifyError, NotEnoughCredits
def ask(assistant, inputs):
try:
return assistant.generate(inputs=inputs)["outputs"]
except NotEnoughCredits as error:
return {"error": f"Needs {error.required} credits, {error.available} available."}
except IaGenifyError as error:
if error.code == "context_too_large":
return {"error": "This conversation is too long. Start a new one."}
if error.code == "generation_failed":
# The provider's own message, cleaned. Useful to you; usually not to your users.
print("generation failed:", error)
return {"error": "That could not be generated."}
raisegeneration_failed 提供商的信息是故意保持的:这是你请求失败的结果——一个无法读取的图像,一个不支持的组合——而细节是您可以修复它。在它到达你之前,已经清理了内部的任何信息。