Class: LLM::Clients::OpenAI::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/clients/open_ai/response.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ Response

Returns a new instance of Response.



7
8
9
# File 'lib/llm/clients/open_ai/response.rb', line 7

def initialize(raw_response)
  @raw_response = raw_response
end

Class Method Details

.normalize_stop_reason(stop_reason) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/llm/clients/open_ai/response.rb', line 20

def self.normalize_stop_reason(stop_reason)
  case stop_reason
  when "stop"
    LLM::StopReason::STOP
  when "safety"
    LLM::StopReason::SAFETY
  when "max_tokens"
    LLM::StopReason::MAX_TOKENS_REACHED
  else
    LLM::StopReason::OTHER
  end
end

Instance Method Details

#to_normalized_responseObject



11
12
13
14
15
16
17
18
# File 'lib/llm/clients/open_ai/response.rb', line 11

def to_normalized_response
  LLM::Response.new(
    content: content,
    raw_response: parsed_response,
    stop_reason: normalize_stop_reason,
    structured_output: structured_output
  )
end