openai
feishu.agent.adapters.openai
¶
OpenAIBackend
¶
OpenAI Chat Completions API 的 feishu.agent.llm.LlmBackend 实现。
将与厂商无关的 feishu.agent.llm.Message、feishu.agent.llm.ToolSpec 翻译为 Chat Completions
请求格式(系统提示词作为 role="system" 的消息),并把其流式分片归一化为
feishu.agent.llm.StreamChunk。openai SDK 仅在未注入 client 时按需懒加载,核心模块本身不依赖
该 SDK。本适配器仅实现已确认的 Chat Completions 流式协议。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
Any
|
已构造的 |
None
|
|
str
|
模型名称,例如 |
必需 |
|
Any
|
透传给 OpenAI API 的默认参数,例如 |
{}
|
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/agent/adapters/openai.py
| Python | |
|---|---|
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
stream
¶
stream(*, messages: Sequence[Message], tools: Sequence[ToolSpec] = (), system: str | None = None, **kwargs: Any) -> AsyncIterator[StreamChunk]
调用 OpenAI Chat Completions API 流式生成一轮响应。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
Sequence[Message]
|
截至当前轮次的对话历史。 |
必需 |
|
Sequence[ToolSpec]
|
本轮可供模型调用的工具声明。 |
()
|
|
str | None
|
系统提示词,将作为首条 |
None
|
|
Any
|
覆盖默认参数(如 |
{}
|
返回:
| 类型 | 描述 |
|---|---|
AsyncIterator[StreamChunk]
|
逐个产出归一化 feishu.agent.llm.StreamChunk 的异步迭代器。 |
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/agent/adapters/openai.py
create_openai_client
¶
Create an OpenAI-compatible client for an explicitly configured provider endpoint.
源代码位于: feishu/agent/adapters/openai.py
create_openai_backend
¶
create_openai_backend(*, client: Any, model: str, base_url: str | None, thinking_enabled: bool | None = None, thinking_budget: int | None = None, force_non_thinking: bool = False) -> OpenAIBackend
Build a backend with the configured provider’s thinking protocol.
DeepSeek uses the OpenAI-compatible thinking object and requires
reasoning_content replay across tool-result turns. Qwen-compatible
endpoints retain their enable_thinking / thinking_budget contract.