Module: OpenAI::ChatGPT::ClassMethods

Defined in:
lib/open_ai/chat_gpt.rb

Instance Method Summary collapse

Instance Method Details

#default_instructionObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/open_ai/chat_gpt.rb', line 16

def default_instruction
  msg = <<~MSG
    You are in a group chat. In the first line of the message, you will receive the name of the user who sent that message.
    Do not sign your messages this way
    Do not use users' names without need (for example, if you are replying to @foo, do not add "@foo" to your message)
    You can still use names to mention other users you're not replying to directly.

    Different languages can be used.
  MSG

  SystemMessage.new(
    body: msg
  )
end

#first_bot_messageObject



38
39
40
41
42
# File 'lib/open_ai/chat_gpt.rb', line 38

def first_bot_message
  BotMessage.new(
    body: "Good for you!"
  )
end

#first_user_messageObject



31
32
33
34
35
36
# File 'lib/open_ai/chat_gpt.rb', line 31

def first_user_message
  Message.new(
    from: "@tyradee",
    body: "I drank some tea today."
  )
end

#initial_messagesObject



44
45
46
47
48
49
50
# File 'lib/open_ai/chat_gpt.rb', line 44

def initial_messages
  [
    default_instruction,
    first_user_message,
    first_bot_message
  ]
end

#new_thread(chat_id, model = nil) ⇒ Object



10
11
12
13
14
# File 'lib/open_ai/chat_gpt.rb', line 10

def new_thread(chat_id, model = nil)
  msgs = config.open_ai["whitelist"].include?(chat_id) ? initial_messages : []
  new_thread = ChatThread.new(msgs, model)
  threads[chat_id] = new_thread
end

#threadsObject



6
7
8
# File 'lib/open_ai/chat_gpt.rb', line 6

def threads
  @threads ||= {}
end