omniai-google 1.5.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5654724585620a00d0254e9eb55a80eccae2bc0d58e13bd44cc10d4ccfd3abd4
4
- data.tar.gz: 3253d076f87054ed57ae84279f83b8dcb06493b504ffecf4fde5ba9d2d0150e0
3
+ metadata.gz: 76a81bb43234ee957a4eeaad25a4aada75d776d2f2a510c65fbabed5ecb41954
4
+ data.tar.gz: 21dafc2e2b81cfa2dce6e74ce8a093812a0299cde5837ac8425c5ef46020aa45
5
5
  SHA512:
6
- metadata.gz: 28b889a214a03e16478a0ad57856e53faabc28e007b75c165723136110aba6dcca2ffb3ba31a4244b4294922a44e14639d570d2a011131ec8a2a4df0fc923a6e
7
- data.tar.gz: 0ac2802328f1acda7739039f9365fd2eaecd78a11255dee060b853481c7e85e517060080dfcfbf943eb4088bd92efed9a5252d17d8f54750f80e6189106d4abd
6
+ metadata.gz: 3c3595de2ad04e982aa0f7ca062db4ccf9f7bf500ba05edaad988e9b3379c5183a585ab877eba3c150794584007a9caae9ed279300ace51f71a7f223fe32ec5c
7
+ data.tar.gz: 2b4046f363a0f8ccd4817f6266e92db2a86e43b93c9622710dab614e7413a02ec4f8c29eeefd905f1cac77fd2e48f2368fcd8389a7a2daa0aaf77490a2688047
@@ -23,6 +23,46 @@ module OmniAI
23
23
  GEMINI_FLASH = GEMINI_1_5_FLASH
24
24
  end
25
25
 
26
+ TEXT_SERIALIZER = lambda do |content, *|
27
+ { text: content.text }
28
+ end
29
+
30
+ # @param [Message]
31
+ # @return [Hash]
32
+ # @example
33
+ # message = Message.new(...)
34
+ # MESSAGE_SERIALIZER.call(message)
35
+ MESSAGE_SERIALIZER = lambda do |message, context:|
36
+ parts = message.content.is_a?(String) ? [Text.new(message.content)] : message.content
37
+
38
+ {
39
+ role: message.role,
40
+ parts: parts.map { |part| part.serialize(context:) },
41
+ }
42
+ end
43
+
44
+ # @param [Media]
45
+ # @return [Hash]
46
+ # @example
47
+ # media = Media.new(...)
48
+ # MEDIA_SERIALIZER.call(media)
49
+ MEDIA_SERIALIZER = lambda do |media, *|
50
+ {
51
+ inlineData: {
52
+ mimeType: media.type,
53
+ data: media.data,
54
+ },
55
+ }
56
+ end
57
+
58
+ # @return [Context]
59
+ CONTEXT = Context.build do |context|
60
+ context.serializers[:message] = MESSAGE_SERIALIZER
61
+ context.serializers[:text] = TEXT_SERIALIZER
62
+ context.serializers[:file] = MEDIA_SERIALIZER
63
+ context.serializers[:url] = MEDIA_SERIALIZER
64
+ end
65
+
26
66
  protected
27
67
 
28
68
  # @return [HTTP::Response]
@@ -67,9 +107,7 @@ module OmniAI
67
107
  #
68
108
  # @return [Array<Hash>]
69
109
  def contents
70
- messages.map do |message|
71
- { role: message[:role], parts: [{ text: message[:content] }] }
72
- end
110
+ @prompt.serialize(context: CONTEXT)
73
111
  end
74
112
 
75
113
  # @return [String]
@@ -52,9 +52,12 @@ module OmniAI
52
52
  # @param stream [Proc, nil] optional
53
53
  # @param tools [Array<OmniAI::Chat::Tool>, nil] optional
54
54
  #
55
+ # @yield [prompt] optional
56
+ # @yieldparam prompt [OmniAI::Chat::Prompt]
57
+ #
55
58
  # @return [OmniAI::Chat::Completion]
56
- def chat(messages, model: Chat::Model::GEMINI_PRO, temperature: nil, format: nil, stream: nil, tools: nil)
57
- Chat.process!(messages, model:, temperature:, format:, stream:, tools:, client: self)
59
+ def chat(messages, model: Chat::Model::GEMINI_PRO, temperature: nil, format: nil, stream: nil, tools: nil, &)
60
+ Chat.process!(messages, model:, temperature:, format:, stream:, tools:, client: self, &)
58
61
  end
59
62
  end
60
63
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module Google
5
- VERSION = '1.5.0'
5
+ VERSION = '1.6.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai-google
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-15 00:00:00.000000000 Z
11
+ date: 2024-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_stream_parser