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)
<img width="1045" height="1085" alt="image"
src="https://github.com/user-attachments/assets/10385181-578e-4933-afc4-4609a6abcec8"
/>


## 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 <muhsinkeramam@gmail.com>
This commit is contained in:
Tanmay Deep Sharma
2025-09-23 13:17:15 +02:00
committed by GitHub
parent 9a5a71b34f
commit 5c5abc24e3
3 changed files with 8 additions and 4 deletions

View File

@@ -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

View File

@@ -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',

View File

@@ -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