Class: OpenAI::ChatThread

Inherits:
Object
  • Object
show all
Defined in:
lib/open_ai/chat_thread.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(defaults = [], model = nil) ⇒ ChatThread

Returns a new instance of ChatThread.



5
6
7
8
9
# File 'lib/open_ai/chat_thread.rb', line 5

def initialize(defaults = [], model = nil)
  @history ||= defaults
  @model = model
  puts @history
end

Instance Attribute Details

#historyObject (readonly) Also known as: messages

Returns the value of attribute history.



11
12
13
# File 'lib/open_ai/chat_thread.rb', line 11

def history
  @history
end

#modelObject (readonly)

Returns the value of attribute model.



12
13
14
# File 'lib/open_ai/chat_thread.rb', line 12

def model
  @model
end

Instance Method Details

#add(message) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/open_ai/chat_thread.rb', line 23

def add(message)
  return false unless message&.valid?
  return false if @history.any? { message.id == _1.id}

  @history << message
  puts message

  true
end

#as_jsonObject



33
34
35
# File 'lib/open_ai/chat_thread.rb', line 33

def as_json
  @history.map(&:as_json)
end

#delete(id) ⇒ Object



16
17
18
19
20
21
# File 'lib/open_ai/chat_thread.rb', line 16

def delete(id)
  return false unless id

  @history.delete_if { _1.id == id }
  true
end

#for_logsObject



37
38
39
# File 'lib/open_ai/chat_thread.rb', line 37

def for_logs
  @history.map(&:for_logs)
end