Repository navigation
zh dev star guides ai models
github-actions[bot] edited this page Nov 15, 2026
·
1 revision
直接调用模型生成回复或进行结构化判断。需要执行工具或沿用会话历史时,参见 Agent。
umo = event.unified_msg_origin
provider_id = await self.context.get_current_chat_provider_id(umo=umo)llm_resp = await self.context.llm_generate(
chat_provider_id=provider_id, # 聊天模型 ID
prompt="Hello, world!",
)
# print(llm_resp.completion_text) # 获取返回的文本判断提供商用于是否回复、选择执行分支等任务。先在 WebUI 模型提供商 → 判断 中配置提供商,再通过 self.context.decision 调用。
should_reply = await self.context.decision.yes_no(
question="Should the assistant reply to this message?",
state="I cannot log in; every request returns 500.",
threshold=0.7,
)
strategy = await self.context.decision.choose(
question="Which reply strategy should be used?",
criteria={"short": "A brief reply", "detailed": "A detailed reply"},
state="The user asks for step-by-step troubleshooting.",
)
print(strategy.choice)yes_no() 返回 bool,当肯定概率达到 threshold 时为 True;choose() 返回 DecisionChoiceAnswer,通过 .choice 读取选项值。
state 提供判断所需的上下文,支持文本、列表或字典。默认使用当前判断提供商,也可传入 provider_id 指定。
需要一次回答多个问题时,调用 ask({问题名: 问题对象}, state=...),结果按问题名返回。以下类型从 astrbot.api.provider 导入:
| 问题类型 | 配置 | 返回类型及主要字段 |
|---|---|---|
DecisionBooleanQuestion |
instructions:待判断的陈述。 |
DecisionBooleanAnswer.probability:陈述为真的概率。 |
DecisionChoiceQuestion |
instructions 和 criteria:选项 ID 到描述的映射。 |
DecisionChoiceAnswer.choice:选中的选项 ID。 |
DecisionScoreQuestion |
instructions 和 criteria:由低到高的 2~10 个等级描述。 |
DecisionScoreAnswer.score:从 0 到等级数减 1 的评分,可为小数。 |
提供商不可用、请求失败或返回结果无效时抛出 DecisionError。yes_no() 可通过 default=False 在这类错误发生时返回默认值。
- 首页
- 文档入口
- Top Level
- community events
- config
- deploy
- dev
- others
- platform
- 接入 OneBot v11 协议实现
- 接入钉钉 DingTalk
- 接入 Discord
- 接入 Kook
- 接入飞书
- 接入 LINE
- 接入 Matrix
- 接入 Mattermost
- 接入 Misskey 平台
- 接入 QQ 官方机器人平台
- 通过 QQ官方机器人 接入 QQ (Webhook)
- 通过 QQ官方机器人 接入 QQ (Websockets)
- 接入 Satori 协议
- 接入 server-satori (基于 Koishi)
- 接入 Slack
- 接入消息平台
- 接入 Telegram
- 接入 VoceChat
- AstrBot 接入企业微信
- 接入企业微信智能机器人平台
- AstrBot 接入微信公众平台
- 接入个人微信
- providers
- use
- Home
- Docs Entry
- Top Level
- config
- deploy
- Deploy AstrBot on 1Panel
- Deploy AstrBot on BT Panel
- Deploy AstrBot on CasaOS
- Deploy AstrBot from Source Code
- Community-Provided Deployment Methods
- Deploy via Compshare
- Deploy with AstrBot Desktop Client
- Deploy AstrBot with Docker
- Deploy AstrBot with Kubernetes
- Deploy AstrBot with AstrBot Launcher
- Other Deployments
- Script Deployment
- Installation via System Package Manager
- Preface
- dev
- AstrBot Configuration File
- API Scope–Endpoint Reference
- AstrBot HTTP API
- AstrBot Plugin Market JSON Specification
- AstrBot Plugin Market JSON Specification
- Developing a Platform Adapter
- plugin
- AI
- Agents
- Sessions and Conversations
- Models
- Other APIs
- Tools
- Documentation moved
- Text to Image
- Handling Message Events
- Plugin Configuration
- Plugin Internationalization
- Documentation moved
- Shared Bridge API
- Interactive message component
- Standalone plugin page
- Backend Web APIs
- Workbench page
- Sending Messages
- Session Control
- Minimal Example
- Plugin Storage
- AstrBot Plugin Development Guide 🌠
- Publishing Plugins to the Plugin Marketplace
- ospp
- others
- platform
- Connect OneBot v11 Protocol Implementations
- Connect to DingTalk
- Connecting to Discord
- Connect to KOOK
- Connecting to Lark
- Connecting to LINE
- Connecting to Matrix
- Connecting to Mattermost
- Connecting to Misskey Platform
- Connect QQ Official Bot
- Connect QQ via QQ Official Bot (Webhook)
- Connect QQ via QQ Official Bot (Websockets)
- Connect to Satori Protocol
- Connect server-satori (Koishi)
- Connecting to Slack
- Messaging Platforms
- Connecting to Telegram
- Connect to VoceChat
- Connect AstrBot to WeCom
- Connect to WeCom AI Bot Platform
- Connect AstrBot to WeChat Official Account Platform
- Connect Personal WeChat
- providers
- Connect 302.AI
- Agent Runners
- Built-in Agent Runner
- Connect to Coze
- Connect to Alibaba Cloud Bailian Application
- Connect to DeerFlow
- Connect to Dify
- Connect AIHubMix
- coze
- dashscope
- DeepSeek STT Integration
- DeepSeek TTS Integration
- dify
- Model input images
- Large Language Model Providers
- Connect MiraRouter
- NewAPI
- Connect PPIO Cloud
- Connect LM Studio to Use DeepSeek-R1 and Other Models
- Integrating Ollama
- Connect ShengSuanYun
- Connecting to SiliconFlow
- Connecting Model Services
- Connecting to TokenPony
- use
- Agent Execution Mode {#agent-runner}
- Agent Sandbox Environment
- astrbot sandbox
- AstrBot CLI {#cli-commands}
- Docker-based Code Interpreter
- Built-in Commands
- computer
- Context Compression
- Session Configuration Mappings (formerly Custom Rules)
- AstrBot Knowledge Base
- MCP
- AstrBot Plugins {#astrbot-star}
- Proactive Capabilities
- Skills {#anthropic-skills}
- Subagents {#agent-handsoff-and-subagent}
- Unified Webhook Mode
- Web Search
- DeepSeek Search API
- SerpApi
- WebUI