intelli_agent 0.2.13 → 0.2.15

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: c91be5552b13825b657164e1ac9836e88fbdd98e99930ba7aececb54cb6e273a
4
- data.tar.gz: f80215a13d785d1d50f835148be4f842a6c058f9f8445b94928feeb4f64b6e01
3
+ metadata.gz: 4d6276a8e024459b249c86faebc914d7a3a54fd0c13ff1e13cad85c32cb155b7
4
+ data.tar.gz: 9f4973740258dea719fb5133ab4670e274247c0bc3ef8d6457f651193477761e
5
5
  SHA512:
6
- metadata.gz: 184e9e14319cfa84487eb3919ffb0b27a1f1b273464fd9410992d1c0467bbfbf2f68eabf7e31e3002f26feecd5107d37cae2acbfafdf7a3473ec1a0076a1699a
7
- data.tar.gz: 8a3facc0c1bc891a457573e20b4581422565dd970cf666e1a848e46e226b5fd7203130e2740859c2c6393ef3826314ff914bfab0811c79af9845ed5192359ad9
6
+ metadata.gz: 0c660848db3259c3082b2c2430d96763499d6f35d1a921ad85f664b494fff3fe0a8470c286a1e83a00c6c1b5709873fe41442d0f657c6ca71c23d4e53d7de7ad
7
+ data.tar.gz: 7f6610170d835b4bc04b79ef1b1a95008f39f510594f1a78d65caa18c20c6ce487ff9e6f0f31977c270874071fe19341b88979505a8ff30763ef0b69c62e0f96
@@ -1,5 +1,4 @@
1
1
  class IntelliAgent::OpenAI::Messages < Array
2
- # VALID_ROLES = %i[system user assistant function tool].freeze
3
2
 
4
3
  def initialize messages = nil
5
4
  super parse_messages(messages)
@@ -22,6 +21,9 @@ Important note: the content can be either a string or an array.
22
21
  return [] if messages.nil?
23
22
 
24
23
  messages = [messages] unless messages.is_a?(Array)
24
+
25
+ # if first element is ok, then do not parse the rest
26
+ return messages if messages.first in { role: String | Symbol, content: String | Array | Hash}
25
27
 
26
28
  messages.flat_map do |msg|
27
29
  if msg.is_a?(Hash)
@@ -80,7 +80,6 @@ module IntelliAgent::OpenAI
80
80
  parameters = { model:, messages:, store: }
81
81
  parameters[:metadata] = metadata if metadata
82
82
 
83
-
84
83
  # o1 family models doesn't support max_tokens params. Instead, use max_completion_tokens
85
84
  parameters[:max_completion_tokens] = max_tokens if is_o1_model
86
85
  parameters[:max_tokens] = max_tokens unless is_o1_model
@@ -88,7 +87,11 @@ module IntelliAgent::OpenAI
88
87
  parameters[:response_format] = { type: 'json_object' } if response_format.eql?(:json)
89
88
  parameters[:tools] = tools if tools
90
89
 
91
- response = OpenAI::Client.new.chat(parameters:)
90
+ begin
91
+ response = OpenAI::Client.new.chat(parameters:)
92
+ rescue => e
93
+ raise "Error in OpenAI chat: #{e.message}\nParameters: #{parameters.inspect}"
94
+ end
92
95
 
93
96
  response[:chat_params] = parameters
94
97
  response.extend(ResponseExtender)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intelli_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.13
4
+ version: 0.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gedean Dias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-11 00:00:00.000000000 Z
11
+ date: 2024-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-openai
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '7.2'
19
+ version: '7.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '7.2'
26
+ version: '7.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: anthropic
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,6 @@ files:
66
66
  - lib/intelli_agent/anthropic.rb
67
67
  - lib/intelli_agent/openai.rb
68
68
  - lib/intelli_agent/openai/messages.rb
69
- - lib/intelli_agent/openai/messages_helper copy.rb
70
69
  homepage: https://github.com/gedean/intelli_agent
71
70
  licenses:
72
71
  - MIT
@@ -1,40 +0,0 @@
1
- class IntelliAgent::OpenAI::Messages < Array
2
- VALID_ROLES = %i[system user assistant tool].freeze
3
-
4
- def initialize(messages = [])
5
- @messages = self.class.parse_messages(messages)
6
- end
7
-
8
- def add(message) = @messages.concat(self.class.parse_messages(message))
9
-
10
- =begin
11
- O Formato de saída deve ser um array de hashes com as chaves `role` e `content`.
12
-
13
- A entrada pode ser:
14
- - um hash simples { user: 'mensagem do usuário' }, deve ser transformado em { role: 'user', content: 'mensagem do usuário' }
15
- - um hash com várias chaves {system: 'mensagem', user: 'mensagem do usuário' }, deve ser transformado em [{ role: 'system', content: 'mensagem'}, { role: 'user', content: 'mensagem do usuário' }]
16
- - um array de hashes [{ system: 'mensagem'}, { user: 'mensagem do usuário' }], deve ser transformado em [{ role: 'system', content: 'mensagem'}, { role: 'user', content: 'mensagem do usuário' }]
17
- Obervação imporante: o content pode ser uma string ou um array
18
- =end
19
-
20
- def self.parse_messages(messages)
21
- return [] if messages.empty?
22
-
23
- messages = [messages] unless messages.is_a?(Array)
24
-
25
- messages.flat_map do |msg|
26
- if msg.is_a?(Hash)
27
- if msg.keys.size == 1
28
- role, content = msg.first
29
- { role: role.to_s, content: content }
30
- elsif msg.key?(:role) && msg.key?(:content)
31
- { role: msg[:role].to_s, content: msg[:content] }
32
- else
33
- msg.map { |role, content| { role: role.to_s, content: content } }
34
- end
35
- else
36
- raise ArgumentError, "Invalid message format: #{msg}"
37
- end
38
- end
39
- end
40
- end