词元广场TOKPUB.COM - 欢迎您,支持一个 Key 调用近 600+ 海内外模型,限时特价模型低至 1 折,欢迎上岸!
ctx.llm 是 plugin 发起 LLM 调用的官方方式。purpose 是一个自由格式的审计字符串——它会出现在 agent.log 和 result.audit 中,方便运营人员查看哪个 plugin 发起了哪次调用。可选,但对于频繁触发的场景建议填写。jsonschema 则对你的 schema 进行验证,最终在 result.parsed 上返回一个 Python 对象。如果模型无法生成有效 JSON,result.parsed 为 None,result.text 携带原始响应。complete() 用于对话,complete_structured() 用于有类型的 JSON,acomplete() 和 acomplete_structured() 用于 asyncio。参数相同,结果对象相同。result.audit 将调用归因回溯。config.yaml 中按 plugin 逐一选择开启特定覆盖。register(ctx) 函数中实现,无需任何外部配置即可针对用户当前激活的模型运行。/tldrresult.text 是模型的响应;result.usage 携带 token 计数;result.provider 和 result.model 携带归因信息。/paste-to-taskshermes-example-pluginsacomplete() / acomplete_structured() 与 asyncio.gather() 配合使用),请参见同一仓库中的plugin-llm-async-example。| 你需要…… | 使用 |
|---|---|
| 自由格式文本响应(翻译、摘要、改写、生成) | complete() |
| 多轮 prompt(system + few-shot 示例 + user) | complete() |
| 经 schema 验证的有类型 dict | complete_structured() |
| 图像或文本输入并返回有类型 dict | complete_structured() |
| 在异步代码中发起相同调用(gateway 适配器、异步 hook) | acomplete() / acomplete_structured() |
ctx.llm 是 agent.plugin_llm.PluginLlm 的实例。complete()messages 采用标准 OpenAI 格式——{"role": "...", "content": "..."} 字典列表。多轮 prompt(system + few-shot user/assistant 对 + 最终 user)的用法与 OpenAI SDK 完全一致。provider= 和 model= 相互独立,格式与宿主主配置(model.provider + model.model)相同。仅设置 model= 可在用户当前激活的 provider 上使用不同模型。同时设置两者则完全切换 provider。任一参数在未获运营人员授权时均会抛出 PluginLlmTrustError。complete_structured()data: URL)。当提供 json_schema 或设置 json_mode=True 时,宿主通过 response_format 向 provider 请求 JSON 输出,在本地作为兜底进行解析,若安装了 jsonschema 则对你的 schema 进行验证。result.content_type == "json" — result.parsed 是符合你 schema 的 Python 对象。result.content_type == "text" — 解析或验证失败;检查 result.text 获取原始模型响应。usage 携带 input_tokens、output_tokens、total_tokens、cache_read_tokens、cache_write_tokens 和 cost_usd。plugins.entries 配置块的情况下,plugin 可以:temperature、max_tokens、timeout、system_prompt、purpose、messages、instructions、input、json_schema),provider=、model=、agent_id= 和 profile= 参数在运营人员授权前均会抛出 PluginLlmTrustError。ctx.llm.complete(messages=...) 且不带任何覆盖的 plugin,会针对用户当前激活的内容运行,零配置即可工作。以下配置块仅在 plugin 明确需要固定到与用户不同的模型或 provider 时才有意义。name: 字段,对于嵌套 plugin 是路径派生的键(image_gen/openai、memory/honcho 等)。