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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80e08395bc3710a72cc59b7c110cc50b1ba4a1dc64e15c622fcacb39448c1265
4
- data.tar.gz: cccb64b57c0430caf449ebb1de2620e597409de0179379ef0cb26588d41418a2
3
+ metadata.gz: 94943a4eb224e5224148c1109d3a8472d26f40d83684c102cee11f6f46d5ae00
4
+ data.tar.gz: c234428c542e1b507dcf86a80e624eec640173db0604c7e2f10264de569532b4
5
5
  SHA512:
6
- metadata.gz: cf8a4e78c06a9808930300c1aa05b45211ab0f733a79bddc22bd5ac3ca2bfff1a00d075ca596122295c82aeb909372d2a9c7a66bc27566386d529428209beda7
7
- data.tar.gz: 7324a4d99c3ce3a890129eb5a3091459facbd0acf5818b7ff0624d168d2fee94613656db1fe1c1091f8f001c6c34cc34c66a835b69fb7d90191075bde455de5b
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 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
- gem 'logger'
8
- gem 'rake'
9
- gem 'rspec'
10
- gem 'rspec_junit_formatter'
11
- gem 'rubocop'
12
- gem 'rubocop-rake'
13
- gem 'rubocop-rspec'
14
- gem 'simplecov'
15
- gem 'webmock'
16
- gem 'yard'
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['content'], context:)
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['text'] then data['text']
14
- when data['functionCall'] then OmniAI::Chat::ToolCall.deserialize(data, context:)
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['name']
21
- arguments = data['args']
20
+ name = data["name"]
21
+ arguments = data["args"]
22
22
  OmniAI::Chat::Function.new(name:, arguments:)
23
23
  end
24
24
  end
@@ -44,7 +44,7 @@ module OmniAI
44
44
  #
45
45
  # @return [Boolean]
46
46
  def self.use_file_data?(uri)
47
- uri.host.eql?('generativelanguage.googleapis.com') || uri.scheme.eql?('gs')
47
+ uri.host.eql?("generativelanguage.googleapis.com") || uri.scheme.eql?("gs")
48
48
  end
49
49
  end
50
50
  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['role']
28
- parts = arrayify(data['parts']).map do |part|
27
+ role = data["role"]
28
+ parts = arrayify(data["parts"]).map do |part|
29
29
  case
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:)
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['candidates'].map { |candidate| OmniAI::Chat::Choice.deserialize(candidate, context:) }
26
- usage = OmniAI::Chat::Usage.deserialize(data['usageMetadata'], context:) if data['usageMetadata']
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
@@ -14,7 +14,7 @@ module OmniAI
14
14
  # @param data [Hash]
15
15
  # @return [OmniAI::Chat::Text]
16
16
  def self.deserialize(data, *)
17
- OmniAI::Chat::Text.new(data['text'])
17
+ OmniAI::Chat::Text.new(data["text"])
18
18
  end
19
19
  end
20
20
  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['functionResponse']['name']
26
- content = data['functionResponse']['response']['content']
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['functionCall'], context:)
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['promptTokenCount']
22
- output_tokens = data['candidatesTokenCount']
23
- total_tokens = data['totalTokenCount']
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
@@ -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 = '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'
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 = GEMINI_1_5_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 = 'application/json'
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
- protected
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: ('sse' if @stream),
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 ? 'streamGenerateContent' : 'generateContent'
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: 'function', content:)]
133
+ [Message.new(role: "function", content:)]
136
134
  end
137
135
  end
138
136
  end
@@ -5,11 +5,11 @@ module OmniAI
5
5
  # Configuration for Google.
6
6
  class Config < OmniAI::Config
7
7
  module Version
8
- STABLE = 'v1'
9
- BETA = 'v1beta'
8
+ STABLE = "v1"
9
+ BETA = "v1beta"
10
10
  end
11
11
 
12
- DEFAULT_HOST = 'https://generativelanguage.googleapis.com'
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('GOOGLE_API_KEY', nil),
26
- host: ENV.fetch('GOOGLE_HOST', DEFAULT_HOST),
27
- version: ENV.fetch('GOOGLE_VERSION', DEFAULT_VERSION),
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
  )
@@ -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 = 'text-embedding-004'
15
- TEXT_MULTILINGUAL_EMBEDDING_002 = '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['embeddings'].map { |embedding| embedding['values'] }
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
- protected
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['name'],
34
- uri: data['uri'],
35
- state: data['state'],
36
- mime_type: data['mimeType']
33
+ name: data["name"],
34
+ uri: data["uri"],
35
+ state: data["state"],
36
+ mime_type: data["mimeType"]
37
37
  )
38
38
  end
39
39
 
@@ -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 file [File]
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({ 'X-Goog-Upload-Protocol' => 'raw' })
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['file'])
35
+ File.parse(client: @client, data: response.parse["file"])
38
36
  end
39
37
 
40
- protected
38
+ protected
41
39
 
42
40
  # @raise [FetchError]
43
41
  #
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module Google
5
- VERSION = '1.9.3'
5
+ VERSION = "1.9.6"
6
6
  end
7
7
  end
data/lib/omniai/google.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'event_stream_parser'
4
- require 'omniai'
5
- require 'zeitwerk'
3
+ require "event_stream_parser"
4
+ require "omniai"
5
+ require "zeitwerk"
6
6
 
7
7
  loader = Zeitwerk::Loader.for_gem
8
8
  loader.push_dir(__dir__, namespace: OmniAI)
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.3
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: 2024-11-13 00:00:00.000000000 Z
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.5.14
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: []