llm_hub 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c791bf83c85b80125da4cf8a71eab51d804f21f0f29d128f27710c6bd0e9c621
4
- data.tar.gz: 244a67dd97fd68b97a345971a7e806520c83f6906f9d50362ad2dc8b29086253
3
+ metadata.gz: 48d9d052b63d19d6c83b84e5cae7c60ac65ce53d6fe464a557a665d682f55e55
4
+ data.tar.gz: 276a0ad6024d42b9e6dc0000fb0ed2ecea7339ce8412b1be48c3ab1326c92279
5
5
  SHA512:
6
- metadata.gz: a64411fb25ba585dffc8251414231871ff173d89a16e06c4c0b0d6c8bf00fcb859bcf5f7ff0bec7c653ca5249fa48b1d70e03ee507dbc82851d1f4b8c02a3e5c
7
- data.tar.gz: 89e38e3d90d585b56809a5fb7e18f4e7257fa4f8675e7172a622ef56f222175b2d68b1b60f73a8f6e50a391b121e8e7523f014fe0af79c98e4f57881d7c35eef
6
+ metadata.gz: 87949cc584f5f8cf6da70de897a1c31c5a0f3e66a312534a90c803ded364fa51cec51b5c855c339fa29c905765e11ea5f315f3de4254870d4fd5d2a50d29c382
7
+ data.tar.gz: 5d4bdadeec61209087d063ed6e0cb98a490eb5e1f2423e724d0b154259f06416b1b44259a2d9a12fad169f5927fa1c9c6624b023a25e2cacacdeb64b2d3c4346
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2025-07-08
4
+
5
+ - Added Google as a provider.
6
+
7
+ ## [0.2.1] - 2025-07-04
8
+
9
+ - Added new option parameters.
10
+
11
+ ## [0.2.0] - 2025-06-17
12
+
13
+ - Added Deepseek as a provider.
14
+
3
15
  ## [0.1.1] - 2025-05-30
4
16
 
5
17
  - Updated description in README.md
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # LlmHub
2
2
 
3
- This is a Ruby interface for multiple LLM providers, such as OpenAI, Anthropic, and DeepSeek.
3
+ This is a Ruby interface for multiple LLM providers, such as OpenAI, Anthropic, DeepSeek, and Google Gemini.
4
4
 
5
5
  It provides easy access to Completion and Embedding functionalities.
6
6
 
@@ -37,7 +37,7 @@ puts response
37
37
 
38
38
  ## Development
39
39
 
40
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run the tests and code quality checks (or `rake spec` for tests only). You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
41
 
42
42
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
43
 
@@ -8,15 +8,20 @@ module LlmHub
8
8
  class ClientBase
9
9
  include LlmHub::Common::HttpHelper
10
10
 
11
- attr_reader :api_key, :provider, :retry_count
11
+ attr_reader :api_key, :provider, :retry_count, :open_time_out, :read_time_out
12
12
 
13
13
  # Initialize a new client
14
14
  # @param api_key [String] API key for the provider (required)
15
15
  # @param provider [Symbol, String] Provider name (required)
16
- def initialize(api_key:, provider:)
16
+ # @param open_time_out [Integer] HTTP open timeout in seconds (optional, defaults to Config value)
17
+ # @param read_time_out [Integer] HTTP read timeout in seconds (optional, defaults to Config value)
18
+ # @param retry_count [Integer] Number of retries for failed requests (optional, defaults to Config value)
19
+ def initialize(api_key:, provider:, open_time_out: nil, read_time_out: nil, retry_count: nil)
17
20
  @api_key = api_key
18
21
  @provider = provider
19
- @retry_count = LlmHub::Config::RETRY_COUNT
22
+ @open_time_out = open_time_out || LlmHub::Config::DEFAULT_OPEN_TIME_OUT
23
+ @read_time_out = read_time_out || LlmHub::Config::DEFAULT_READ_TIME_OUT
24
+ @retry_count = retry_count || LlmHub::Config::DEFAULT_RETRY_COUNT
20
25
  end
21
26
 
22
27
  protected
@@ -29,8 +29,8 @@ module LlmHub
29
29
  )
30
30
  http_client.use_ssl = uri.scheme == 'https'
31
31
  http_client.verify_mode = OpenSSL::SSL::VERIFY_NONE
32
- http_client.open_timeout = LlmHub::Config::OPEN_TIME_OUT
33
- http_client.read_timeout = LlmHub::Config::READ_TIME_OUT
32
+ http_client.open_timeout = @open_time_out
33
+ http_client.read_timeout = @read_time_out
34
34
  http_client
35
35
  end
36
36
  end
@@ -9,14 +9,18 @@ module LlmHub
9
9
  PROVIDER_CLASSES = {
10
10
  openai: Providers::OpenAI,
11
11
  anthropic: Providers::Anthropic,
12
- deepseek: Providers::Deepseek
12
+ deepseek: Providers::Deepseek,
13
+ google: Providers::Google
13
14
  }.freeze
14
15
 
15
16
  # Initialize a new completion client
16
17
  # @param api_key [String] API key for the provider (required)
17
- # @param provider [Symbol, String] Provider name (:openai, :anthropic, :deepseek) (required)
18
+ # @param provider [Symbol, String] Provider name (:openai, :anthropic, :deepseek, :google) (required)
19
+ # @param open_time_out [Integer] HTTP open timeout in seconds (optional, defaults to Config value)
20
+ # @param read_time_out [Integer] HTTP read timeout in seconds (optional, defaults to Config value)
21
+ # @param retry_count [Integer] Number of retries for failed requests (optional, defaults to Config value)
18
22
  # @see LlmHub::Common::ClientBase#initialize
19
- def initialize(api_key:, provider:)
23
+ def initialize(api_key:, provider:, open_time_out: nil, read_time_out: nil, retry_count: nil)
20
24
  super
21
25
  @provider_client = create_provider_client
22
26
  end
@@ -35,7 +39,7 @@ module LlmHub
35
39
  option_params: {}
36
40
  )
37
41
  with_retry do
38
- url = @provider_client.url
42
+ url = provider_url(model_name)
39
43
  request_body = @provider_client.request_body(system_prompt, content, model_name, option_params)
40
44
  headers = @provider_client.headers
41
45
 
@@ -48,6 +52,17 @@ module LlmHub
48
52
 
49
53
  private
50
54
 
55
+ # Get the appropriate URL for the provider
56
+ # @param model_name [String] Model name to use
57
+ # @return [String] Provider URL
58
+ def provider_url(model_name)
59
+ if @provider_client.is_a?(Providers::Google)
60
+ @provider_client.url(model_name)
61
+ else
62
+ @provider_client.url
63
+ end
64
+ end
65
+
51
66
  # Format the response from provider
52
67
  # @param response_body [Hash] Raw response from provider
53
68
  # @return [Hash{Symbol => String, Integer}] Formatted response
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LlmHub
4
+ module Completion
5
+ module Providers
6
+ # Google Gemini completion provider
7
+ class Google < Base
8
+ COMPLETIONS_URI = 'https://generativelanguage.googleapis.com/v1beta/models'
9
+
10
+ def url(model_name)
11
+ # Gemini API requires model name in URL
12
+ "#{COMPLETIONS_URI}/#{model_name}:generateContent"
13
+ end
14
+
15
+ def headers
16
+ {
17
+ 'Content-Type' => 'application/json',
18
+ 'x-goog-api-key' => @api_key
19
+ }
20
+ end
21
+
22
+ def request_body(system_prompt, content, _model_name, option_params)
23
+ {
24
+ system_instruction: build_system_instruction(system_prompt),
25
+ contents: build_contents(content),
26
+ generationConfig: build_generation_config(option_params)
27
+ }
28
+ end
29
+
30
+ def extract_answer(response_body)
31
+ response_body&.dig('candidates', 0, 'content', 'parts', 0, 'text')
32
+ end
33
+
34
+ def extract_tokens(response_body)
35
+ usage_metadata = response_body&.dig('usageMetadata')
36
+ {
37
+ total_tokens: usage_metadata&.dig('totalTokenCount'),
38
+ prompt_tokens: usage_metadata&.dig('promptTokenCount'),
39
+ completion_tokens: usage_metadata&.dig('candidatesTokenCount')
40
+ }
41
+ end
42
+
43
+ private
44
+
45
+ def build_system_instruction(system_prompt)
46
+ {
47
+ parts: [
48
+ {
49
+ text: system_prompt
50
+ }
51
+ ]
52
+ }
53
+ end
54
+
55
+ def build_contents(content)
56
+ [{
57
+ role: 'user',
58
+ parts: [{ text: content }]
59
+ }]
60
+ end
61
+
62
+ def build_generation_config(option_params)
63
+ base_config = {
64
+ temperature: 0.2,
65
+ maxOutputTokens: 1024,
66
+ topP: 0.8,
67
+ topK: 40
68
+ }
69
+
70
+ option_params.any? ? base_config.merge(option_params) : base_config
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module LlmHub
4
4
  module Config
5
- OPEN_TIME_OUT = 5
6
- READ_TIME_OUT = 20
7
- RETRY_COUNT = 1
5
+ DEFAULT_OPEN_TIME_OUT = 5
6
+ DEFAULT_READ_TIME_OUT = 20
7
+ DEFAULT_RETRY_COUNT = 1
8
8
  end
9
9
  end
@@ -13,8 +13,11 @@ module LlmHub
13
13
  # Initialize a new embedding client
14
14
  # @param api_key [String] API key for the provider (required)
15
15
  # @param provider [Symbol, String] Provider name (:openai) (required)
16
+ # @param open_time_out [Integer] HTTP open timeout in seconds (optional, defaults to Config value)
17
+ # @param read_time_out [Integer] HTTP read timeout in seconds (optional, defaults to Config value)
18
+ # @param retry_count [Integer] Number of retries for failed requests (optional, defaults to Config value)
16
19
  # @see LlmHub::Common::ClientBase#initialize
17
- def initialize(api_key:, provider:)
20
+ def initialize(api_key:, provider:, open_time_out: nil, read_time_out: nil, retry_count: nil)
18
21
  super
19
22
  @provider_client = create_provider_client
20
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LlmHub
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/llm_hub.rb CHANGED
@@ -19,6 +19,7 @@ require_relative 'llm_hub/completion/providers/base'
19
19
  require_relative 'llm_hub/completion/providers/openai'
20
20
  require_relative 'llm_hub/completion/providers/anthropic'
21
21
  require_relative 'llm_hub/completion/providers/deepseek'
22
+ require_relative 'llm_hub/completion/providers/google'
22
23
  require_relative 'llm_hub/completion/client'
23
24
 
24
25
  # Embedding providers
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llm_hub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - akiraNuma
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-06-17 00:00:00.000000000 Z
10
+ date: 2025-07-07 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport
@@ -37,8 +37,9 @@ dependencies:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
- description: This is a Ruby interface for multiple LLM providers, such as OpenAI and
41
- Anthropic.It provides easy access to Completion and Embedding functionalities.
40
+ description: This is a Ruby interface for multiple LLM providers, such as OpenAI,
41
+ Anthropic, DeepSeek, and Google Gemini.It provides easy access to Completion and
42
+ Embedding functionalities.
42
43
  email:
43
44
  - akiran@akiranumakura.com
44
45
  executables: []
@@ -60,6 +61,7 @@ files:
60
61
  - lib/llm_hub/completion/providers/anthropic.rb
61
62
  - lib/llm_hub/completion/providers/base.rb
62
63
  - lib/llm_hub/completion/providers/deepseek.rb
64
+ - lib/llm_hub/completion/providers/google.rb
63
65
  - lib/llm_hub/completion/providers/openai.rb
64
66
  - lib/llm_hub/config.rb
65
67
  - lib/llm_hub/embedding/client.rb
@@ -91,5 +93,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
93
  requirements: []
92
94
  rubygems_version: 3.6.3
93
95
  specification_version: 4
94
- summary: This is a Ruby interface for multiple LLM providers, such as OpenAI and Anthropic.
96
+ summary: This is a Ruby interface for multiple LLM providers, such as OpenAI, Anthropic,
97
+ DeepSeek, and Google Gemini.
95
98
  test_files: []