intelli_agent 0.2.2 → 0.2.3

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: a70f9043e7c97455596b720e803c7ae02274c8bf8e63eff090cf813327e256d7
4
- data.tar.gz: b0e4e27b5ea461dbf87e8b7fa551b85de2258f3ffcb56c8fb98ba32d74d6a3a7
3
+ metadata.gz: 8b165ba2e8f4c70fc7b6719f1761e89a44c7646d9018ad55142d0b9ff39c167a
4
+ data.tar.gz: d618dd1fe8e8cdcacab135f2a59a59aa823875e9e30ec39d4dce3649b962a5af
5
5
  SHA512:
6
- metadata.gz: 8792b7a3c0fddbbf7969f9d45a3f1a171613ad4f6f5331f88c0e43aa0adbd2c58ea4c7ad563dcd6eff6e5d00f4a4fda33cfaf8568efaacaff7fe242970c8464b
7
- data.tar.gz: 7e60f9ddb4c80bfdd642330f1e066e641023f206f72302d9cc07cc27c4e70e4d353030d24600831dae1f97ec7edfd913ba6e37c5e53360c122492d658a4228e0
6
+ metadata.gz: c72e622cbba6b3302096f4f32522173b29e0bf7c8921fc75fd6bfb8f231b2bd804c2421f128a605381b7b94d7c43c241b2cfd20b32b86281673623af5fc5dae9
7
+ data.tar.gz: 3e74939dc68fa5bc007c3a785b327fcffbda1e71efb0fdaaae6fe82b594b5e15a6756a7418764d7ab4e690b0f218d8f8417ae01c1ade8738291495ba7a2234bb
@@ -46,7 +46,8 @@ module IntelliAgent::OpenAI
46
46
 
47
47
  def self.embed(input, model: 'text-embedding-3-large')
48
48
  response = OpenAI::Client.new.embeddings(parameters: { input:, model: })
49
- response.dig('data', 0, 'embedding')
49
+ def response.embedding = dig('data', 0, 'embedding')
50
+ response
50
51
  end
51
52
 
52
53
  def self.vision(prompt:, image_url:, model: :advanced, response_format: nil, max_tokens: MAX_TOKENS)
@@ -59,7 +60,9 @@ module IntelliAgent::OpenAI
59
60
 
60
61
  response = OpenAI::Client.new.chat(parameters:)
61
62
 
62
- response.dig('choices', 0, 'message', 'content').strip
63
+ def response.content = dig('choices', 0, 'message', 'content').strip
64
+
65
+ response
63
66
  end
64
67
 
65
68
  def self.single_prompt(prompt:, model: :basic, response_format: nil, max_tokens: MAX_TOKENS, tools: nil, function_run_context: self)
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.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gedean Dias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2027-09-21 00:00:00.000000000 Z
11
+ date: 2027-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-openai
@@ -63,7 +63,6 @@ files:
63
63
  - lib/intelli_agent/agent.rb.disabled
64
64
  - lib/intelli_agent/agent_test.rb_
65
65
  - lib/intelli_agent/anthropic.rb
66
- - lib/intelli_agent/openai.bkp.rb
67
66
  - lib/intelli_agent/openai.rb
68
67
  homepage: https://github.com/gedean/intelli_agent
69
68
  licenses:
@@ -1,145 +0,0 @@
1
- module IntelliAgent::OpenAI
2
- BASIC_MODEL = ENV.fetch('OPENAI_BASIC_MODEL', 'gpt-4o-mini')
3
- ADVANCED_MODEL = ENV.fetch('OPENAI_ADVANCED_MODEL', 'gpt-4o-2024-08-06')
4
- MAX_TOKENS = ENV.fetch('OPENAI_MAX_TOKENS', 16_383).to_i
5
-
6
- module ResponseExtender
7
- def content
8
- dig('choices', 0, 'message', 'content')
9
- end
10
-
11
- def message
12
- dig('choices', 0, 'message')
13
- end
14
-
15
- def content?
16
- !content.nil?
17
- end
18
-
19
- def tool_calls
20
- dig('choices', 0, 'message', 'tool_calls')
21
- end
22
-
23
- def tool_calls?
24
- !tool_calls.nil?
25
- end
26
-
27
- def functions
28
- return if tool_calls.nil?
29
-
30
- functions = tool_calls.filter { |tool| tool['type'].eql? 'function' }
31
- return if functions.empty?
32
-
33
- functions_list = []
34
- functions.map.with_index do |function, function_index|
35
- function_def = tool_calls.dig(function_index, 'function')
36
- functions_list << { id: function['id'], name: function_def['name'], arguments: Oj.load(function_def['arguments'], symbol_keys: true) }
37
- end
38
-
39
- functions_list
40
- end
41
-
42
- def functions?
43
- !functions.nil?
44
- end
45
- end
46
-
47
- def self.embed(input, model: 'text-embedding-3-large')
48
- response = OpenAI::Client.new.embeddings(parameters: { input:, model: })
49
- response.dig('data', 0, 'embedding')
50
- end
51
-
52
- def self.vision(prompt:, image_url:, model: :advanced, response_format: nil, max_tokens: MAX_TOKENS)
53
- model = select_model(model)
54
- messages = [{ type: :text, text: prompt },
55
- { type: :image_url, image_url: { url: image_url } }]
56
-
57
- parameters = { model: model, messages: [{ role: :user, content: messages }], max_tokens: }
58
- parameters[:response_format] = { type: 'json_object' } if response_format.eql?(:json)
59
-
60
- response = OpenAI::Client.new.chat(parameters:)
61
-
62
- response.dig('choices', 0, 'message', 'content').strip
63
- end
64
-
65
-
66
-
67
- def self.single_prompt(prompt:, model: :basic, response_format: nil, max_tokens: MAX_TOKENS, tools: nil, function_run_context: self)
68
- model = select_model(model)
69
-
70
- parameters = { model:, messages: [{ role: 'user', content: prompt }], max_tokens: }
71
- parameters[:response_format] = { type: 'json_object' } if response_format.eql?(:json)
72
- parameters[:tools] = tools if tools
73
- banana(parameters:)
74
- end
75
-
76
- def self.single_chat(system:, user:, model: :basic, response_format: nil, max_tokens: MAX_TOKENS, tools: nil, function_run_context: self)
77
- model = select_model(model)
78
- parameters = { model:,
79
- messages: [
80
- { role: 'system', content: system },
81
- { role: 'user', content: user }
82
- ], max_tokens: }
83
-
84
- parameters[:response_format] = { type: 'json_object' } if response_format.eql?(:json)
85
- parameters[:tools] = tools if tools
86
-
87
- banana(parameters:)
88
- end
89
-
90
- def self.chat(messages:, model: :basic, response_format: nil, max_tokens: MAX_TOKENS, tools: nil, function_run_context: self)
91
- model = select_model(model)
92
-
93
- messages = parse_messages(messages)
94
-
95
- parameters = { model:, messages:, max_tokens: }
96
- parameters[:response_format] = { type: 'json_object' } if response_format.eql?(:json)
97
- parameters[:tools] = tools if tools
98
-
99
- response = OpenAI::Client.new.chat(parameters:)
100
- response.extend(ResponseExtender)
101
-
102
- if response.functions?
103
- parameters[:messages] << response.message
104
-
105
- response.functions.each do |function|
106
- parameters[:messages] << {
107
- tool_call_id: function[:id],
108
- role: :tool,
109
- name: function[:name],
110
- content: parameters[:function_run_context].send(function[:name], **function[:arguments])
111
- }
112
- end
113
-
114
- response = OpenAI::Client.new.chat(parameters:)
115
- response.extend(ResponseExtender)
116
- end
117
-
118
- response
119
- end
120
-
121
- def self.models = OpenAI::Client.new.models.list
122
-
123
- def self.select_model(model)
124
- case model
125
- when :basic
126
- BASIC_MODEL
127
- when :advanced
128
- ADVANCED_MODEL
129
- else
130
- model
131
- end
132
- end
133
-
134
- def self.parse_messages(messages)
135
- case messages
136
- in [{ role: String, content: String }, *]
137
- messages
138
- else
139
- messages.map do |msg|
140
- role, content = msg.first
141
- { role: role.to_s, content: content }
142
- end
143
- end
144
- end
145
- end