# frozen_string_literal: true
module DiscourseAi
module AiBot
module Tools
class Custom < Tool
def self.class_instance(tool_id)
klass = Class.new(self)
klass.tool_id = tool_id
klass
end
def self.custom?
true
def self.tool_id
@tool_id
def self.tool_id=(tool_id)
@tool_id = tool_id
def self.signature
AiTool.find(tool_id).signature
def self.name
AiTool.where(id: tool_id).pluck(:name).first
def initialize(*args, **kwargs)
@chain_next_response = true
super(*args, **kwargs)
def invoke
result = runner.invoke
if runner.custom_raw
self.custom_raw = runner.custom_raw
@chain_next_response = false
result
def runner
@runner ||= ai_tool.runner(parameters, llm: llm, bot_user: bot_user, context: context)
def ai_tool
@ai_tool ||= AiTool.find(self.class.tool_id)
def summary
ai_tool.summary
def details
runner.details
def chain_next_response?
!!@chain_next_response
def help
# I do not think this is called, but lets make sure
raise "Not implemented"