refactor: relocate captain assistant services to oss
This commit is contained in:
-6
@@ -11,7 +11,6 @@ class Captain::Assistant::BaseAssistantService
|
||||
|
||||
result = runner.run(@text, context: {})
|
||||
|
||||
# Check if result has an error field
|
||||
return error_response(result.error) if result.respond_to?(:error) && result.error
|
||||
|
||||
process_result(result)
|
||||
@@ -37,7 +36,6 @@ class Captain::Assistant::BaseAssistantService
|
||||
InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_MODEL')&.value.presence || OpenAiConstants::DEFAULT_MODEL
|
||||
end
|
||||
|
||||
# To be implemented by subclasses
|
||||
def agent_name
|
||||
raise NotImplementedError, "#{self.class} must implement agent_name"
|
||||
end
|
||||
@@ -53,13 +51,11 @@ class Captain::Assistant::BaseAssistantService
|
||||
def process_result(result)
|
||||
output = result.output
|
||||
|
||||
# Check if output itself has an error
|
||||
return error_response(output[:error] || output['error']) if output.is_a?(Hash) && (output[:error] || output['error'])
|
||||
|
||||
build_success_response(output)
|
||||
end
|
||||
|
||||
# Override in subclasses for custom response structure
|
||||
def build_success_response(output)
|
||||
{
|
||||
success: true,
|
||||
@@ -76,7 +72,6 @@ class Captain::Assistant::BaseAssistantService
|
||||
}
|
||||
end
|
||||
|
||||
# Helper methods for extracting data from output
|
||||
def extract_field(output, *field_names)
|
||||
return output.to_s unless output.is_a?(Hash)
|
||||
|
||||
@@ -88,7 +83,6 @@ class Captain::Assistant::BaseAssistantService
|
||||
nil
|
||||
end
|
||||
|
||||
# Override in subclasses to specify the primary field to extract
|
||||
def extract_primary_field(output)
|
||||
output
|
||||
end
|
||||
-9
@@ -3,7 +3,6 @@ class Captain::Assistant::ConversationSummaryService < Captain::Assistant::BaseA
|
||||
|
||||
def initialize(conversation:)
|
||||
@conversation = conversation
|
||||
# Format conversation messages as text
|
||||
super(text: format_conversation_messages)
|
||||
end
|
||||
|
||||
@@ -17,7 +16,6 @@ class Captain::Assistant::ConversationSummaryService < Captain::Assistant::BaseA
|
||||
Captain::PromptRenderer.render('summary', {})
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def response_schema
|
||||
{
|
||||
type: 'object',
|
||||
@@ -49,7 +47,6 @@ class Captain::Assistant::ConversationSummaryService < Captain::Assistant::BaseA
|
||||
additionalProperties: false
|
||||
}
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def build_success_response(output)
|
||||
{
|
||||
@@ -97,30 +94,25 @@ class Captain::Assistant::ConversationSummaryService < Captain::Assistant::BaseA
|
||||
output[field_name.to_sym] || output[field_name.to_s] || []
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
||||
def build_summary_markdown(output)
|
||||
return '' unless output.is_a?(Hash)
|
||||
|
||||
sections = []
|
||||
|
||||
# Customer Intent
|
||||
if (intent = extract_field(output, 'customer_intent')).present?
|
||||
sections << "**Customer Intent**\n\n#{intent}"
|
||||
end
|
||||
|
||||
# Conversation Summary
|
||||
if (summary = extract_field(output, 'conversation_summary')).present?
|
||||
sections << "**Conversation Summary**\n\n#{summary}"
|
||||
end
|
||||
|
||||
# Action Items
|
||||
action_items = extract_array_field(output, 'action_items')
|
||||
if action_items&.any?
|
||||
items_list = action_items.map { |item| "- #{item}" }.join("\n")
|
||||
sections << "**Action Items**\n\n#{items_list}"
|
||||
end
|
||||
|
||||
# Follow-up Items
|
||||
follow_up_items = extract_array_field(output, 'follow_up_items')
|
||||
if follow_up_items&.any?
|
||||
items_list = follow_up_items.map { |item| "- #{item}" }.join("\n")
|
||||
@@ -129,5 +121,4 @@ class Captain::Assistant::ConversationSummaryService < Captain::Assistant::BaseA
|
||||
|
||||
sections.join("\n\n")
|
||||
end
|
||||
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
||||
end
|
||||
Reference in New Issue
Block a user