omniai-google 1.9.3 → 1.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +12 -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 +11 -11
- 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: fb82538924ecdd019097f464a0ff96e0afb7b813dc7073eb4c57d7e6bc76f8c8
|
4
|
+
data.tar.gz: 90c7e6a988cad6af59c23e41aa44bd2a39d12d9d647a2f69c980cd60dacaae25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 137a19a3afb8bcd01c6aab23956ebe8f10be958bd9b5dc7418fc8c4fdf495d5aaab86457221cdce091986a2ed9abec8a4117e360b5a68e6d8b95563bd29daa4e
|
7
|
+
data.tar.gz: 59bff744b639b7203f34d8950a56b289d0d2c7784ccf81d34f9e145195837a5651aa0152b65ae1ed0f51490edf60106b5134a3373744a9a3a277b9ce53942e18
|
data/Gemfile
CHANGED
@@ -1,16 +1,17 @@
|
|
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 "logger"
|
8
|
+
gem "rake"
|
9
|
+
gem "rspec"
|
10
|
+
gem "rspec_junit_formatter"
|
11
|
+
gem "rubocop"
|
12
|
+
gem "rubocop-basic"
|
13
|
+
gem "rubocop-rake"
|
14
|
+
gem "rubocop-rspec"
|
15
|
+
gem "simplecov"
|
16
|
+
gem "webmock"
|
17
|
+
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,19 @@ 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
|
-
GEMINI_1_0_PRO_LATEST =
|
20
|
-
GEMINI_1_5_PRO_LATEST =
|
21
|
-
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_1_0_PRO_LATEST = "gemini-1.0-pro-latest"
|
20
|
+
GEMINI_1_5_PRO_LATEST = "gemini-1.5-pro-latest"
|
21
|
+
GEMINI_1_5_FLASH_LATEST = "gemini-1.5-flash-latest"
|
22
22
|
GEMINI_PRO = GEMINI_1_5_PRO
|
23
23
|
GEMINI_FLASH = GEMINI_1_5_FLASH
|
24
24
|
end
|
25
25
|
|
26
26
|
DEFAULT_MODEL = Model::GEMINI_PRO
|
27
27
|
|
28
|
-
JSON_MIME_TYPE =
|
28
|
+
JSON_MIME_TYPE = "application/json"
|
29
29
|
|
30
30
|
# @return [Context]
|
31
31
|
CONTEXT = Context.build do |context|
|
@@ -61,7 +61,7 @@ module OmniAI
|
|
61
61
|
context.serializers[:tool] = ToolSerializer.method(:serialize)
|
62
62
|
end
|
63
63
|
|
64
|
-
|
64
|
+
protected
|
65
65
|
|
66
66
|
# @return [Context]
|
67
67
|
def context
|
@@ -75,7 +75,7 @@ module OmniAI
|
|
75
75
|
.accept(:json)
|
76
76
|
.post(path, params: {
|
77
77
|
key: @client.api_key,
|
78
|
-
alt: (
|
78
|
+
alt: ("sse" if @stream),
|
79
79
|
}.compact, json: payload)
|
80
80
|
end
|
81
81
|
|
@@ -123,7 +123,7 @@ module OmniAI
|
|
123
123
|
|
124
124
|
# @return [String]
|
125
125
|
def operation
|
126
|
-
@stream ?
|
126
|
+
@stream ? "streamGenerateContent" : "generateContent"
|
127
127
|
end
|
128
128
|
|
129
129
|
# @return [Array<Message>]
|
@@ -132,7 +132,7 @@ module OmniAI
|
|
132
132
|
ToolCallResult.new(tool_call_id: tool_call.id, content: execute_tool_call(tool_call))
|
133
133
|
end
|
134
134
|
|
135
|
-
[Message.new(role:
|
135
|
+
[Message.new(role: "function", content:)]
|
136
136
|
end
|
137
137
|
end
|
138
138
|
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.5
|
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-01-18 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: []
|