llmshim 0.3.7 → 0.5.0
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/lib/llmshim/client.rb +3 -0
- data/lib/llmshim/types.rb +49 -7
- data/lib/llmshim/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5929fc579493f05ebbfc27fa5aaa5c570b6f886421545f2ab0c008d695bca4e7
|
|
4
|
+
data.tar.gz: bb2947ee359e67054a0ca8946890d9c139cd866e7c169c4a2d28af10caaa1b9e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 555a81741fe9549d5beded8aa0857594e9af7d4836c99b6a155302228434e8100a1246c4158ad19390152b28892bb51071e28df99d17b4641393e342566efa97
|
|
7
|
+
data.tar.gz: a9d8c8cac89793ce30f475498404468c546916104c8c88953208079100da5dd92b6a626013c1067ce45d57c1d426c1f83adad969a2e78c701509a80f6b8494e2
|
data/lib/llmshim/client.rb
CHANGED
|
@@ -120,6 +120,9 @@ module Llmshim
|
|
|
120
120
|
provider_config["tool_choice"] = opts[:tool_choice] unless opts[:tool_choice].nil?
|
|
121
121
|
body["provider_config"] = provider_config unless provider_config.empty?
|
|
122
122
|
|
|
123
|
+
body["x-cache"] = stringify(opts[:cache]) unless opts[:cache].nil?
|
|
124
|
+
body["x-shim"] = stringify(opts[:shim]) unless opts[:shim].nil?
|
|
125
|
+
body["response_format"] = stringify(opts[:response_format]) unless opts[:response_format].nil?
|
|
123
126
|
body["fallback"] = opts[:fallback] unless opts[:fallback].nil?
|
|
124
127
|
body["stream"] = opts[:stream] unless opts[:stream].nil?
|
|
125
128
|
|
data/lib/llmshim/types.rb
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
3
5
|
module Llmshim
|
|
4
6
|
# Token accounting returned with a chat response or a usage stream event.
|
|
5
7
|
#
|
|
6
8
|
# Mirrors the +Usage+ schema in api/openapi.yaml.
|
|
7
9
|
Usage = Struct.new(
|
|
8
10
|
:input_tokens, :output_tokens, :reasoning_tokens, :total_tokens,
|
|
11
|
+
:cache_read_tokens, :cache_write_tokens, :cost_usd,
|
|
9
12
|
keyword_init: true
|
|
10
13
|
) do
|
|
11
14
|
def self.from_hash(hash)
|
|
@@ -15,7 +18,11 @@ module Llmshim
|
|
|
15
18
|
input_tokens: hash["input_tokens"],
|
|
16
19
|
output_tokens: hash["output_tokens"],
|
|
17
20
|
reasoning_tokens: hash["reasoning_tokens"],
|
|
18
|
-
total_tokens: hash["total_tokens"]
|
|
21
|
+
total_tokens: hash["total_tokens"],
|
|
22
|
+
cache_read_tokens: hash.fetch("cache_read_tokens", 0),
|
|
23
|
+
cache_write_tokens: hash.fetch("cache_write_tokens", 0),
|
|
24
|
+
# nil means the server could not price the model, never free.
|
|
25
|
+
cost_usd: hash["cost_usd"]
|
|
19
26
|
)
|
|
20
27
|
end
|
|
21
28
|
end
|
|
@@ -24,9 +31,13 @@ module Llmshim
|
|
|
24
31
|
#
|
|
25
32
|
# +function+ is a plain Hash with "name" and "arguments" (JSON-encoded string)
|
|
26
33
|
# to match the wire format exactly.
|
|
27
|
-
ToolCall = Struct.new(:id, :type, :function, keyword_init: true) do
|
|
34
|
+
ToolCall = Struct.new(:id, :type, :function, :thought_signature, :wire_ids, keyword_init: true) do
|
|
28
35
|
def self.from_hash(hash)
|
|
29
|
-
new(id: hash["id"], type: hash["type"], function: hash["function"])
|
|
36
|
+
new(id: hash["id"], type: hash["type"], function: hash["function"], thought_signature: hash["thought_signature"], wire_ids: hash["wire_ids"])
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def to_json(*args)
|
|
40
|
+
to_h.reject { |_key, value| value.nil? }.to_json(*args)
|
|
30
41
|
end
|
|
31
42
|
|
|
32
43
|
# Convenience accessor for the tool name.
|
|
@@ -41,10 +52,14 @@ module Llmshim
|
|
|
41
52
|
end
|
|
42
53
|
|
|
43
54
|
# The assistant message inside a ChatResponse.
|
|
44
|
-
ResponseMessage = Struct.new(:role, :content, :tool_calls, keyword_init: true) do
|
|
55
|
+
ResponseMessage = Struct.new(:role, :content, :tool_calls, :reasoning, :refusal, keyword_init: true) do
|
|
45
56
|
def self.from_hash(hash)
|
|
46
57
|
calls = (hash["tool_calls"] || []).map { |c| ToolCall.from_hash(c) }
|
|
47
|
-
new(role: hash["role"], content: hash["content"], tool_calls: calls)
|
|
58
|
+
new(role: hash["role"], content: hash["content"], tool_calls: calls, reasoning: hash["reasoning"], refusal: hash["refusal"])
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def to_json(*args)
|
|
62
|
+
to_h.reject { |key, value| value.nil? && !%i[role content].include?(key) }.to_json(*args)
|
|
48
63
|
end
|
|
49
64
|
end
|
|
50
65
|
|
|
@@ -52,7 +67,7 @@ module Llmshim
|
|
|
52
67
|
#
|
|
53
68
|
# +raw+ retains the original parsed Hash for forward compatibility.
|
|
54
69
|
ChatResponse = Struct.new(
|
|
55
|
-
:id, :model, :provider, :message, :reasoning, :usage, :latency_ms, :raw,
|
|
70
|
+
:id, :model, :provider, :message, :reasoning, :usage, :latency_ms, :raw, :served_model, :finish_reason,
|
|
56
71
|
keyword_init: true
|
|
57
72
|
) do
|
|
58
73
|
def self.from_hash(hash)
|
|
@@ -64,7 +79,9 @@ module Llmshim
|
|
|
64
79
|
reasoning: hash["reasoning"],
|
|
65
80
|
usage: Usage.from_hash(hash["usage"]),
|
|
66
81
|
latency_ms: hash["latency_ms"],
|
|
67
|
-
raw: hash
|
|
82
|
+
raw: hash,
|
|
83
|
+
served_model: hash["x-llmshim-served-model"],
|
|
84
|
+
finish_reason: hash["finish_reason"]
|
|
68
85
|
)
|
|
69
86
|
end
|
|
70
87
|
|
|
@@ -120,10 +137,22 @@ module Llmshim
|
|
|
120
137
|
type == "usage"
|
|
121
138
|
end
|
|
122
139
|
|
|
140
|
+
def finish_reason
|
|
141
|
+
raw["finish_reason"]
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def served_model
|
|
145
|
+
raw["x-llmshim-served-model"]
|
|
146
|
+
end
|
|
147
|
+
|
|
123
148
|
def done?
|
|
124
149
|
type == "done"
|
|
125
150
|
end
|
|
126
151
|
|
|
152
|
+
def error_details
|
|
153
|
+
raw["error"]
|
|
154
|
+
end
|
|
155
|
+
|
|
127
156
|
def error?
|
|
128
157
|
type == "error"
|
|
129
158
|
end
|
|
@@ -133,6 +162,19 @@ module Llmshim
|
|
|
133
162
|
raw["text"]
|
|
134
163
|
end
|
|
135
164
|
|
|
165
|
+
# Reasoning delta blocks retain signatures, opaque data, and provenance.
|
|
166
|
+
def blocks
|
|
167
|
+
raw["blocks"]
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def thought_signature
|
|
171
|
+
raw["thought_signature"]
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def wire_ids
|
|
175
|
+
raw["wire_ids"]
|
|
176
|
+
end
|
|
177
|
+
|
|
136
178
|
# tool_call events
|
|
137
179
|
def id
|
|
138
180
|
raw["id"]
|
data/lib/llmshim/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: llmshim
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sanjay Nadhavajhala
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-09-
|
|
11
|
+
date: 2026-09-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|