Class: Agents::GptAgent
- Defined in:
- lib/agents/gpt_agents/gpt_agent.rb
Direct Known Subclasses
CalendarGptAgent, CategorizingGptAgent, InformationRetrievalGptAgent, PromptlessGptAgent, TodoGptAgent
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#gpt_client ⇒ Object
readonly
Returns the value of attribute gpt_client.
-
#system_prompt ⇒ Object
readonly
Returns the value of attribute system_prompt.
Attributes inherited from Agent
Instance Method Summary collapse
- #handle(request:) ⇒ Object
-
#initialize(gpt_client:, description: "An AI Chatbot", system_prompt: "", **args) ⇒ GptAgent
constructor
A new instance of GptAgent.
- #prompt_prefix ⇒ Object
Methods inherited from Agent
Constructor Details
#initialize(gpt_client:, description: "An AI Chatbot", system_prompt: "", **args) ⇒ GptAgent
Returns a new instance of GptAgent.
7 8 9 10 11 12 |
# File 'lib/agents/gpt_agents/gpt_agent.rb', line 7 def initialize(gpt_client:, description: "An AI Chatbot", system_prompt: "", **args) super(**args) @gpt_client = gpt_client @description = description @system_prompt = system_prompt end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/agents/gpt_agents/gpt_agent.rb', line 4 def description @description end |
#gpt_client ⇒ Object (readonly)
Returns the value of attribute gpt_client.
3 4 5 |
# File 'lib/agents/gpt_agents/gpt_agent.rb', line 3 def gpt_client @gpt_client end |
#system_prompt ⇒ Object (readonly)
Returns the value of attribute system_prompt.
5 6 7 |
# File 'lib/agents/gpt_agents/gpt_agent.rb', line 5 def system_prompt @system_prompt end |
Instance Method Details
#handle(request:) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/agents/gpt_agents/gpt_agent.rb', line 14 def handle(request:) response = gpt_client.chat system_prompt: system_prompt, prompt: "#{prompt_prefix}#{request.request_text}" response.suggested_actions.each do |action| actions.find{ |a| a.name == action["name"] }&.call(action["args"]) end response end |
#prompt_prefix ⇒ Object
24 25 26 |
# File 'lib/agents/gpt_agents/gpt_agent.rb', line 24 def prompt_prefix "" end |