Class: RubyBots::OpenAIBot

Inherits:
OpenAITool show all
Defined in:
lib/ruby_bots/bots/openai_bot.rb

Overview

Bot class for OpenAI. This will use open AI to determine which tool to use for the response.

Direct Known Subclasses

OpenAIChatBot, OpenAIReactBot, RouterBot

Constant Summary collapse

DEFAULT_DESCRIPTION =
'This bot will use OpenAI to determine the appropriate tool.'.freeze

Instance Attribute Summary collapse

Attributes inherited from Tool

#description, #errors, #name

Instance Method Summary collapse

Methods inherited from OpenAITool

#client, #default_params

Methods inherited from Tool

#response, validate_input, validate_output

Constructor Details

#initialize(tools:, name: 'OpenAI bot', description: DEFAULT_DESCRIPTION) ⇒ OpenAIBot

Returns a new instance of OpenAIBot.



10
11
12
13
# File 'lib/ruby_bots/bots/openai_bot.rb', line 10

def initialize(tools:, name: 'OpenAI bot', description: DEFAULT_DESCRIPTION)
  @tools = tools
  super(name:, description:)
end

Instance Attribute Details

#toolsObject

Returns the value of attribute tools.



4
5
6
# File 'lib/ruby_bots/bots/openai_bot.rb', line 4

def tools
  @tools
end

Instance Method Details

#system_instructionsObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/ruby_bots/bots/openai_bot.rb', line 15

def system_instructions
  <<~PROMPT
    You are an assistant designed to select a tool for a user to use. You are provided with the user's input.
    Select from the following tools (name - description):
    #{tools.map { |t| "#{t.name} - #{t.description}" }.join('\n')}

    Return only the name of the tool that best fits the user's request.
    If no tools match the user's request respond with "no tool" and nothing more.
  PROMPT
end