intelli_agent 0.2.3 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/intelli_agent/openai.rb +12 -24
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b165ba2e8f4c70fc7b6719f1761e89a44c7646d9018ad55142d0b9ff39c167a
4
- data.tar.gz: d618dd1fe8e8cdcacab135f2a59a59aa823875e9e30ec39d4dce3649b962a5af
3
+ metadata.gz: dbcf865d2efd8e333b82c32d8f90d7537a6175520d25c1da6d4596f28ae0d5b5
4
+ data.tar.gz: b135ada1b6204ef416763c4bfdbc6a1e837a1c06bdd0ae97bc42b90562c46055
5
5
  SHA512:
6
- metadata.gz: c72e622cbba6b3302096f4f32522173b29e0bf7c8921fc75fd6bfb8f231b2bd804c2421f128a605381b7b94d7c43c241b2cfd20b32b86281673623af5fc5dae9
7
- data.tar.gz: 3e74939dc68fa5bc007c3a785b327fcffbda1e71efb0fdaaae6fe82b594b5e15a6756a7418764d7ab4e690b0f218d8f8417ae01c1ade8738291495ba7a2234bb
6
+ metadata.gz: 19d6ef84e6d8071daa0e041666fd8c9b80462dc9c1b48cecfc39d26384741156d8bd16be8ed7068d0d400bfaa4c67f396bcec34985d3296ac6b8516c5c770025
7
+ data.tar.gz: 847d5813d222b4b01bb8697040b88e7fa18ef9a02b479dfbf4b4dd86a8a22ef84c32f6358c078551f84fb6c3d6993157983660e3731b25f96122b292a1d3a5ad
@@ -4,25 +4,13 @@ module IntelliAgent::OpenAI
4
4
  MAX_TOKENS = ENV.fetch('OPENAI_MAX_TOKENS', 16_383).to_i
5
5
 
6
6
  module ResponseExtender
7
- def content
8
- dig('choices', 0, 'message', 'content')
9
- end
7
+ def message = dig('choices', 0, 'message')
10
8
 
11
- def message
12
- dig('choices', 0, 'message')
13
- end
9
+ def content = dig('choices', 0, 'message', 'content')
10
+ def content? = !content.nil?
14
11
 
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
12
+ def tool_calls = dig('choices', 0, 'message', 'tool_calls')
13
+ def tool_calls? = !tool_calls.nil?
26
14
 
27
15
  def functions
28
16
  return if tool_calls.nil?
@@ -39,12 +27,10 @@ module IntelliAgent::OpenAI
39
27
  functions_list
40
28
  end
41
29
 
42
- def functions?
43
- !functions.nil?
44
- end
30
+ def functions? = !functions.nil?
45
31
  end
46
32
 
47
- def self.embed(input, model: 'text-embedding-3-large')
33
+ def self.embeddings(input, model: 'text-embedding-3-large')
48
34
  response = OpenAI::Client.new.embeddings(parameters: { input:, model: })
49
35
  def response.embedding = dig('data', 0, 'embedding')
50
36
  response
@@ -69,7 +55,7 @@ module IntelliAgent::OpenAI
69
55
  chat(messages: [{ user: prompt }], model:, response_format:, max_tokens:, tools:, function_run_context:)
70
56
  end
71
57
 
72
- def self.single_chat(system:, user:, model: :basic, response_format: nil, max_tokens: MAX_TOKENS, tools: nil, function_run_context: self)
58
+ def self.single_chat(system:, user:, model: :basic, response_format: nil, max_tokens: MAX_TOKENS, tools: nil, function_run_context: nil)
73
59
  chat(messages: [{ system: }, { user: }], model:, response_format:, max_tokens:, tools:, function_run_context:)
74
60
  end
75
61
 
@@ -85,6 +71,8 @@ module IntelliAgent::OpenAI
85
71
  response.extend(ResponseExtender)
86
72
 
87
73
  if response.functions?
74
+ raise 'Function run context not provided' if function_run_context.nil?
75
+
88
76
  parameters[:messages] << response.message
89
77
 
90
78
  response.functions.each do |function|
@@ -92,7 +80,7 @@ module IntelliAgent::OpenAI
92
80
  tool_call_id: function[:id],
93
81
  role: :tool,
94
82
  name: function[:name],
95
- content: parameters[:function_run_context].send(function[:name], **function[:arguments])
83
+ content: function_run_context.send(function[:name], **function[:arguments])
96
84
  }
97
85
  end
98
86
 
@@ -127,4 +115,4 @@ module IntelliAgent::OpenAI
127
115
  end
128
116
  end
129
117
  end
130
- end
118
+ end
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.3
4
+ version: 0.2.5
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-22 00:00:00.000000000 Z
11
+ date: 2027-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-openai