Class: Roseflow::Chat::Dialogue
- Inherits:
-
Object
- Object
- Roseflow::Chat::Dialogue
- Defined in:
- lib/roseflow/chat/dialogue.rb
Instance Attribute Summary collapse
-
#exchanges ⇒ Object
readonly
Returns the value of attribute exchanges.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#personality ⇒ Object
readonly
Returns the value of attribute personality.
Instance Method Summary collapse
-
#initialize(personality: nil) ⇒ Dialogue
constructor
A new instance of Dialogue.
- #model ⇒ Object
- #provider ⇒ Object
- #recall(messages) ⇒ Object
-
#say(input, **options) ⇒ Object
This method takes a string input as input, which is a message to send to the LLM model.
Constructor Details
#initialize(personality: nil) ⇒ Dialogue
Returns a new instance of Dialogue.
13 14 15 16 17 |
# File 'lib/roseflow/chat/dialogue.rb', line 13 def initialize(personality: nil) @messages = [] @exchanges = [] initialize_with_personality(personality) if personality end |
Instance Attribute Details
#exchanges ⇒ Object (readonly)
Returns the value of attribute exchanges.
10 11 12 |
# File 'lib/roseflow/chat/dialogue.rb', line 10 def exchanges @exchanges end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
9 10 11 |
# File 'lib/roseflow/chat/dialogue.rb', line 9 def @messages end |
#personality ⇒ Object (readonly)
Returns the value of attribute personality.
11 12 13 |
# File 'lib/roseflow/chat/dialogue.rb', line 11 def personality @personality end |
Instance Method Details
#model ⇒ Object
19 20 21 |
# File 'lib/roseflow/chat/dialogue.rb', line 19 def model @model ||= provider.models.chattable.first end |
#provider ⇒ Object
23 24 25 |
# File 'lib/roseflow/chat/dialogue.rb', line 23 def provider @provider ||= OpenAI::Provider.new(Roseflow::OpenAI::Config.new) end |
#recall(messages) ⇒ Object
27 28 29 30 |
# File 'lib/roseflow/chat/dialogue.rb', line 27 def recall() @messages = parse_exchanges end |
#say(input, **options) ⇒ Object
This method takes a string input as input, which is a message to send to the LLM model. If the model is chattable, it sends the messages to the model and returns a response.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/roseflow/chat/dialogue.rb', line 34 def say(input, **) if model.chattable? = (input) @messages.push() model_response = provider.chat(model: model, messages: @messages, **) if model_response && model_response.success? exchange = create_exchange(, model_response.choices.first.) @exchanges.push(exchange) @messages.push(exchange.response) exchange.response else raise "Did not receive a response from the model" end else raise "Model is not chattable" end end |