mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-03-09 11:48:47 +00:00
This re-implements tool support in DiscourseAi::Completions::Llm #generate Previously tool support was always returned via XML and it would be the responsibility of the caller to parse XML New implementation has the endpoints return ToolCall objects. Additionally this simplifies the Llm endpoint interface and gives it more clarity. Llms must implement decode, decode_chunk (for streaming) It is the implementers responsibility to figure out how to decode chunks, base no longer implements. To make this easy we ship a flexible json decoder which is easy to wire up. Also (new) Better debugging for PMs, we now have a next / previous button to see all the Llm messages associated with a PM Token accounting is fixed for vllm (we were not correctly counting tokens)
30 lines
712 B
Ruby
30 lines
712 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module Completions
|
|
class ToolCall
|
|
attr_reader :id, :name, :parameters
|
|
|
|
def initialize(id:, name:, parameters: nil)
|
|
@id = id
|
|
@name = name
|
|
self.parameters = parameters if parameters
|
|
@parameters ||= {}
|
|
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
|
|
end
|
|
end
|
|
end
|