llm_specs 0.2.0 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81de39be8dfae6778725b265ee16a65cdfbbc5f10becd03fb1537c895cb7f8d4
4
- data.tar.gz: 3c53b4ee94aaadd71070f89d9c76ddcf7f5a662e1cce2bc62b2626d63e81383e
3
+ metadata.gz: 48e800a2dbfee7149fd20468bcbb8f68b0f5f4d30a1fdf86d03cc067d6b36f53
4
+ data.tar.gz: 75ff11e8f37673d7ac209ba081f32c7b8a12bc461844e84b20a4b553ff9ab5d0
5
5
  SHA512:
6
- metadata.gz: fc192a767f25c7563c6eb6c3ca32b66d08fc905ae6b4a856c597e3b2074ecf517a417ab46ccd3a59da215a98a1e827d3e93cb9b5b9717ac3f2a7359fe0fde23d
7
- data.tar.gz: 7e7bebb57d8f2875f604c519bac4685f78cf9d0227107bcebabc32e9d1fd4b6efa2febb62d04484ed1c1ee47c2cd4277821fabae60d7d9bab0284bd62747675d
6
+ metadata.gz: ca5b4d11c6d3f7b2c4aff772b4cf0170e2c7063091154c5f48ef1010b6e29e803154b37d09ae21cee49c2da6a89afd8b5a2bce527e75b8a02ad35fb55ed3ed75
7
+ data.tar.gz: 72d975c0c18fc754ed7458b4784c1787beca7363948052567fc3310dda4ad314775025126d65bb84e256a9c04c207e10b2793adb9af4511773606e66b0c159fd
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # LLMSpecs
2
2
 
3
- LLMSpecs is a lightweight Ruby interface for fetching and caching
3
+ LLMSpecs is a lightweight Ruby interface for fetching
4
4
  large language model (LLM) specifications from the [Parsera API](https://llmspecs.parsera.org).
5
5
  It provides a simple, efficient way to access model metadata with built-in caching and query support.
6
6
 
@@ -63,7 +63,7 @@ Each model is represented by an instance of `LLMSpecs::Model`, a value object th
63
63
  - `citations?`
64
64
  - `batch?`
65
65
 
66
- - Pricing breakdowns via `input_pricing` and `output_pricing`
66
+ - Pricing breakdowns via `pricing`, `input_pricing` and `output_pricing`
67
67
 
68
68
  You can easily check capabilities:
69
69
  ```ruby
@@ -91,11 +91,35 @@ model.embeddings_output?
91
91
 
92
92
  Pricing methods:
93
93
  ```ruby
94
- model.input_pricing # 1.1 => $ per 1M input tokens (default :text_tokens)
95
- model.output_pricing
94
+ model.input_pricing # => returns a hash:
95
+ # {
96
+ # text_tokens: {
97
+ # standard: {
98
+ # input_per_million: 15.0,
99
+ # cached_input_per_million: 18.75,
100
+ # output_per_million: 75.0
101
+ # },
102
+ # batch: {
103
+ # input_per_million: nil,
104
+ # output_per_million: nil
105
+ # }
106
+ # },
107
+ # embeddings: {
108
+ # standard: {
109
+ # input_per_million: nil
110
+ # },
111
+ # batch: {
112
+ # input_per_million: nil
113
+ # }
114
+ # }
115
+ # }
116
+
117
+ model.pricing.dig(:text_tokens, :standard, :input_per_million)
118
+ model.input_pricing # 15.0 => $ per 1M input tokens (default to pricing[:text_tokens][:standard][:input_per_million])
119
+ model.output_pricing # 75.0 => $ per 1M output tokens
96
120
 
97
121
  model.input_pricing(:text_tokens, :batch)
98
- model.output_pricing(:embeddings)
122
+ model.input_pricing(:embeddings)
99
123
  ```
100
124
 
101
125
  ## Cache configuration
@@ -5,22 +5,30 @@ module LLMSpecs
5
5
  @file = file
6
6
  @ttl = ttl
7
7
  end
8
-
8
+
9
9
  def fetch
10
10
  return read if valid?
11
11
  yield.tap { write it }
12
12
  end
13
13
 
14
- def valid?
15
- File.exist?(@file) && (Time.now - File.mtime(@file) < @ttl)
16
- end
17
-
18
14
  def read
19
- JSON.parse(File.read(@file), symbolize_names: true)
15
+ File.read(@file)
20
16
  end
21
17
 
22
18
  def write(data)
23
- File.write(@file, JSON.pretty_generate(data)) if data
19
+ File.write(@file, data)
20
+ end
21
+
22
+ def valid?
23
+ exist? && fresh?
24
+ end
25
+
26
+ def exist?
27
+ File.exist?(@file)
28
+ end
29
+
30
+ def fresh?
31
+ Time.now - File.mtime(@file) < @ttl
24
32
  end
25
33
  end
26
34
  end
@@ -13,13 +13,11 @@ module LLMSpecs
13
13
  private
14
14
 
15
15
  def fetch
16
- @cache.fetch do
17
- parse Net::HTTP.get_response(@uri).tap(&:value) # raises Net::HTTPError if not 2xx
18
- end
19
- end
20
-
21
- def parse(response)
22
- JSON.parse(response.body, symbolize_names: true)
16
+ @cache.fetch {
17
+ Net::HTTP.get_response(@uri).tap(&:value).body # .value raises Net::HTTPError if not 2xx
18
+ }.then {
19
+ JSON.parse it, symbolize_names: true
20
+ }
23
21
  end
24
22
  end
25
23
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module LLMSpecs
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.2"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llm_specs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Power
@@ -23,9 +23,9 @@ dependencies:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '1.0'
26
- description: LLMSpecs is a lightweight Ruby interface for fetching and caching large
27
- language model (LLM) specifications from the Parsera API. It provides a simple,
28
- efficient way to access model metadata with built-in caching and query support.
26
+ description: LLMSpecs is a lightweight Ruby interface for fetching large language
27
+ model (LLM) specifications from the Parsera API. It provides a simple, efficient
28
+ way to access model metadata with built-in caching and query support.
29
29
  email:
30
30
  - kevin.melchert@gmail.com
31
31
  executables: []
@@ -56,14 +56,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 3.2.0
59
+ version: 3.4.0
60
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - ">="
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  requirements: []
66
- rubygems_version: 3.6.7
66
+ rubygems_version: 3.6.9
67
67
  specification_version: 4
68
68
  summary: Ruby interface for fetching LLM specifications from the Parsera API
69
69
  test_files: []