Class: Promptcraft::Command::LlmChatCommand
- Inherits:
-
Object
- Object
- Promptcraft::Command::LlmChatCommand
- Defined in:
- lib/promptcraft/command/llm_chat_command.rb
Instance Attribute Summary collapse
-
#llm ⇒ Object
readonly
Returns the value of attribute llm.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(messages:, llm:) ⇒ LlmChatCommand
constructor
A new instance of LlmChatCommand.
Constructor Details
#initialize(messages:, llm:) ⇒ LlmChatCommand
Returns a new instance of LlmChatCommand.
6 7 8 9 |
# File 'lib/promptcraft/command/llm_chat_command.rb', line 6 def initialize(messages:, llm:) @messages = @llm = llm end |
Instance Attribute Details
#llm ⇒ Object (readonly)
Returns the value of attribute llm.
4 5 6 |
# File 'lib/promptcraft/command/llm_chat_command.rb', line 4 def llm @llm end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
4 5 6 |
# File 'lib/promptcraft/command/llm_chat_command.rb', line 4 def @messages end |
Instance Method Details
#execute ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/promptcraft/command/llm_chat_command.rb', line 11 def execute # cleanse messages of missing content, role, etc = @messages.reject { |m| m[:content].nil? || m[:content].empty? || m[:role].nil? || m[:role].empty? } response = @llm.chat(messages:) response_text = response.chat_completion {role: "assistant", content: response_text} rescue => e puts e. raise end |