omniai-google 1.9.3 → 1.9.6
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/Gemfile +13 -11
- data/lib/omniai/google/chat/choice_serializer.rb +1 -1
- data/lib/omniai/google/chat/content_serializer.rb +2 -2
- data/lib/omniai/google/chat/function_serializer.rb +2 -2
- data/lib/omniai/google/chat/media_serializer.rb +1 -1
- data/lib/omniai/google/chat/message_serializer.rb +5 -5
- data/lib/omniai/google/chat/payload_serializer.rb +2 -2
- data/lib/omniai/google/chat/text_serializer.rb +1 -1
- data/lib/omniai/google/chat/tool_call_result_serializer.rb +2 -2
- data/lib/omniai/google/chat/tool_call_serializer.rb +1 -1
- data/lib/omniai/google/chat/usage_serializer.rb +3 -3
- data/lib/omniai/google/chat.rb +10 -12
- data/lib/omniai/google/config.rb +6 -6
- data/lib/omniai/google/embed.rb +4 -4
- data/lib/omniai/google/upload/file.rb +4 -4
- data/lib/omniai/google/upload.rb +4 -6
- data/lib/omniai/google/version.rb +1 -1
- data/lib/omniai/google.rb +3 -3
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 94943a4eb224e5224148c1109d3a8472d26f40d83684c102cee11f6f46d5ae00
|
|
4
|
+
data.tar.gz: c234428c542e1b507dcf86a80e624eec640173db0604c7e2f10264de569532b4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 55eec5fa84a4f4662d2623bd79443bf41df07b84961349f2c8fd974bbfb441ec3b3bdfbc8da9738156215da54bd74f3e2bb636e4878180ef523f379b76e474d3
|
|
7
|
+
data.tar.gz: 1bc60cd887bc6dfd531556291f06b192622586a59872818491d39ea99464f290f4d231d2935a64fd35b0a75736becfc1ac5c3d52f75b127fd6916fe13f572b23
|
data/Gemfile
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
source
|
|
3
|
+
source "https://rubygems.org"
|
|
4
4
|
|
|
5
5
|
gemspec
|
|
6
6
|
|
|
7
|
-
gem
|
|
8
|
-
gem
|
|
9
|
-
gem
|
|
10
|
-
gem
|
|
11
|
-
gem
|
|
12
|
-
gem
|
|
13
|
-
gem
|
|
14
|
-
gem
|
|
15
|
-
gem
|
|
16
|
-
gem
|
|
7
|
+
gem "irb"
|
|
8
|
+
gem "logger"
|
|
9
|
+
gem "rake"
|
|
10
|
+
gem "rspec"
|
|
11
|
+
gem "rspec_junit_formatter"
|
|
12
|
+
gem "rubocop"
|
|
13
|
+
gem "rubocop-basic"
|
|
14
|
+
gem "rubocop-rake"
|
|
15
|
+
gem "rubocop-rspec"
|
|
16
|
+
gem "simplecov"
|
|
17
|
+
gem "webmock"
|
|
18
|
+
gem "yard"
|
|
@@ -17,7 +17,7 @@ module OmniAI
|
|
|
17
17
|
# @param context [Context]
|
|
18
18
|
# @return [OmniAI::Chat::Choice]
|
|
19
19
|
def self.deserialize(data, context:)
|
|
20
|
-
message = OmniAI::Chat::Message.deserialize(data[
|
|
20
|
+
message = OmniAI::Chat::Message.deserialize(data["content"], context:)
|
|
21
21
|
OmniAI::Chat::Choice.new(message:)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
@@ -10,8 +10,8 @@ module OmniAI
|
|
|
10
10
|
# @return [OmniAI::Chat::Text, OmniAI::Chat::ToolCall]
|
|
11
11
|
def self.deserialize(data, context:)
|
|
12
12
|
case
|
|
13
|
-
when data[
|
|
14
|
-
when data[
|
|
13
|
+
when data["text"] then data["text"]
|
|
14
|
+
when data["functionCall"] then OmniAI::Chat::ToolCall.deserialize(data, context:)
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
end
|
|
@@ -17,8 +17,8 @@ module OmniAI
|
|
|
17
17
|
# @param data [Hash]
|
|
18
18
|
# @return [OmniAI::Chat::Function]
|
|
19
19
|
def self.deserialize(data, *)
|
|
20
|
-
name = data[
|
|
21
|
-
arguments = data[
|
|
20
|
+
name = data["name"]
|
|
21
|
+
arguments = data["args"]
|
|
22
22
|
OmniAI::Chat::Function.new(name:, arguments:)
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -24,12 +24,12 @@ module OmniAI
|
|
|
24
24
|
# @param context [OmniAI::Context]
|
|
25
25
|
# @return [OmniAI::Chat::Message]
|
|
26
26
|
def self.deserialize(data, context:)
|
|
27
|
-
role = data[
|
|
28
|
-
parts = arrayify(data[
|
|
27
|
+
role = data["role"]
|
|
28
|
+
parts = arrayify(data["parts"]).map do |part|
|
|
29
29
|
case
|
|
30
|
-
when part[
|
|
31
|
-
when part[
|
|
32
|
-
when part[
|
|
30
|
+
when part["text"] then OmniAI::Chat::Text.deserialize(part, context:)
|
|
31
|
+
when part["functionCall"] then OmniAI::Chat::ToolCall.deserialize(part, context:)
|
|
32
|
+
when part["functionResponse"] then OmniAI::Chat::ToolCallResult.deserialize(part, context:)
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
|
|
@@ -22,8 +22,8 @@ module OmniAI
|
|
|
22
22
|
# @param context [OmniAI::Context]
|
|
23
23
|
# @return [OmniAI::Chat::Payload]
|
|
24
24
|
def self.deserialize(data, context:)
|
|
25
|
-
choices = data[
|
|
26
|
-
usage = OmniAI::Chat::Usage.deserialize(data[
|
|
25
|
+
choices = data["candidates"].map { |candidate| OmniAI::Chat::Choice.deserialize(candidate, context:) }
|
|
26
|
+
usage = OmniAI::Chat::Usage.deserialize(data["usageMetadata"], context:) if data["usageMetadata"]
|
|
27
27
|
|
|
28
28
|
OmniAI::Chat::Payload.new(choices:, usage:)
|
|
29
29
|
end
|
|
@@ -22,8 +22,8 @@ module OmniAI
|
|
|
22
22
|
# @param data [Hash]
|
|
23
23
|
# @return [ToolCallResult]
|
|
24
24
|
def self.deserialize(data, *)
|
|
25
|
-
tool_call_id = data[
|
|
26
|
-
content = data[
|
|
25
|
+
tool_call_id = data["functionResponse"]["name"]
|
|
26
|
+
content = data["functionResponse"]["response"]["content"]
|
|
27
27
|
OmniAI::Chat::ToolCallResult.new(content:, tool_call_id:)
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -16,7 +16,7 @@ module OmniAI
|
|
|
16
16
|
# @param context [OmniAI::Context]
|
|
17
17
|
# @return [OmniAI::Chat::ToolCall]
|
|
18
18
|
def self.deserialize(data, context:)
|
|
19
|
-
function = OmniAI::Chat::Function.deserialize(data[
|
|
19
|
+
function = OmniAI::Chat::Function.deserialize(data["functionCall"], context:)
|
|
20
20
|
OmniAI::Chat::ToolCall.new(id: function.name, function:)
|
|
21
21
|
end
|
|
22
22
|
end
|
|
@@ -18,9 +18,9 @@ module OmniAI
|
|
|
18
18
|
# @param data [Hash]
|
|
19
19
|
# @return [OmniAI::Chat::Usage]
|
|
20
20
|
def self.deserialize(data, *)
|
|
21
|
-
input_tokens = data[
|
|
22
|
-
output_tokens = data[
|
|
23
|
-
total_tokens = data[
|
|
21
|
+
input_tokens = data["promptTokenCount"]
|
|
22
|
+
output_tokens = data["candidatesTokenCount"]
|
|
23
|
+
total_tokens = data["totalTokenCount"]
|
|
24
24
|
OmniAI::Chat::Usage.new(input_tokens:, output_tokens:, total_tokens:)
|
|
25
25
|
end
|
|
26
26
|
end
|
data/lib/omniai/google/chat.rb
CHANGED
|
@@ -13,19 +13,17 @@ module OmniAI
|
|
|
13
13
|
# chat.completion([{ role: 'system', content: 'Tell me a joke.' }])
|
|
14
14
|
class Chat < OmniAI::Chat
|
|
15
15
|
module Model
|
|
16
|
-
GEMINI_1_0_PRO =
|
|
17
|
-
GEMINI_1_5_PRO =
|
|
18
|
-
GEMINI_1_5_FLASH =
|
|
19
|
-
|
|
20
|
-
GEMINI_1_5_PRO_LATEST = 'gemini-1.5-pro-latest'
|
|
21
|
-
GEMINI_1_5_FLASH_LATEST = 'gemini-1.5-flash-latest'
|
|
16
|
+
GEMINI_1_0_PRO = "gemini-1.0-pro"
|
|
17
|
+
GEMINI_1_5_PRO = "gemini-1.5-pro"
|
|
18
|
+
GEMINI_1_5_FLASH = "gemini-1.5-flash"
|
|
19
|
+
GEMINI_2_0_FLASH = "gemini-2.0-flash"
|
|
22
20
|
GEMINI_PRO = GEMINI_1_5_PRO
|
|
23
|
-
GEMINI_FLASH =
|
|
21
|
+
GEMINI_FLASH = GEMINI_2_0_FLASH
|
|
24
22
|
end
|
|
25
23
|
|
|
26
24
|
DEFAULT_MODEL = Model::GEMINI_PRO
|
|
27
25
|
|
|
28
|
-
JSON_MIME_TYPE =
|
|
26
|
+
JSON_MIME_TYPE = "application/json"
|
|
29
27
|
|
|
30
28
|
# @return [Context]
|
|
31
29
|
CONTEXT = Context.build do |context|
|
|
@@ -61,7 +59,7 @@ module OmniAI
|
|
|
61
59
|
context.serializers[:tool] = ToolSerializer.method(:serialize)
|
|
62
60
|
end
|
|
63
61
|
|
|
64
|
-
|
|
62
|
+
protected
|
|
65
63
|
|
|
66
64
|
# @return [Context]
|
|
67
65
|
def context
|
|
@@ -75,7 +73,7 @@ module OmniAI
|
|
|
75
73
|
.accept(:json)
|
|
76
74
|
.post(path, params: {
|
|
77
75
|
key: @client.api_key,
|
|
78
|
-
alt: (
|
|
76
|
+
alt: ("sse" if @stream),
|
|
79
77
|
}.compact, json: payload)
|
|
80
78
|
end
|
|
81
79
|
|
|
@@ -123,7 +121,7 @@ module OmniAI
|
|
|
123
121
|
|
|
124
122
|
# @return [String]
|
|
125
123
|
def operation
|
|
126
|
-
@stream ?
|
|
124
|
+
@stream ? "streamGenerateContent" : "generateContent"
|
|
127
125
|
end
|
|
128
126
|
|
|
129
127
|
# @return [Array<Message>]
|
|
@@ -132,7 +130,7 @@ module OmniAI
|
|
|
132
130
|
ToolCallResult.new(tool_call_id: tool_call.id, content: execute_tool_call(tool_call))
|
|
133
131
|
end
|
|
134
132
|
|
|
135
|
-
[Message.new(role:
|
|
133
|
+
[Message.new(role: "function", content:)]
|
|
136
134
|
end
|
|
137
135
|
end
|
|
138
136
|
end
|
data/lib/omniai/google/config.rb
CHANGED
|
@@ -5,11 +5,11 @@ module OmniAI
|
|
|
5
5
|
# Configuration for Google.
|
|
6
6
|
class Config < OmniAI::Config
|
|
7
7
|
module Version
|
|
8
|
-
STABLE =
|
|
9
|
-
BETA =
|
|
8
|
+
STABLE = "v1"
|
|
9
|
+
BETA = "v1beta"
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
DEFAULT_HOST =
|
|
12
|
+
DEFAULT_HOST = "https://generativelanguage.googleapis.com"
|
|
13
13
|
DEFAULT_VERSION = Version::BETA
|
|
14
14
|
|
|
15
15
|
# @!attribute [rw] version
|
|
@@ -22,9 +22,9 @@ module OmniAI
|
|
|
22
22
|
# @param logger [Logger, nil] optional - defaults to
|
|
23
23
|
# @param timeout [Integer, Hash, nil] optional
|
|
24
24
|
def initialize(
|
|
25
|
-
api_key: ENV.fetch(
|
|
26
|
-
host: ENV.fetch(
|
|
27
|
-
version: ENV.fetch(
|
|
25
|
+
api_key: ENV.fetch("GOOGLE_API_KEY", nil),
|
|
26
|
+
host: ENV.fetch("GOOGLE_HOST", DEFAULT_HOST),
|
|
27
|
+
version: ENV.fetch("GOOGLE_VERSION", DEFAULT_VERSION),
|
|
28
28
|
logger: nil,
|
|
29
29
|
timeout: nil
|
|
30
30
|
)
|
data/lib/omniai/google/embed.rb
CHANGED
|
@@ -11,8 +11,8 @@ module OmniAI
|
|
|
11
11
|
# response.embedding [0.0, ...]
|
|
12
12
|
class Embed < OmniAI::Embed
|
|
13
13
|
module Model
|
|
14
|
-
TEXT_EMBEDDING_004 =
|
|
15
|
-
TEXT_MULTILINGUAL_EMBEDDING_002 =
|
|
14
|
+
TEXT_EMBEDDING_004 = "text-embedding-004"
|
|
15
|
+
TEXT_MULTILINGUAL_EMBEDDING_002 = "text-multilingual-embedding-002"
|
|
16
16
|
EMBEDDING = TEXT_EMBEDDING_004
|
|
17
17
|
MULTILINGUAL_EMBEDDING = TEXT_MULTILINGUAL_EMBEDDING_002
|
|
18
18
|
end
|
|
@@ -20,7 +20,7 @@ module OmniAI
|
|
|
20
20
|
DEFAULT_MODEL = Model::EMBEDDING
|
|
21
21
|
|
|
22
22
|
EMBEDDINGS_DESERIALIZER = proc do |data, *|
|
|
23
|
-
data[
|
|
23
|
+
data["embeddings"].map { |embedding| embedding["values"] }
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
# @return [Context]
|
|
@@ -28,7 +28,7 @@ module OmniAI
|
|
|
28
28
|
context.deserializers[:embeddings] = EMBEDDINGS_DESERIALIZER
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
protected
|
|
32
32
|
|
|
33
33
|
# @param response [HTTP::Response]
|
|
34
34
|
# @return [Response]
|
|
@@ -30,10 +30,10 @@ module OmniAI
|
|
|
30
30
|
def self.parse(client:, data:)
|
|
31
31
|
new(
|
|
32
32
|
client: client,
|
|
33
|
-
name: data[
|
|
34
|
-
uri: data[
|
|
35
|
-
state: data[
|
|
36
|
-
mime_type: data[
|
|
33
|
+
name: data["name"],
|
|
34
|
+
uri: data["uri"],
|
|
35
|
+
state: data["state"],
|
|
36
|
+
mime_type: data["mimeType"]
|
|
37
37
|
)
|
|
38
38
|
end
|
|
39
39
|
|
data/lib/omniai/google/upload.rb
CHANGED
|
@@ -8,14 +8,12 @@ module OmniAI
|
|
|
8
8
|
|
|
9
9
|
# @param client [Client]
|
|
10
10
|
# @param io [IO]
|
|
11
|
-
# @param mime_type [String]
|
|
12
11
|
def self.process!(client:, io:)
|
|
13
12
|
new(client:, io:).process!
|
|
14
13
|
end
|
|
15
14
|
|
|
16
15
|
# @param client [Client]
|
|
17
|
-
# @param
|
|
18
|
-
# @param mime_type [String]
|
|
16
|
+
# @param io [File]
|
|
19
17
|
def initialize(client:, io:)
|
|
20
18
|
@client = client
|
|
21
19
|
@io = io
|
|
@@ -28,16 +26,16 @@ module OmniAI
|
|
|
28
26
|
response = io! do |io|
|
|
29
27
|
response = @client
|
|
30
28
|
.connection
|
|
31
|
-
.headers({
|
|
29
|
+
.headers({ "X-Goog-Upload-Protocol" => "raw" })
|
|
32
30
|
.post("/upload/#{@client.version}/files?key=#{@client.api_key}", body: HTTP::FormData::File.new(io))
|
|
33
31
|
end
|
|
34
32
|
|
|
35
33
|
raise OmniAI::HTTPError, response.flush unless response.status.ok?
|
|
36
34
|
|
|
37
|
-
File.parse(client: @client, data: response.parse[
|
|
35
|
+
File.parse(client: @client, data: response.parse["file"])
|
|
38
36
|
end
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
protected
|
|
41
39
|
|
|
42
40
|
# @raise [FetchError]
|
|
43
41
|
#
|
data/lib/omniai/google.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: omniai-google
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.9.
|
|
4
|
+
version: 1.9.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kevin Sylvestre
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2025-02-05 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: event_stream_parser
|
|
@@ -87,7 +86,6 @@ metadata:
|
|
|
87
86
|
homepage_uri: https://github.com/ksylvest/omniai-google
|
|
88
87
|
changelog_uri: https://github.com/ksylvest/omniai-google/releases
|
|
89
88
|
rubygems_mfa_required: 'true'
|
|
90
|
-
post_install_message:
|
|
91
89
|
rdoc_options: []
|
|
92
90
|
require_paths:
|
|
93
91
|
- lib
|
|
@@ -102,8 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
102
100
|
- !ruby/object:Gem::Version
|
|
103
101
|
version: '0'
|
|
104
102
|
requirements: []
|
|
105
|
-
rubygems_version: 3.
|
|
106
|
-
signing_key:
|
|
103
|
+
rubygems_version: 3.6.2
|
|
107
104
|
specification_version: 4
|
|
108
105
|
summary: A generalized framework for interacting with Google
|
|
109
106
|
test_files: []
|