[BUG] Native OpenAI async streaming does not send response_model as response_format

未关闭 适合新手
#9,785 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@basil-k-aji-dev 已经在做这个了。

开始于 2026年11月25日。

  • #9794 来自 @basil-k-aji-dev —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
84/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
ai, backend

调研方向

阅读 lib/crewai/src/crewai/llms/providers/openai/completion.py,并比较 _ahandle_streaming_completion 与 _handle_streaming_completion。找到测试 test_openai_streaming_with_response_model,检查它如何覆盖异步路径。完成的标准是异步流式请求将 response_model 的架构作为 response_format 包含在内,并且有测试验证请求参数。

由索引模型根据 Issue 内容生成。

描述

Description

OpenAICompletion._ahandle_streaming_completion ignores the per-call response_model when it builds the request. In llms/providers/openai/completion.py the if response_model: branch calls self._get_async_client().chat.completions.create(**params), and params come from _prepare_completion_params, which only sets response_format from self.response_format. The sync twin (_handle_streaming_completion) uses beta.chat.completions.stream(..., response_format=response_model). So await llm.acall(..., response_model=M) with streaming sends an unconstrained request and usually gets prose back instead of an instance of M.

Steps to Reproduce
  1. Create LLM(model="openai/gpt-4o", stream=True) with the native OpenAI provider.
  2. Mock or inspect llm._async_client.chat.completions.create and call await llm.acall(messages, response_model=SomeModel).
  3. The kwargs passed to create contain no response_format.
Expected behavior

The structured-output schema of response_model is sent, as on the sync path.

Screenshots/Code snippets

Related, on the LiteLLM path (llm.py): #9283 and PR #9284. This issue is the native OpenAI async path only.

Evidence

Code reading of lib/crewai/src/crewai/llms/providers/openai/completion.py at 97f2424 (async streaming handler vs the sync one). I can send a fix with a test next to test_openai_streaming_with_response_model.

Operating System

Linux (Debian-based)

Python Version

3.12

crewAI Version

1.15.45 (origin/main at 97f2424)

crewAI Tools Version

Not relevant

Virtual Environment

uv

主要语言
Python
星标
61.2k
派生
9.2k
平均合并
1 天 14 小时
30 天内合并 PR
180

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

crewAIInc/crewAI 的其他 Issue

查看 crewAIInc/crewAI 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。