Class: OpenAI::ChatThread
- Inherits:
-
Object
- Object
- OpenAI::ChatThread
- Defined in:
- lib/open_ai/chat_thread.rb
Instance Attribute Summary collapse
-
#history ⇒ Object
(also: #messages)
readonly
Returns the value of attribute history.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #add(message) ⇒ Object
- #as_json ⇒ Object
- #delete(id) ⇒ Object
- #for_logs ⇒ Object
-
#initialize(defaults = [], model = nil) ⇒ ChatThread
constructor
A new instance of ChatThread.
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
#history ⇒ Object (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 |
#model ⇒ Object (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() return false unless &.valid? return false if @history.any? { .id == _1.id} @history << puts true end |
#as_json ⇒ Object
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_logs ⇒ Object
37 38 39 |
# File 'lib/open_ai/chat_thread.rb', line 37 def for_logs @history.map(&:for_logs) end |