Class: Langchain::Thread
- Inherits:
-
Object
- Object
- Langchain::Thread
- Defined in:
- lib/langchain/assistants/thread.rb
Overview
Langchain::Thread keeps track of messages in a conversation. TODO: Add functionality to persist to the thread to disk, DB, storage, etc.
Instance Attribute Summary collapse
-
#messages ⇒ Object
Returns the value of attribute messages.
Instance Method Summary collapse
-
#add_message(message) ⇒ Array<Langchain::Message>
Add a message to the thread.
-
#initialize(messages: []) ⇒ Thread
constructor
A new instance of Thread.
-
#openai_messages ⇒ Array<Hash>
Convert the thread to an OpenAI API-compatible array of hashes.
Constructor Details
#initialize(messages: []) ⇒ Thread
Returns a new instance of Thread.
10 11 12 13 14 |
# File 'lib/langchain/assistants/thread.rb', line 10 def initialize(messages: []) raise ArgumentError, "messages array must only contain Langchain::Message instance(s)" unless .is_a?(Array) && .all? { |m| m.is_a?(Langchain::Message) } @messages = end |
Instance Attribute Details
#messages ⇒ Object
Returns the value of attribute messages.
7 8 9 |
# File 'lib/langchain/assistants/thread.rb', line 7 def @messages end |
Instance Method Details
#add_message(message) ⇒ Array<Langchain::Message>
Add a message to the thread
27 28 29 30 31 32 |
# File 'lib/langchain/assistants/thread.rb', line 27 def () raise ArgumentError, "message must be a Langchain::Message instance" unless .is_a?(Langchain::Message) # Prepend the message to the thread << end |
#openai_messages ⇒ Array<Hash>
Convert the thread to an OpenAI API-compatible array of hashes
19 20 21 |
# File 'lib/langchain/assistants/thread.rb', line 19 def .map(&:to_openai_format) end |