Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
79 lines
2.2 KiB
Ruby
79 lines
2.2 KiB
Ruby
class Captain::Documents::ResponseBuilderJob < ApplicationJob
|
|
queue_as :low
|
|
|
|
def perform(document, options = {})
|
|
reset_previous_responses(document)
|
|
|
|
faqs = generate_faqs(document, options)
|
|
create_responses_from_faqs(faqs, document)
|
|
end
|
|
|
|
private
|
|
|
|
def generate_faqs(document, options)
|
|
if should_use_pagination?(document)
|
|
generate_paginated_faqs(document, options)
|
|
else
|
|
generate_standard_faqs(document)
|
|
end
|
|
end
|
|
|
|
def generate_paginated_faqs(document, options)
|
|
service = build_paginated_service(document, options)
|
|
faqs = service.generate
|
|
store_paginated_metadata(document, service)
|
|
faqs
|
|
end
|
|
|
|
def generate_standard_faqs(document)
|
|
Captain::Llm::FaqGeneratorService.new(document.content, document.account.locale_english_name, account_id: document.account_id).generate
|
|
end
|
|
|
|
def build_paginated_service(document, options)
|
|
Captain::Llm::PaginatedFaqGeneratorService.new(
|
|
document,
|
|
pages_per_chunk: options[:pages_per_chunk],
|
|
max_pages: options[:max_pages],
|
|
language: document.account.locale_english_name
|
|
)
|
|
end
|
|
|
|
def store_paginated_metadata(document, service)
|
|
document.update!(
|
|
metadata: (document.metadata || {}).merge(
|
|
'faq_generation' => {
|
|
'method' => 'paginated',
|
|
'pages_processed' => service.total_pages_processed,
|
|
'iterations' => service.iterations_completed,
|
|
'timestamp' => Time.current.iso8601
|
|
}
|
|
)
|
|
)
|
|
end
|
|
|
|
def create_responses_from_faqs(faqs, document)
|
|
faqs.each { |faq| create_response(faq, document) }
|
|
end
|
|
|
|
def should_use_pagination?(document)
|
|
# Auto-detect when to use pagination
|
|
# For now, use pagination for PDFs with OpenAI file ID
|
|
document.pdf_document? && document.openai_file_id.present?
|
|
end
|
|
|
|
def reset_previous_responses(response_document)
|
|
response_document.responses.destroy_all
|
|
end
|
|
|
|
def create_response(faq, document)
|
|
document.responses.create!(
|
|
question: faq['question'],
|
|
answer: faq['answer'],
|
|
assistant: document.assistant,
|
|
documentable: document
|
|
)
|
|
rescue ActiveRecord::RecordInvalid => e
|
|
Rails.logger.error I18n.t('captain.documents.response_creation_error', error: e.message)
|
|
end
|
|
end
|