From 5c5abc24e340b1633b90bcfbf800190dc3bb1403 Mon Sep 17 00:00:00 2001
From: Tanmay Deep Sharma <32020192+tds-1@users.noreply.github.com>
Date: Tue, 23 Sep 2025 13:17:15 +0200
Subject: [PATCH] fix: Use account locale when generating PDF FAQs (#12491)
## Linear Link:
https://linear.app/chatwoot/issue/CW-5636/pdf-faqs-captain-generates-faqs-in-the-english-only
## Description
PDF Faqs should be generated in the same language as set in account
## Type of change
- [ ] Bug fix (non-breaking change which fixes an issue)
## How Has This Been Tested?
This has been tested via UI, by setting account language to arabic and
upload the pdf for faq generation (pdf content in Hindi)
## Checklist:
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
Co-authored-by: Muhsin Keloth
---
.../app/jobs/captain/documents/response_builder_job.rb | 3 ++-
.../services/captain/llm/paginated_faq_generator_service.rb | 5 +++--
.../app/services/captain/llm/system_prompts_service.rb | 4 +++-
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/enterprise/app/jobs/captain/documents/response_builder_job.rb b/enterprise/app/jobs/captain/documents/response_builder_job.rb
index 5dacb416f..b22fa5bc1 100644
--- a/enterprise/app/jobs/captain/documents/response_builder_job.rb
+++ b/enterprise/app/jobs/captain/documents/response_builder_job.rb
@@ -33,7 +33,8 @@ class Captain::Documents::ResponseBuilderJob < ApplicationJob
Captain::Llm::PaginatedFaqGeneratorService.new(
document,
pages_per_chunk: options[:pages_per_chunk],
- max_pages: options[:max_pages]
+ max_pages: options[:max_pages],
+ language: document.account.locale_english_name
)
end
diff --git a/enterprise/app/services/captain/llm/paginated_faq_generator_service.rb b/enterprise/app/services/captain/llm/paginated_faq_generator_service.rb
index 18f9813ef..2d326f081 100644
--- a/enterprise/app/services/captain/llm/paginated_faq_generator_service.rb
+++ b/enterprise/app/services/captain/llm/paginated_faq_generator_service.rb
@@ -8,6 +8,7 @@ class Captain::Llm::PaginatedFaqGeneratorService < Llm::BaseOpenAiService
def initialize(document, options = {})
super()
@document = document
+ @language = options[:language] || 'english'
@pages_per_chunk = options[:pages_per_chunk] || DEFAULT_PAGES_PER_CHUNK
@max_pages = options[:max_pages] # Optional limit from UI
@total_pages_processed = 0
@@ -118,7 +119,7 @@ class Captain::Llm::PaginatedFaqGeneratorService < Llm::BaseOpenAiService
end
def page_chunk_prompt(start_page, end_page)
- Captain::Llm::SystemPromptsService.paginated_faq_generator(start_page, end_page)
+ Captain::Llm::SystemPromptsService.paginated_faq_generator(start_page, end_page, @language)
end
def standard_chat_parameters
@@ -128,7 +129,7 @@ class Captain::Llm::PaginatedFaqGeneratorService < Llm::BaseOpenAiService
messages: [
{
role: 'system',
- content: Captain::Llm::SystemPromptsService.faq_generator
+ content: Captain::Llm::SystemPromptsService.faq_generator(@language)
},
{
role: 'user',
diff --git a/enterprise/app/services/captain/llm/system_prompts_service.rb b/enterprise/app/services/captain/llm/system_prompts_service.rb
index b8282beb1..ba8834c1f 100644
--- a/enterprise/app/services/captain/llm/system_prompts_service.rb
+++ b/enterprise/app/services/captain/llm/system_prompts_service.rb
@@ -206,7 +206,7 @@ class Captain::Llm::SystemPromptsService
SYSTEM_PROMPT_MESSAGE
end
- def paginated_faq_generator(start_page, end_page)
+ def paginated_faq_generator(start_page, end_page, language = 'english')
<<~PROMPT
You are an expert technical documentation specialist tasked with creating comprehensive FAQs from a SPECIFIC SECTION of a document.
@@ -226,6 +226,8 @@ class Captain::Llm::SystemPromptsService
FAQ GENERATION GUIDELINES
════════════════════════════════════════════════════════
+ **Language**: Generate the FAQs only in #{language}, use no other language
+
1. **Comprehensive Extraction**
• Extract ALL information that could generate FAQs from this section
• Target 5-10 FAQs per page equivalent of rich content