2024-11-11 16:14:30 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module DiscourseAi
|
|
|
|
module Completions
|
|
|
|
class ToolCall
|
|
|
|
attr_reader :id, :name, :parameters
|
2024-11-13 14:58:24 -05:00
|
|
|
attr_accessor :partial
|
2024-11-11 16:14:30 -05:00
|
|
|
|
2024-11-18 17:22:39 -05:00
|
|
|
def partial?
|
|
|
|
!!@partial
|
|
|
|
end
|
|
|
|
|
2024-11-11 16:14:30 -05:00
|
|
|
def initialize(id:, name:, parameters: nil)
|
|
|
|
@id = id
|
|
|
|
@name = name
|
|
|
|
self.parameters = parameters if parameters
|
|
|
|
@parameters ||= {}
|
2024-11-13 14:58:24 -05:00
|
|
|
@partial = false
|
2024-11-11 16:14:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def parameters=(parameters)
|
|
|
|
raise ArgumentError, "parameters must be a hash" unless parameters.is_a?(Hash)
|
|
|
|
@parameters = parameters.symbolize_keys
|
|
|
|
end
|
|
|
|
|
|
|
|
def ==(other)
|
|
|
|
id == other.id && name == other.name && parameters == other.parameters
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"#{name} - #{id} (\n#{parameters.map(&:to_s).join("\n")}\n)"
|
|
|
|
end
|
2024-11-13 14:58:24 -05:00
|
|
|
|
|
|
|
def dup
|
|
|
|
call = ToolCall.new(id: id, name: name, parameters: parameters.deep_dup)
|
|
|
|
call.partial = partial
|
|
|
|
call
|
|
|
|
end
|
2024-11-11 16:14:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|