Skip to content

Introduce support of Responses API #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

redox
Copy link
Contributor

@redox redox commented Jul 23, 2025

What this does

Some models (incl. o4-mini-deep-research) aren't compatible with the chat/completion API. They will fail with

(...):1:in '<main>': This model is only supported in v1/responses and not in v1/chat/completions. (RubyLLM::Error)

This PR introduces a new Response class, which - similarly to Chat (and inheriting from the same base Conversation class) - allows a user to target the responses endpoint.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Quality check

  • I ran overcommit --install and all hooks pass
  • I tested my changes thoroughly
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

API changes

  • Breaking change
  • New public methods/classes
  • Changed method signatures
  • No API changes

Related issues

I was surprised nothing was there.

Some model (incl. `o4-mini-deep-research`) aren't compatible with the
chat/completion API.

This PR introduces a new `Response` class, which - similarly to `Chat`
(and inheriting from the same base `Conversation` class) - allows a user
to target the `responses` endpoint.
@redox
Copy link
Contributor Author

redox commented Jul 23, 2025

@crmne let me know what you think about the approach, I think this is an important missing part of RubyLLM to actually support all models. If the approach does look good to you, I'll add more tests (incl. streaming ones) and documentation.

@@ -8,162 +8,17 @@ module RubyLLM
# chat = RubyLLM.chat
# chat.ask "What's the best way to learn Ruby?"
# chat.ask "Can you elaborate on that?"
class Chat
include Enumerable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm moving most of the Chat implementation to a base class Conversation so both Chat and Conversation inherit from the logic

@@ -68,7 +68,7 @@
instance_double(Message,
content: '',
tool_calls: {
'tool_123' => instance_double(ToolCall,
'tool_123' => instance_double(RubyLLM::ToolCall,
id: 'tool_123',
name: 'test_tool',
arguments: { 'arg1' => 'value1' })
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think those tests were wrongly relying on the Dummy app ToolCall class VS the RubyLLM one

@@ -143,6 +143,10 @@
end
end

RESPONSE_MODELS = [
{ provider: :openai, model: 'o4-mini-deep-research', params: { tools: [{ type: 'web_search_preview' }] } }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the o4-mini-deep-research requires 1 web_search_preview tool.

@tpaulshippy
Copy link
Contributor

I was working on this other night also. I think what I would prefer is if RubyLLM hid from me which endpoint was necessary for the given model and just handled this automatically. Not sure I love the library consumer having to figure out whether to call chat or response.

Excited to see someone working on this! Definitely needed (see #213).

@redox
Copy link
Contributor Author

redox commented Jul 23, 2025

I was working on this other night also. I think what I would prefer is if RubyLLM hid from me which endpoint was necessary for the given model and just handled this automatically. Not sure I love the library consumer having to figure out whether to call chat or response.

Yes, I wasn't sure as the tools and some parameters are different.

Excited to see someone working on this! Definitely needed (see #213).

Gosh, thanks for sharing; I couldn't find anything searching for Responses in the issues, not sure why I didn't stumble upon this one.

@tpaulshippy
Copy link
Contributor

Wondering if we can just switch to Responses for everything and keep the old code around for compatibility on other providers.

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.

2 participants