Skip to content

Feat/support OpenAI response#6864

Draft
zhist2028 wants to merge 10 commits intoAstrBotDevs:masterfrom
zhist2028:feat/support-openai-response
Draft

Feat/support OpenAI response#6864
zhist2028 wants to merge 10 commits intoAstrBotDevs:masterfrom
zhist2028:feat/support-openai-response

Conversation

@zhist2028
Copy link
Copy Markdown

@zhist2028 zhist2028 commented Mar 23, 2026

新增功能

添加了新的适配器 OpenAi Responses ,以支持 openai response模式。

Modifications / 改动点

  1. astrbot/core/provider/sources/openai_responses_source.py
    这是本次功能的主体,新实现了 ProviderOpenAIResponses。它把 AstrBot 的消息、图片、工具调用上下文适配到 OpenAI Responses API,并支持普通响应、流式响应、reasoning 文本、function calling、usage 解析、重试、限流切 key、上下文过长回退、图片失败降级为纯文本等逻辑。

  2. astrbot/core/agent/tool.py
    新增 openai_responses_schema(),把现有工具定义转换成 OpenAI Responses API 需要的工具 schema,保证 AstrBot 的工具调用可以接到 Responses API 上。

  3. astrbot/core/provider/manager.py
    在 provider 分发入口里注册了 openai_responses 类型,让配置里的新 provider 能被正确实例化和使用。

  4. astrbot/core/config/default.py
    增加了 OpenAI Responses 的默认 provider 模板,方便在配置和面板中直接选择并填写 api_base、key、timeout、proxy、custom_headers 等参数。

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

  1. openai responses配置和运行结果
image image image

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Add support for OpenAI Responses API as a new provider.

New Features:

  • Introduce an OpenAI Responses provider adapter that supports text, streaming, tools, images, and error handling via the OpenAI Responses API.
  • Expose an OpenAI Responses-specific tool schema for converting internal tools into the Responses API format.

Enhancements:

  • Register the OpenAI Responses provider in the provider manager and add its default configuration entry.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the system's capabilities by integrating the OpenAI Responses API, offering a new way to process and generate responses from OpenAI models. It also introduces a global streaming output configuration, allowing various parts of the application, such as webchat title generation and cron tasks, to leverage real-time data streams for improved performance and user experience.

Highlights

  • OpenAI Responses API Support: A new adapter, OpenAI(Responses), has been implemented to integrate with the OpenAI Responses API, providing an alternative mode for interacting with OpenAI models.
  • Streaming Output Configuration: A new configuration for streaming output has been introduced, which will apply to future tasks and the generation of webchat titles, enhancing responsiveness.
  • Tool Schema Conversion: A dedicated function has been added to convert existing tools into the specific schema format required by the OpenAI Responses API.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new OpenAI Responses API provider, including a new tool schema conversion method, a new provider configuration, and a new provider source file. It also updates the main agent to support streaming responses for title generation and adjusts cron manager configuration. The review comments highlight several areas for improvement: a potential bug in _collect_streamed_response where streamed title generation might return incomplete text; significant code duplication in text_chat and text_chat_stream's retry logic within the new OpenAI Responses provider; code duplication between openai_responses_schema and openai_schema in tool.py; an unnecessary try...except block in _handle_webchat; code duplication in request parameter preparation within _query and _query_stream; and a side effect in _remove_image_from_context that modifies input parameters directly.

避免因为取lastchunk导致webchattitle生成不全

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@zhist2028
Copy link
Copy Markdown
Author

zhist2028 commented Mar 27, 2026

我计划放弃支持并回退掉“流式输出对webchat 标题生成和定时任务生效”。即放弃支持“仅支持流式输出的服务商”的情况。

@zhist2028
Copy link
Copy Markdown
Author

已完成代码重构。当前的最终结果如下:

  1. astrbot/core/provider/sources/openai_responses_source.py
    这是本次功能的主体,新实现了 ProviderOpenAIResponses。它把 AstrBot 的消息、图片、工具调用上下文适配到 OpenAI Responses API,并支持普通响应、流式响应、reasoning 文本、function calling、usage 解析、重试、限流切 key、上下文过长回退、图片失败降级为纯文本等逻辑。

  2. astrbot/core/agent/tool.py
    新增 openai_responses_schema(),把现有工具定义转换成 OpenAI Responses API 需要的工具 schema,保证 AstrBot 的工具调用可以接到 Responses API 上。

  3. astrbot/core/provider/manager.py
    在 provider 分发入口里注册了 openai_responses 类型,让配置里的新 provider 能被正确实例化和使用。

  4. astrbot/core/config/default.py
    增加了 OpenAI Responses 的默认 provider 模板,方便在配置和面板中直接选择并填写 api_base、key、timeout、proxy、custom_headers 等参数。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant