-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEATURE: PDF support for rag pipeline #1118
base: main
Are you sure you want to change the base?
Conversation
(this starts by defining the extraction routines)
@llm_model.vision_enabled | ||
end | ||
|
||
private |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably a forgotten private
def system_message | ||
<<~MSG | ||
OCR the following page into Markdown. Tables should be formatted as Github flavored markdown. | ||
Do not sorround your output with triple backticks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not sorround your output with triple backticks. | |
Do not surround your output with triple backticks. |
|
||
@uploaded_pages = uploads | ||
ensure | ||
FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FileUtils.rm_rf(path)
already handles non-existent paths gracefully.
FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir) | |
FileUtils.rm_rf(temp_dir) |
temp_dir = File.join(Dir.tmpdir, "discourse-pdf-#{SecureRandom.hex(8)}") | ||
FileUtils.mkdir_p(temp_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
temp_dir = File.join(Dir.tmpdir, "discourse-pdf-#{SecureRandom.hex(8)}") | |
FileUtils.mkdir_p(temp_dir) | |
Dir.mktmpdir("discourse-pdf-#{SecureRandom.hex(8)}") |
@@ -50,6 +47,28 @@ def self.valid_value?(val) | |||
true | |||
end | |||
|
|||
# returns an array of hashes (id: , name:, vision_enabled:) | |||
def self.values_for_serialization(allowed_seeded_llm_ids: nil) | |||
#if allowed_seeded_llms.is_a?(Array) && !allowed_seeded_llms.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you mean to keep this?
get visionLlmId() { | ||
return this.args.model.rag_llm_model_id || "blank"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
} | ||
|
||
get mappedDefaultLlm() { | ||
return this.editingModel?.default_llm || "blank"; | ||
return this.editingModel?.default_llm_id || "blank"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return this.editingModel?.default_llm_id || "blank"; | |
return this.editingModel?.default_llm_id ?? "blank"; |
I explain later why
@@ -167,27 +167,27 @@ export default class PersonaEditor extends Component { | |||
} | |||
|
|||
get mappedQuestionConsolidatorLlm() { | |||
return this.editingModel?.question_consolidator_llm || "blank"; | |||
return this.editingModel?.question_consolidator_llm_id || "blank"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return this.editingModel?.question_consolidator_llm_id || "blank"; | |
return this.editingModel?.question_consolidator_llm_id ?? "blank"; |
This PR introduces several enhancements and refactorings to the AI Persona and RAG (Retrieval-Augmented Generation) functionalities within the discourse-ai plugin. Here's a breakdown of the changes:
1. LLM Model Association for RAG and Personas:
rag_llm_model_id
to bothai_personas
andai_tools
tables. This allows specifying a dedicated LLM for RAG indexing, separate from the persona's primary LLM. Addsdefault_llm_id
andquestion_consolidator_llm_id
toai_personas
.20250210032345_migrate_persona_to_llm_model_id.rb
) to populate the newdefault_llm_id
andquestion_consolidator_llm_id
columns inai_personas
based on the existingdefault_llm
andquestion_consolidator_llm
string columns, and a post migration to remove the latter.AiPersona
andAiTool
models nowbelong_to
anLlmModel
viarag_llm_model_id
. TheLlmModel.proxy
method now accepts anLlmModel
instance instead of just an identifier.AiPersona
now hasdefault_llm_id
andquestion_consolidator_llm_id
attributes.AiCustomToolSerializer
,AiCustomToolListSerializer
,LocalizedAiPersonaSerializer
) have been updated to include the newrag_llm_model_id
,default_llm_id
andquestion_consolidator_llm_id
attributes.2. PDF and Image Support for RAG:
ai_rag_pdf_images_enabled
, to control whether PDF and image files can be indexed for RAG. This defaults tofalse
.RagDocumentFragmentsController
now checks theai_rag_pdf_images_enabled
setting and allows PDF, PNG, JPG, and JPEG files if enabled. Error handling is included for cases where PDF/image indexing is attempted with the setting disabled.DiscourseAi::Utils::PdfToImages
, which uses ImageMagick (magick
) to convert PDF pages into individual PNG images. A maximum PDF size and conversion timeout are enforced.DiscourseAi::Utils::ImageToText
, is included to handle OCR for the images and PDFs.DigestRagUpload
job now handles PDF and image uploads. It usesPdfToImages
andImageToText
to extract text and create document fragments.ai_rag_pdf_images_enabled
is true. The UI text is adjusted to indicate supported file types.3. Refactoring and Improvements:
DiscourseAi::Configuration::LlmEnumerator
now provides avalues_for_serialization
method, which returns a simplified array of LLM data (id, name, vision_enabled) suitable for use in serializers. This avoids exposing unnecessary details to the frontend.AiHelper::Assistant
now takes optionalhelper_llm
andimage_caption_llm
parameters in its constructor, allowing for greater flexibility.DiscourseAi::Completions::Endpoints::Base
now formats raw request payloads as pretty JSON for easier auditing.4. Testing:
/evals