Class: Ruboty::OpenAIChat::Actions::Chat
- Defined in:
- lib/ruboty/openai_chat/actions/chat.rb
Constant Summary
Constants inherited from Base
Base::NAMESPACE, Base::PROFILE_KEY
Instance Attribute Summary collapse
- #ai_comment ⇒ String readonly
- #human_comment ⇒ String readonly
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#client, #initialize, #memory, #openai_model, #pretexts, #robot
Constructor Details
This class inherits a constructor from Ruboty::OpenAIChat::Actions::Base
Instance Attribute Details
#ai_comment ⇒ String (readonly)
10 11 12 |
# File 'lib/ruboty/openai_chat/actions/chat.rb', line 10 def ai_comment @ai_comment end |
#human_comment ⇒ String (readonly)
10 11 12 |
# File 'lib/ruboty/openai_chat/actions/chat.rb', line 10 def human_comment @human_comment end |
Instance Method Details
#call ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ruboty/openai_chat/actions/chat.rb', line 12 def call human_comment = [:body] response = request_chat(human_comment) p response if Ruboty::OpenAIChat.debug_mode? raise response.body if response.code >= 400 ai_comment = response.dig("choices", 0, "message", "content").gsub(/\A\s+/, "") || "" ( Message.new(role: :user, content: human_comment, expire_at: expire_at), Message.new(role: :assistant, content: ai_comment, expire_at: expire_at) ) .reply(ai_comment) rescue StandardError => e forget .reply(e., code: true) raise e if Ruboty::OpenAIChat.debug_mode? true end |