Class: Foobara::Ai::AnswerBot::DomainMappers::OpenAiApi::ChatToGenerateChatCompletion

Inherits:
DomainMapper
  • Object
show all
Defined in:
foobara-ai-1.0.6/src/foobara/ai/answer_bot/domain_mappers/open_ai_api/chat_to_generate_chat_completion.rb

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Method Summary collapse

Methods inherited from DomainMapper

applicable?, applicable_score, #execute, foobara_on_register, from, #from, from_type, install!, map, map!, matches?, to, to_type

Methods included from CommandPatternImplementation

install_state_machine_callback_methods

Methods included from TruncatedInspect

#inspect, truncating

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Instance Method Details

#chat ⇒ Object



40
41
42
# File 'src/foobara/ai/answer_bot/domain_mappers/open_ai_api/chat_to_generate_chat_completion.rb', line 40

def chat
  from[:chat]
end

#map ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'src/foobara/ai/answer_bot/domain_mappers/open_ai_api/chat_to_generate_chat_completion.rb', line 20

def map
  inputs = {
    messages: chat.messages.map do |message|
      { role: message.role, content: message.content }
    end
  }

  # if temperature
  #   # NOTE: some models don't support temperature, like o1. Instead of possibly receiving an error
  #   # we will set the temperature to 1 which prevents a 400. Maybe print a warning instead?
  #   inputs[:temperature] = model_supports_temperature? ? temperature : 1
  # end

  if model
    inputs[:model] = model
  end

  inputs
end

#model ⇒ Object

def temperature from end



48
49
50
# File 'src/foobara/ai/answer_bot/domain_mappers/open_ai_api/chat_to_generate_chat_completion.rb', line 48

def model
  from[:model]
end