Class: SmartPrompt::Conversation
- Inherits:
-
Object
- Object
- SmartPrompt::Conversation
- Defined in:
- lib/smart_prompt/conversation.rb
Instance Attribute Summary collapse
-
#config_file ⇒ Object
readonly
Returns the value of attribute config_file.
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
-
#initialize(engine) ⇒ Conversation
constructor
A new instance of Conversation.
- #model(model_name) ⇒ Object
- #prompt(template_name, params = {}) ⇒ Object
- #send_msg ⇒ Object
- #sys_msg(message) ⇒ Object
- #use(adapter_name) ⇒ Object
Constructor Details
#initialize(engine) ⇒ Conversation
Returns a new instance of Conversation.
7 8 9 10 11 12 13 14 |
# File 'lib/smart_prompt/conversation.rb', line 7 def initialize(engine) @messages = [] @engine = engine @adapters = engine.adapters @templates = engine.templates @current_adapter = engine.current_adapter @last_response = nil end |
Instance Attribute Details
#config_file ⇒ Object (readonly)
Returns the value of attribute config_file.
5 6 7 |
# File 'lib/smart_prompt/conversation.rb', line 5 def config_file @config_file end |
#last_response ⇒ Object (readonly)
Returns the value of attribute last_response.
5 6 7 |
# File 'lib/smart_prompt/conversation.rb', line 5 def last_response @last_response end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
5 6 7 |
# File 'lib/smart_prompt/conversation.rb', line 5 def @messages end |
Instance Method Details
#model(model_name) ⇒ Object
22 23 24 |
# File 'lib/smart_prompt/conversation.rb', line 22 def model(model_name) @model_name = model_name end |
#prompt(template_name, params = {}) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/smart_prompt/conversation.rb', line 26 def prompt(template_name, params = {}) template_name = template_name.to_s raise "Template #{template_name} not found" unless @templates.key?(template_name) content = @templates[template_name].render(params) @messages << { role: 'user', content: content } self end |
#send_msg ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/smart_prompt/conversation.rb', line 40 def send_msg raise "No adapter selected" if @current_adapter.nil? @last_response = @adapters[@current_adapter].send_request(@messages, @model_name) @messages=[] @messages << { role: 'system', content: @sys_msg } @last_response end |
#sys_msg(message) ⇒ Object
34 35 36 37 38 |
# File 'lib/smart_prompt/conversation.rb', line 34 def sys_msg() @sys_msg = @messages << { role: 'system', content: } self end |
#use(adapter_name) ⇒ Object
16 17 18 19 20 |
# File 'lib/smart_prompt/conversation.rb', line 16 def use(adapter_name) raise "Adapter #{adapter_name} not configured" unless @adapters.key?(adapter_name) @current_adapter = adapter_name self end |