omniai-google 1.9.3 → 1.9.5

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: fb82538924ecdd019097f464a0ff96e0afb7b813dc7073eb4c57d7e6bc76f8c8
4
+ data.tar.gz: 90c7e6a988cad6af59c23e41aa44bd2a39d12d9d647a2f69c980cd60dacaae25
5
5
  SHA512:
6
- metadata.gz: cf8a4e78c06a9808930300c1aa05b45211ab0f733a79bddc22bd5ac3ca2bfff1a00d075ca596122295c82aeb909372d2a9c7a66bc27566386d529428209beda7
7
- data.tar.gz: 7324a4d99c3ce3a890129eb5a3091459facbd0acf5818b7ff0624d168d2fee94613656db1fe1c1091f8f001c6c34cc34c66a835b69fb7d90191075bde455de5b
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 '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 "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['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,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 = '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_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 = 'application/json'
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
- protected
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: ('sse' if @stream),
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 ? 'streamGenerateContent' : 'generateContent'
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: 'function', content:)]
135
+ [Message.new(role: "function", content:)]
136
136
  end
137
137
  end
138
138
  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.5"
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.5
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-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.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: []