llm_hub 0.2.1 → 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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/llm_hub/completion/client.rb +15 -3
- data/lib/llm_hub/completion/providers/google.rb +75 -0
- data/lib/llm_hub/version.rb +1 -1
- data/lib/llm_hub.rb +1 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48d9d052b63d19d6c83b84e5cae7c60ac65ce53d6fe464a557a665d682f55e55
|
4
|
+
data.tar.gz: 276a0ad6024d42b9e6dc0000fb0ed2ecea7339ce8412b1be48c3ab1326c92279
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87949cc584f5f8cf6da70de897a1c31c5a0f3e66a312534a90c803ded364fa51cec51b5c855c339fa29c905765e11ea5f315f3de4254870d4fd5d2a50d29c382
|
7
|
+
data.tar.gz: 5d4bdadeec61209087d063ed6e0cb98a490eb5e1f2423e724d0b154259f06416b1b44259a2d9a12fad169f5927fa1c9c6624b023a25e2cacacdeb64b2d3c4346
|
data/CHANGELOG.md
CHANGED
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
|
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
|
|
@@ -9,12 +9,13 @@ 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)
|
18
19
|
# @param open_time_out [Integer] HTTP open timeout in seconds (optional, defaults to Config value)
|
19
20
|
# @param read_time_out [Integer] HTTP read timeout in seconds (optional, defaults to Config value)
|
20
21
|
# @param retry_count [Integer] Number of retries for failed requests (optional, defaults to Config value)
|
@@ -38,7 +39,7 @@ module LlmHub
|
|
38
39
|
option_params: {}
|
39
40
|
)
|
40
41
|
with_retry do
|
41
|
-
url =
|
42
|
+
url = provider_url(model_name)
|
42
43
|
request_body = @provider_client.request_body(system_prompt, content, model_name, option_params)
|
43
44
|
headers = @provider_client.headers
|
44
45
|
|
@@ -51,6 +52,17 @@ module LlmHub
|
|
51
52
|
|
52
53
|
private
|
53
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
|
+
|
54
66
|
# Format the response from provider
|
55
67
|
# @param response_body [Hash] Raw response from provider
|
56
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
|
data/lib/llm_hub/version.rb
CHANGED
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.
|
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-07-
|
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
|
41
|
-
Anthropic.It provides easy access to Completion and
|
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
|
96
|
+
summary: This is a Ruby interface for multiple LLM providers, such as OpenAI, Anthropic,
|
97
|
+
DeepSeek, and Google Gemini.
|
95
98
|
test_files: []
|