ruby_llm-responses_api 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/ruby_llm/providers/openai_responses/chat.rb +47 -19
- data/lib/ruby_llm/providers/openai_responses.rb +4 -1
- data/lib/rubyllm_responses_api.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '059b94ffc46c9a9505bec39f3c7e11dd55406304b159c9b3e95d37202a085c31'
|
|
4
|
+
data.tar.gz: 9371bcaa6539cd987d7688a3901ae855f090576f07f7e00ba0d8613157224e19
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1cfbb8c9fe68c29e7d32a07cd6f039dedb62eba362d9238ad877e5b10801b313ee8b821971d863dcf18d5d5affd1378e53c1bcbf77887811b41ef2daba834cc4
|
|
7
|
+
data.tar.gz: 62b356bac7017a796033d7ffd8a7e2ca35650898bbf56a59c18fc6530f00787f57b944932b67a5a5dcedc71922b9056f05057118f50ca6aceeea143eb740b9af
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.5.1] - 2026-03-03
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `tool_choice` support (`auto`, `required`, `none`, or specific function name)
|
|
13
|
+
- `parallel_tool_calls` support (`:many` / `:one`) via RubyLLM's `tool_prefs`
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- Compatibility with RubyLLM v1.13.0 (`tool_prefs:` parameter in `complete` and `render_payload`)
|
|
18
|
+
- Handle new pre-normalized schema format from `Chat.with_schema`
|
|
19
|
+
|
|
8
20
|
## [0.5.0] - 2026-02-25
|
|
9
21
|
|
|
10
22
|
### Added
|
|
@@ -12,10 +12,11 @@ module RubyLLM
|
|
|
12
12
|
|
|
13
13
|
module_function
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
# rubocop:disable Metrics/ParameterLists
|
|
16
|
+
def render_payload(messages, tools:, temperature:, model:, stream: false,
|
|
17
|
+
schema: nil, thinking: nil, tool_prefs: nil) # rubocop:disable Lint/UnusedMethodArgument
|
|
18
|
+
tool_prefs ||= {}
|
|
19
|
+
system_messages, non_system_messages = messages.partition { |m| m.role == :system }
|
|
19
20
|
|
|
20
21
|
instructions = system_messages.map { |m| extract_text_content(m.content) }.join("\n\n")
|
|
21
22
|
|
|
@@ -27,27 +28,54 @@ module RubyLLM
|
|
|
27
28
|
|
|
28
29
|
payload[:instructions] = instructions unless instructions.empty?
|
|
29
30
|
payload[:temperature] = temperature unless temperature.nil?
|
|
31
|
+
apply_tools(payload, tools, tool_prefs)
|
|
32
|
+
payload[:text] = build_schema_format(schema) if schema
|
|
30
33
|
|
|
31
|
-
payload[:tools] = tools.map { |_, tool| tool_for(tool) } if tools.any?
|
|
32
|
-
|
|
33
|
-
if schema
|
|
34
|
-
payload[:text] = {
|
|
35
|
-
format: {
|
|
36
|
-
type: 'json_schema',
|
|
37
|
-
name: 'response',
|
|
38
|
-
schema: schema,
|
|
39
|
-
strict: schema[:strict] != false
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Auto-chain conversations: find the last response_id from assistant messages
|
|
45
|
-
# This enables automatic stateful conversations without manual tracking
|
|
46
34
|
last_response_id = extract_last_response_id(messages)
|
|
47
35
|
payload[:previous_response_id] = last_response_id if last_response_id
|
|
48
36
|
|
|
49
37
|
payload
|
|
50
38
|
end
|
|
39
|
+
# rubocop:enable Metrics/ParameterLists
|
|
40
|
+
|
|
41
|
+
# Apply tools and tool preferences to the payload.
|
|
42
|
+
def apply_tools(payload, tools, tool_prefs)
|
|
43
|
+
return unless tools.any?
|
|
44
|
+
|
|
45
|
+
payload[:tools] = tools.map { |_, tool| Tools.tool_for(tool) }
|
|
46
|
+
payload[:tool_choice] = build_tool_choice(tool_prefs[:choice]) unless tool_prefs[:choice].nil?
|
|
47
|
+
payload[:parallel_tool_calls] = tool_prefs[:calls] == :many unless tool_prefs[:calls].nil?
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Convert a RubyLLM tool choice symbol to the Responses API format.
|
|
51
|
+
# Responses API accepts "auto", "required", "none", or
|
|
52
|
+
# { type: "function", name: "fn_name" } for a specific function.
|
|
53
|
+
def build_tool_choice(choice)
|
|
54
|
+
case choice
|
|
55
|
+
when :auto, :none, :required
|
|
56
|
+
choice.to_s
|
|
57
|
+
else
|
|
58
|
+
{ type: 'function', name: choice.to_s }
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Build the Responses API text format block from a schema.
|
|
63
|
+
# Schema arrives pre-normalized as { name:, schema:, strict: } from
|
|
64
|
+
# RubyLLM::Chat.with_schema (v1.13+), or as a raw hash (legacy).
|
|
65
|
+
def build_schema_format(schema)
|
|
66
|
+
schema_name = schema[:name] || 'response'
|
|
67
|
+
schema_def = schema[:schema] || schema
|
|
68
|
+
strict = schema.key?(:strict) ? schema[:strict] : true
|
|
69
|
+
|
|
70
|
+
{
|
|
71
|
+
format: {
|
|
72
|
+
type: 'json_schema',
|
|
73
|
+
name: schema_name,
|
|
74
|
+
schema: schema_def,
|
|
75
|
+
strict: strict
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
end
|
|
51
79
|
|
|
52
80
|
def extract_last_response_id(messages)
|
|
53
81
|
messages
|
|
@@ -17,7 +17,9 @@ module RubyLLM
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
# Override to support WebSocket transport via with_params(transport: :websocket)
|
|
20
|
-
|
|
20
|
+
# rubocop:disable Metrics/ParameterLists
|
|
21
|
+
def complete(messages, tools:, temperature:, model:, params: {}, headers: {},
|
|
22
|
+
schema: nil, thinking: nil, tool_prefs: nil, &block)
|
|
21
23
|
if params[:transport]&.to_sym == :websocket
|
|
22
24
|
ws_complete(messages, tools: tools, temperature: temperature, model: model,
|
|
23
25
|
params: params.except(:transport), schema: schema,
|
|
@@ -26,6 +28,7 @@ module RubyLLM
|
|
|
26
28
|
super
|
|
27
29
|
end
|
|
28
30
|
end
|
|
31
|
+
# rubocop:enable Metrics/ParameterLists
|
|
29
32
|
|
|
30
33
|
def headers
|
|
31
34
|
{
|
|
@@ -39,7 +39,7 @@ RubyLLM::Providers::OpenAIResponses::ModelRegistry.register_all!
|
|
|
39
39
|
module RubyLLM
|
|
40
40
|
# ResponsesAPI namespace for direct access to helpers and version
|
|
41
41
|
module ResponsesAPI
|
|
42
|
-
VERSION = '0.5.
|
|
42
|
+
VERSION = '0.5.1'
|
|
43
43
|
|
|
44
44
|
# Shorthand access to built-in tool helpers
|
|
45
45
|
BuiltInTools = Providers::OpenAIResponses::BuiltInTools
|