open_router_enhanced 2.1.0 → 2.2.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/Gemfile.lock +1 -1
- data/Rakefile +0 -1
- data/examples/dynamic_model_switching_example.rb +0 -0
- data/examples/model_selection_example.rb +0 -0
- data/examples/prompt_template_example.rb +0 -0
- data/examples/real_world_schemas_example.rb +0 -0
- data/examples/responses_api_example.rb +0 -0
- data/examples/smart_completion_example.rb +0 -0
- data/examples/structured_outputs_example.rb +0 -0
- data/examples/tool_calling_example.rb +0 -0
- data/examples/tool_loop_example.rb +0 -0
- data/lib/open_router/callbacks.rb +50 -0
- data/lib/open_router/client.rb +22 -578
- data/lib/open_router/completion_options.rb +15 -7
- data/lib/open_router/parameter_builder.rb +120 -0
- data/lib/open_router/request_handler.rb +99 -0
- data/lib/open_router/response.rb +15 -125
- data/lib/open_router/response_parsing.rb +107 -0
- data/lib/open_router/schema.rb +28 -12
- data/lib/open_router/tool_serializer.rb +152 -0
- data/lib/open_router/version.rb +1 -1
- data/lib/open_router.rb +7 -10
- metadata +7 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9f4936ab4591643976d7cf5f63b92fec61fef1fda2900ce6ed022ce35671bd3a
|
|
4
|
+
data.tar.gz: 1ac1e6ea82c9eacc1bc28e4b99490507bcf1f335446f3ab1cbab2a2ca8d749b4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ef3a651dee0fec1b4d0508e88578c78ed1d259b5dc7c5fb5917d7af0690a2e69c12732f6fc5a0b423340da7afddbc4de80f08f8a27e616c9d7c15a1051508a39
|
|
7
|
+
data.tar.gz: 017ec8a29aeb205e396265409c8f9d53f3f7280d025543e89b2c95510d6b21fe78f230461dcc5291a433c1b60f850425ba754dcfc1ab32e98517b1f522688692
|
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OpenRouter
|
|
4
|
+
# Mixin providing event callback registration and dispatch for Client.
|
|
5
|
+
module Callbacks
|
|
6
|
+
# Register a callback for a specific event
|
|
7
|
+
#
|
|
8
|
+
# @param event [Symbol] The event to register for (:before_request, :after_response, :on_tool_call, :on_error, :on_stream_chunk, :on_healing)
|
|
9
|
+
# @param block [Proc] The callback to execute
|
|
10
|
+
# @return [self] Returns self for method chaining
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# client.on(:after_response) do |response|
|
|
14
|
+
# puts "Used #{response.total_tokens} tokens"
|
|
15
|
+
# end
|
|
16
|
+
def on(event, &block)
|
|
17
|
+
raise ArgumentError, "Invalid event: #{event}. Valid events are: #{@callbacks.keys.join(", ")}" unless @callbacks.key?(event)
|
|
18
|
+
|
|
19
|
+
@callbacks[event] << block
|
|
20
|
+
self
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Remove all callbacks for a specific event
|
|
24
|
+
#
|
|
25
|
+
# @param event [Symbol] The event to clear callbacks for
|
|
26
|
+
# @return [self] Returns self for method chaining
|
|
27
|
+
def clear_callbacks(event = nil)
|
|
28
|
+
if event
|
|
29
|
+
@callbacks[event] = [] if @callbacks.key?(event)
|
|
30
|
+
else
|
|
31
|
+
@callbacks.each_key { |key| @callbacks[key] = [] }
|
|
32
|
+
end
|
|
33
|
+
self
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Trigger callbacks for a specific event
|
|
37
|
+
#
|
|
38
|
+
# @param event [Symbol] The event to trigger
|
|
39
|
+
# @param data [Object] Data to pass to the callbacks
|
|
40
|
+
def trigger_callbacks(event, data = nil)
|
|
41
|
+
return unless @callbacks[event]
|
|
42
|
+
|
|
43
|
+
@callbacks[event].each do |callback|
|
|
44
|
+
callback.call(data)
|
|
45
|
+
rescue StandardError => e
|
|
46
|
+
warn "[OpenRouter] Callback error for #{event}: #{e.message}"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|