omniai-google 2.3.0 → 2.3.2

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: ef7814ad2fd60f7d89dd87a2350c23496d4846e172393bb0b8fbf3ffde48347f
4
- data.tar.gz: 7ead40b0168c010885d0af4fb8633d5da67ef187508777aa506528a5946bef75
3
+ metadata.gz: 3f36d76cb11dd6560ced4cdc09989f40fe0c0461b27c67caf17a7620990d888d
4
+ data.tar.gz: c08242def01cf99eba317b78310b5cb9f7c88346893d1c929a23d89fb4b32f6d
5
5
  SHA512:
6
- metadata.gz: f49152ce0896a0c4ed9668dcc5f4abce7363d4dfe907fd79a7511363fa5e8b7ec1797d1449653c22fb5dfbb9f49054359d7d57102607ec59699c113975d7fdb4
7
- data.tar.gz: 8a88be48a793faefd52d98928fc57b9b1acdc84e1ad0d82735ca6605e63cfdfb7119c6835dc88c51d323cb4d0155a61d5c49995ae2f7b546b937ab333bb90471
6
+ metadata.gz: a3c01b3dd839b845944621e328c091d132ef104a01d7d4c1c59b6277211a05f7a68156d971ce9d632f08270b0b161bbc54d18ea4430902539c1c880c897bf8e6
7
+ data.tar.gz: 353201b366071ac3d4eac2b96c5c24acb3d5a73b09f04e13e2642e96f8eaec9d4ed8c67f50758dfb117221ea3d54d6478a9d4c7eb4f2360711b84598c53d3db2
@@ -50,7 +50,7 @@ module OmniAI
50
50
 
51
51
  @project_id = project_id
52
52
  @location_id = location_id
53
- @credentials = credentials
53
+ @credentials = Credentials.parse(credentials)
54
54
  @version = version
55
55
  end
56
56
 
@@ -51,7 +51,7 @@ module OmniAI
51
51
  Credentials.detect
52
52
  end
53
53
 
54
- # @param value [String, File, Google::Auth::ServiceAccountCredentials, nil]
54
+ # @param value [String, File, Hash, Google::Auth::ServiceAccountCredentials, nil]
55
55
  def credentials=(value)
56
56
  @credentials = Credentials.parse(value)
57
57
  end
@@ -17,14 +17,15 @@ module OmniAI
17
17
  end
18
18
  end
19
19
 
20
- # @param value [Google::Auth::ServiceAccountCredentials, IO, Pathname, String nil]
20
+ # @param value [Google::Auth::ServiceAccountCredentials, IO, Pathname, String, Hash, nil]
21
21
  # @return [Google::Auth::ServiceAccountCredentials]
22
22
  def self.parse(value)
23
23
  case value
24
- when ::Google::Auth::ServiceAccountCredentials then value
25
24
  when IO, StringIO then ::Google::Auth::ServiceAccountCredentials.make_creds(json_key_io: value, scope: SCOPE)
25
+ when Hash then parse(JSON.generate(value))
26
26
  when Pathname then parse(File.open(value))
27
27
  when String then parse(StringIO.new(value))
28
+ else value
28
29
  end
29
30
  end
30
31
  end
@@ -28,6 +28,12 @@ module OmniAI
28
28
  data["predictions"].map { |prediction| prediction["embeddings"]["values"] }
29
29
  end
30
30
 
31
+ VERTEX_USAGE_DESERIALIZER = proc do |data, *|
32
+ tokens = data["predictions"].map { |prediction| prediction["embeddings"]["statistics"]["token_count"] }.sum
33
+
34
+ Usage.new(prompt_tokens: tokens, total_tokens: tokens)
35
+ end
36
+
31
37
  # @return [Context]
32
38
  DEFAULT_CONTEXT = Context.build do |context|
33
39
  context.deserializers[:embeddings] = DEFAULT_EMBEDDINGS_DESERIALIZER
@@ -36,6 +42,7 @@ module OmniAI
36
42
  # @return [Context]
37
43
  VERTEX_CONTEXT = Context.build do |context|
38
44
  context.deserializers[:embeddings] = VERTEX_EMBEDDINGS_DESERIALIZER
45
+ context.deserializers[:usage] = VERTEX_USAGE_DESERIALIZER
39
46
  end
40
47
 
41
48
  protected
@@ -50,12 +57,6 @@ module OmniAI
50
57
  vertex? ? VERTEX_CONTEXT : DEFAULT_CONTEXT
51
58
  end
52
59
 
53
- # @param response [HTTP::Response]
54
- # @return [Response]
55
- def parse!(response:)
56
- Response.new(data: response.parse, context:)
57
- end
58
-
59
60
  # @return [Array[Hash]]
60
61
  def instances
61
62
  arrayify(@input).map { |content| { content: } }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module Google
5
- VERSION = "2.3.0"
5
+ VERSION = "2.3.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai-google
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre