2023-05-05 14:28:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module DiscourseAi
|
|
|
|
module AiBot
|
|
|
|
class BotController < ::ApplicationController
|
|
|
|
requires_plugin ::DiscourseAi::PLUGIN_NAME
|
|
|
|
requires_login
|
|
|
|
|
2024-11-11 16:14:30 -05:00
|
|
|
def show_debug_info_by_id
|
|
|
|
log = AiApiAuditLog.find(params[:id])
|
|
|
|
raise Discourse::NotFound if !log.topic
|
|
|
|
|
|
|
|
guardian.ensure_can_debug_ai_bot_conversation!(log.topic)
|
|
|
|
render json: AiApiAuditLogSerializer.new(log, root: false), status: 200
|
|
|
|
end
|
|
|
|
|
2024-04-15 09:22:06 -04:00
|
|
|
def show_debug_info
|
|
|
|
post = Post.find(params[:post_id])
|
|
|
|
guardian.ensure_can_debug_ai_bot_conversation!(post)
|
|
|
|
|
|
|
|
posts =
|
|
|
|
Post
|
|
|
|
.where("post_number <= ?", post.post_number)
|
|
|
|
.where(topic_id: post.topic_id)
|
|
|
|
.order("post_number DESC")
|
|
|
|
|
|
|
|
debug_info = AiApiAuditLog.where(post: posts).order(created_at: :desc).first
|
|
|
|
|
2024-06-27 09:43:00 -04:00
|
|
|
render json: AiApiAuditLogSerializer.new(debug_info, root: false), status: 200
|
2024-04-15 09:22:06 -04:00
|
|
|
end
|
|
|
|
|
2023-05-05 14:28:31 -04:00
|
|
|
def stop_streaming_response
|
|
|
|
post = Post.find(params[:post_id])
|
|
|
|
guardian.ensure_can_see!(post)
|
|
|
|
|
|
|
|
Discourse.redis.del("gpt_cancel:#{post.id}")
|
|
|
|
|
|
|
|
render json: {}, status: 200
|
|
|
|
end
|
2023-05-16 13:38:21 -04:00
|
|
|
|
|
|
|
def show_bot_username
|
2024-06-18 13:32:14 -04:00
|
|
|
bot_user = DiscourseAi::AiBot::EntryPoint.find_user_from_model(params[:username])
|
|
|
|
raise Discourse::InvalidParameters.new(:username) if !bot_user
|
2023-05-16 13:38:21 -04:00
|
|
|
|
2024-06-18 13:32:14 -04:00
|
|
|
render json: { bot_username: bot_user.username_lower }, status: 200
|
2023-05-16 13:38:21 -04:00
|
|
|
end
|
2023-05-05 14:28:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|