* feat: add per-inbox signature management - Introduced `InboxSignature` model to manage signatures specific to each inbox. - Added API endpoints for fetching, creating, updating, and deleting inbox signatures. - Updated UI components to support inbox-specific signatures, including overrides for signature position and separator. - Implemented a new composable `useInboxSignatures` for managing inbox signatures in the frontend. - Enhanced existing components to utilize inbox signatures, including the reply box and message signature settings. - Added tests for the new inbox signatures functionality, ensuring proper behavior of the API and model validations. - Updated translations for new UI elements related to inbox signatures. * feat: implement inbox access validation and add related tests * feat: enhance inbox signatures fetching and management logic
48 lines
1.2 KiB
Ruby
48 lines
1.2 KiB
Ruby
class Captain::ReplySuggestionService < Captain::BaseTaskService
|
|
pattr_initialize [:account!, :conversation_display_id!, :user!]
|
|
|
|
def perform
|
|
make_api_call(
|
|
model: GPT_MODEL,
|
|
messages: [
|
|
{ role: 'system', content: system_prompt },
|
|
{ role: 'user', content: formatted_conversation }
|
|
]
|
|
)
|
|
end
|
|
|
|
private
|
|
|
|
def system_prompt
|
|
template = prompt_from_file('reply')
|
|
render_liquid_template(template, prompt_variables)
|
|
end
|
|
|
|
def prompt_variables
|
|
{
|
|
'channel_type' => conversation.inbox.channel_type,
|
|
'agent_name' => user.name,
|
|
'agent_signature' => resolved_signature
|
|
}
|
|
end
|
|
|
|
def resolved_signature
|
|
inbox_signature = user.inbox_signatures.find_by(inbox_id: conversation.inbox_id)
|
|
inbox_signature&.message_signature || user.message_signature.presence
|
|
end
|
|
|
|
def render_liquid_template(template_content, variables = {})
|
|
Liquid::Template.parse(template_content).render(variables)
|
|
end
|
|
|
|
def formatted_conversation
|
|
LlmFormatter::ConversationLlmFormatter.new(conversation).format(token_limit: TOKEN_LIMIT)
|
|
end
|
|
|
|
def event_name
|
|
'reply_suggestion'
|
|
end
|
|
end
|
|
|
|
Captain::ReplySuggestionService.prepend_mod_with('Captain::ReplySuggestionService')
|