Module: IntelliAgent::OpenAI::ResponseExtender

Defined in:
lib/intelli_agent/openai.rb

Instance Method Summary collapse

Instance Method Details

#chat_paramsObject



11
# File 'lib/intelli_agent/openai.rb', line 11

def chat_params = self[:chat_params]

#contentObject



15
# File 'lib/intelli_agent/openai.rb', line 15

def content = dig('choices', 0, 'message', 'content')

#content?Boolean

Returns:

  • (Boolean)


16
# File 'lib/intelli_agent/openai.rb', line 16

def content? = !content.nil?

#functionsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/intelli_agent/openai.rb', line 21

def functions
  return if tool_calls.nil?
  
  functions = tool_calls.filter { |tool| tool['type'].eql? 'function' }
  return if functions.empty?
  
  functions_list = []
  functions.map.with_index do |function, function_index|
    function_info = tool_calls.dig(function_index, 'function')
    function_def = { id: function['id'], name: function_info['name'], arguments: Oj.load(function_info['arguments'], symbol_keys: true) }
    
    def function_def.run(context:)
      {
        tool_call_id: self[:id],
        role: :tool,
        name: self[:name],
        content: context.send(self[:name], **self[:arguments])
      }
    end

    functions_list << function_def
  end

  functions_list
end

#functions?Boolean

Returns:

  • (Boolean)


52
# File 'lib/intelli_agent/openai.rb', line 52

def functions? = !functions.nil?

#functions_run_all(context:) ⇒ Object



47
48
49
50
# File 'lib/intelli_agent/openai.rb', line 47

def functions_run_all(context:)
  raise 'No functions to run' if functions.nil?
  functions.map { |function| function.run(context:) }
end

#messageObject



13
# File 'lib/intelli_agent/openai.rb', line 13

def message = dig('choices', 0, 'message')

#tool_callsObject



18
# File 'lib/intelli_agent/openai.rb', line 18

def tool_calls = dig('choices', 0, 'message', 'tool_calls')

#tool_calls?Boolean

Returns:

  • (Boolean)


19
# File 'lib/intelli_agent/openai.rb', line 19

def tool_calls? = !tool_calls.nil?