mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 02:05:37 +08:00
27 lines
823 B
Ruby
Vendored
27 lines
823 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module Automation
|
|
module AiToolAction
|
|
def self.handle(post:, tool_id:, llm_model_id: nil, automation: nil)
|
|
tool = ::AiTool.includes(:secret_bindings).find_by(id: tool_id, enabled: true)
|
|
return if !tool
|
|
|
|
llm =
|
|
LlmModel.find_by(id: llm_model_id)&.then { |m| DiscourseAi::Completions::Llm.proxy(m) }
|
|
context =
|
|
DiscourseAi::Agents::BotContext.new(
|
|
post: post,
|
|
feature_name: "ai_tool_action",
|
|
feature_context: {
|
|
automation_id: automation&.id,
|
|
automation_name: automation&.name,
|
|
},
|
|
)
|
|
|
|
runner = tool.runner({}, llm: llm, bot_user: Discourse.system_user, context: context)
|
|
runner.invoke
|
|
end
|
|
end
|
|
end
|
|
end
|