open_router_enhanced 1.2.1 → 1.2.3
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/.rubocop_todo.yml +33 -15
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +1 -1
- data/docs/tools.md +234 -1
- data/examples/dynamic_model_switching_example.rb +328 -0
- data/examples/real_world_schemas_example.rb +262 -0
- data/examples/responses_api_example.rb +324 -0
- data/examples/tool_loop_example.rb +317 -0
- data/lib/open_router/model_registry.rb +9 -21
- data/lib/open_router/streaming_client.rb +8 -4
- data/lib/open_router/version.rb +1 -1
- metadata +6 -2
|
@@ -36,12 +36,13 @@ module OpenRouter
|
|
|
36
36
|
# @param model [String|Array] Model identifier or array of models for fallback
|
|
37
37
|
# @param accumulate_response [Boolean] Whether to accumulate and return complete response
|
|
38
38
|
# @param extras [Hash] Additional parameters for the completion request
|
|
39
|
+
# @param block [Proc] Optional block to call for each chunk (in addition to registered callbacks)
|
|
39
40
|
# @return [Response, nil] Complete response if accumulate_response is true, nil otherwise
|
|
40
|
-
def stream_complete(messages, model: "openrouter/auto", accumulate_response: true, **extras)
|
|
41
|
+
def stream_complete(messages, model: "openrouter/auto", accumulate_response: true, **extras, &block)
|
|
41
42
|
response_accumulator = ResponseAccumulator.new if accumulate_response
|
|
42
43
|
|
|
43
|
-
# Set up streaming handler
|
|
44
|
-
stream_handler = build_stream_handler(response_accumulator)
|
|
44
|
+
# Set up streaming handler (pass optional per-call block)
|
|
45
|
+
stream_handler = build_stream_handler(response_accumulator, &block)
|
|
45
46
|
|
|
46
47
|
# Trigger start callback
|
|
47
48
|
trigger_streaming_callbacks(:on_start, { model: model, messages: messages })
|
|
@@ -92,11 +93,14 @@ module OpenRouter
|
|
|
92
93
|
|
|
93
94
|
private
|
|
94
95
|
|
|
95
|
-
def build_stream_handler(accumulator)
|
|
96
|
+
def build_stream_handler(accumulator, &per_call_block)
|
|
96
97
|
proc do |chunk|
|
|
97
98
|
# Trigger chunk callback
|
|
98
99
|
trigger_streaming_callbacks(:on_chunk, chunk)
|
|
99
100
|
|
|
101
|
+
# Call per-call block if provided (used by #stream method)
|
|
102
|
+
per_call_block&.call(chunk)
|
|
103
|
+
|
|
100
104
|
# Accumulate if needed
|
|
101
105
|
accumulator&.add_chunk(chunk)
|
|
102
106
|
|
data/lib/open_router/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: open_router_enhanced
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eric Stiens
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-12-
|
|
11
|
+
date: 2025-12-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -136,13 +136,17 @@ files:
|
|
|
136
136
|
- docs/structured_outputs.md
|
|
137
137
|
- docs/tools.md
|
|
138
138
|
- examples/basic_completion.rb
|
|
139
|
+
- examples/dynamic_model_switching_example.rb
|
|
139
140
|
- examples/model_selection_example.rb
|
|
140
141
|
- examples/observability_example.rb
|
|
141
142
|
- examples/prompt_template_example.rb
|
|
143
|
+
- examples/real_world_schemas_example.rb
|
|
144
|
+
- examples/responses_api_example.rb
|
|
142
145
|
- examples/smart_completion_example.rb
|
|
143
146
|
- examples/streaming_example.rb
|
|
144
147
|
- examples/structured_outputs_example.rb
|
|
145
148
|
- examples/tool_calling_example.rb
|
|
149
|
+
- examples/tool_loop_example.rb
|
|
146
150
|
- lib/open_router.rb
|
|
147
151
|
- lib/open_router/client.rb
|
|
148
152
|
- lib/open_router/http.rb
|