Class: OmniAI::Chat::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/omniai/chat/response.rb

Overview

Used when processing everything at once.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, context: nil) ⇒ Response

Returns a new instance of Response.

Parameters:

  • data (Hash)
  • context (Context, nil) (defaults to: nil)


12
13
14
15
# File 'lib/omniai/chat/response.rb', line 12

def initialize(data:, context: nil)
  @data = data
  @context = context
end

Instance Attribute Details

#dataHash

Returns:

  • (Hash)


8
9
10
# File 'lib/omniai/chat/response.rb', line 8

def data
  @data
end

Instance Method Details

#choice(index: 0) ⇒ Choice

Parameters:

  • index (Integer) (defaults to: 0)

Returns:



39
40
41
# File 'lib/omniai/chat/response.rb', line 39

def choice(index: 0)
  completion.choice(index:)
end

#choicesArray<Choice>

Returns:



28
29
30
# File 'lib/omniai/chat/response.rb', line 28

def choices
  completion.choices
end

#completionPayload

Returns:



18
19
20
# File 'lib/omniai/chat/response.rb', line 18

def completion
  @completion ||= Payload.deserialize(@data, context: @context)
end

#message(index: 0) ⇒ Message

Parameters:

  • index (Integer) (defaults to: 0)

Returns:



45
46
47
# File 'lib/omniai/chat/response.rb', line 45

def message(index: 0)
  completion.message(index:)
end

#messagesArray<Message>

Returns:



33
34
35
# File 'lib/omniai/chat/response.rb', line 33

def messages
  completion.messages
end

#textString

Returns:

  • (String)


50
51
52
# File 'lib/omniai/chat/response.rb', line 50

def text
  message.text
end

#text?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/omniai/chat/response.rb', line 55

def text?
  message.text?
end

#tool_call_listArray<ToolCall>

Returns:



60
61
62
# File 'lib/omniai/chat/response.rb', line 60

def tool_call_list
  choice.tool_call_list
end

#tool_call_list?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/omniai/chat/response.rb', line 65

def tool_call_list?
  tool_call_list&.any?
end

#usageUsage?

Returns:



23
24
25
# File 'lib/omniai/chat/response.rb', line 23

def usage
  completion.usage
end