active_harness 0.2.37 → 0.2.38
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/active_harness/agent/cost.rb +29 -5
- data/lib/active_harness/agent.rb +0 -12
- data/lib/active_harness.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: '064709a78ef949aadd741237f4cdd5a2f36056d211fa2038048a2911fc45a5be'
|
|
4
|
+
data.tar.gz: 298318704ce083cf46b87dc5dbaebbae15df127a313685ea32d5c82b03191072
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b7c4e5a06e8f8a66e89a0f0b2289c7f461e76cd942a374abb5e6a3845f35e348b8b5fc63182e384d825863ef4c8698c59b64d606d11b5eb27bcada47b1d57642
|
|
7
|
+
data.tar.gz: 3528828f40f1a11a0b62b45ff193b49e05cc202e09e754a578e94c372279cdb760622d5e33de3f61aeef62d7cf15166197a4e0d2a5637d0c4cb8e5d5cf332112
|
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
module ActiveHarness
|
|
2
2
|
class Agent
|
|
3
|
+
# Providers that have a dedicated pricing source beyond ModelsDev.
|
|
4
|
+
# Consulted in tier-2 before the general ModelsDev fallback.
|
|
5
|
+
# Add entries here when a new provider-specific source is available.
|
|
6
|
+
PROVIDER_PRICING_SOURCES = {
|
|
7
|
+
openrouter: Pricing::OpenRouter
|
|
8
|
+
}.freeze
|
|
9
|
+
|
|
3
10
|
private
|
|
4
11
|
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
12
|
+
# Cost lookup — three-tier fallback:
|
|
13
|
+
# 1. provider_cost in the API response (handled in build_usage)
|
|
14
|
+
# 2. provider-specific source (e.g. Pricing::OpenRouter for :openrouter)
|
|
15
|
+
# 3. Pricing::ModelsDev general fallback
|
|
16
|
+
# → nil when no data found at any tier
|
|
17
|
+
def lookup_model_cost(entry)
|
|
18
|
+
return nil unless entry
|
|
19
|
+
|
|
20
|
+
model = entry[:model].to_s
|
|
21
|
+
provider = entry[:provider].to_sym
|
|
22
|
+
|
|
23
|
+
source = PROVIDER_PRICING_SOURCES[provider]
|
|
24
|
+
cost = source&.find(model)
|
|
25
|
+
return cost if cost
|
|
26
|
+
|
|
27
|
+
Pricing::ModelsDev.find(model)
|
|
28
|
+
rescue StandardError
|
|
29
|
+
nil
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Builds a CostBreakdown from token counts and per-million rates.
|
|
33
|
+
# Returns nil when pricing or token data is absent.
|
|
10
34
|
def calculate_cost(pricing, tokens)
|
|
11
35
|
return nil unless pricing && tokens
|
|
12
36
|
return nil unless pricing.input_per_million && pricing.output_per_million
|
data/lib/active_harness/agent.rb
CHANGED
|
@@ -198,18 +198,6 @@ module ActiveHarness
|
|
|
198
198
|
UsageInfo.new(tokens: tokens, cost: cost)
|
|
199
199
|
end
|
|
200
200
|
|
|
201
|
-
def lookup_model_cost(entry)
|
|
202
|
-
return nil unless entry
|
|
203
|
-
|
|
204
|
-
if entry[:provider].to_sym == :openrouter
|
|
205
|
-
Pricing::OpenRouter.find(entry[:model].to_s) || Pricing.find(entry[:model].to_s)
|
|
206
|
-
else
|
|
207
|
-
Pricing.find(entry[:model].to_s)
|
|
208
|
-
end
|
|
209
|
-
rescue StandardError
|
|
210
|
-
nil
|
|
211
|
-
end
|
|
212
|
-
|
|
213
201
|
def normalize_input!
|
|
214
202
|
return if @config.fetch(:normalize_input, true) == false
|
|
215
203
|
@input = @input&.strip&.gsub(/\s+/, " ")
|
data/lib/active_harness.rb
CHANGED