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>
64 lines
1.6 KiB
Ruby
64 lines
1.6 KiB
Ruby
class Captain::Llm::PdfProcessingService < Llm::LegacyBaseOpenAiService
|
|
include Integrations::LlmInstrumentation
|
|
|
|
def initialize(document)
|
|
super()
|
|
@document = document
|
|
end
|
|
|
|
def process
|
|
return if document.openai_file_id.present?
|
|
|
|
file_id = upload_pdf_to_openai
|
|
raise CustomExceptions::Pdf::UploadError, I18n.t('captain.documents.pdf_upload_failed') if file_id.blank?
|
|
|
|
document.store_openai_file_id(file_id)
|
|
end
|
|
|
|
private
|
|
|
|
attr_reader :document
|
|
|
|
def upload_pdf_to_openai
|
|
with_tempfile do |temp_file|
|
|
instrument_file_upload do
|
|
response = @client.files.upload(
|
|
parameters: {
|
|
file: temp_file,
|
|
purpose: 'assistants'
|
|
}
|
|
)
|
|
response['id']
|
|
end
|
|
end
|
|
end
|
|
|
|
def instrument_file_upload(&)
|
|
return yield unless ChatwootApp.otel_enabled?
|
|
|
|
tracer.in_span('llm.file.upload') do |span|
|
|
span.set_attribute('gen_ai.provider', 'openai')
|
|
span.set_attribute('file.purpose', 'assistants')
|
|
span.set_attribute(ATTR_LANGFUSE_USER_ID, document.account_id.to_s)
|
|
span.set_attribute(ATTR_LANGFUSE_TAGS, ['pdf_upload'].to_json)
|
|
span.set_attribute(format(ATTR_LANGFUSE_METADATA, 'document_id'), document.id.to_s)
|
|
file_id = yield
|
|
span.set_attribute('file.id', file_id) if file_id
|
|
file_id
|
|
end
|
|
end
|
|
|
|
def with_tempfile
|
|
Tempfile.create(['pdf_upload', '.pdf'], binmode: true) do |temp_file|
|
|
document.pdf_file.blob.open do |blob_file|
|
|
IO.copy_stream(blob_file, temp_file)
|
|
end
|
|
|
|
temp_file.flush
|
|
temp_file.rewind
|
|
|
|
yield temp_file
|
|
end
|
|
end
|
|
end
|