Co-authored-by: Aakash Bakhle <48802744+aakashb95@users.noreply.github.com> Co-authored-by: Vishnu Narayanan <iamwishnu@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: iamsivin <iamsivin@gmail.com> Co-authored-by: aakashb95 <aakashbakhle@gmail.com>
72 lines
1.8 KiB
Ruby
72 lines
1.8 KiB
Ruby
class Api::V1::Accounts::Captain::TasksController < Api::V1::Accounts::BaseController
|
|
before_action :check_authorization
|
|
|
|
def rewrite
|
|
result = Captain::RewriteService.new(
|
|
account: Current.account,
|
|
content: params[:content],
|
|
operation: params[:operation],
|
|
conversation_display_id: params[:conversation_display_id]
|
|
).perform
|
|
|
|
render_result(result)
|
|
end
|
|
|
|
def summarize
|
|
result = Captain::SummaryService.new(
|
|
account: Current.account,
|
|
conversation_display_id: params[:conversation_display_id]
|
|
).perform
|
|
|
|
render_result(result)
|
|
end
|
|
|
|
def reply_suggestion
|
|
result = Captain::ReplySuggestionService.new(
|
|
account: Current.account,
|
|
conversation_display_id: params[:conversation_display_id],
|
|
user: Current.user
|
|
).perform
|
|
|
|
render_result(result)
|
|
end
|
|
|
|
def label_suggestion
|
|
result = Captain::LabelSuggestionService.new(
|
|
account: Current.account,
|
|
conversation_display_id: params[:conversation_display_id]
|
|
).perform
|
|
|
|
render_result(result)
|
|
end
|
|
|
|
def follow_up
|
|
result = Captain::FollowUpService.new(
|
|
account: Current.account,
|
|
follow_up_context: params[:follow_up_context]&.to_unsafe_h,
|
|
user_message: params[:message],
|
|
conversation_display_id: params[:conversation_display_id]
|
|
).perform
|
|
|
|
render_result(result)
|
|
end
|
|
|
|
private
|
|
|
|
def render_result(result)
|
|
if result.nil?
|
|
render json: { message: nil }
|
|
elsif result[:error]
|
|
render json: { error: result[:error] }, status: :unprocessable_entity
|
|
else
|
|
response_data = { message: result[:message] }
|
|
response_data[:follow_up_context] = result[:follow_up_context] if result[:follow_up_context]
|
|
render json: response_data
|
|
end
|
|
end
|
|
|
|
def check_authorization
|
|
authorize(:'captain/tasks')
|
|
end
|
|
end
|