Skip to content

Conversation

@jlandiseigsti
Copy link
Contributor

closes #159

This provides the logic for the ImageAltText Job, and uses our own AltText gem to create alt text for whatever we upload. Though the alt text is added to the ImageJob model, live updates are not implemented until ticket 161.

Comment on lines 13 to 23
timer = 0
until alt_text = client.process_image(tmp_path, prompt: File.read('prompt.txt'),
model_id: ENV.fetch('LLM_MODEL', nil))
sleep OUTPUT_POLLING_INTERVAL
timer += OUTPUT_POLLING_INTERVAL
if timer > output_polling_timeout
update_with_failure(job, 'Timed out waiting for alt-text')
FileUtils.rm_f(tmp_path)
return true
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The polling process here can be removed. AltText::Client#process_image immediately returns the generated alt-text once done. It isn't checking for a file like the PDF remediation process.

# File.delete(tmp_path) if File.exist?(tmp_path)
include AppJobModule

def perform(job_uuid, tmp_path, output_polling_timeout: OUTPUT_POLLING_TIMEOUT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the output_polling_timeout argument can be removed.

finished_at: Time.zone.now,
alt_text: alt_text
)
FileUtils.rm_f(tmp_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should put the file delete in an ensure block after the rescue so it always happens, even when there's an error.

job = Job.find_by!(uuid: job_uuid)
alt_text = client.process_image(
tmp_path,
prompt: File.read('prompt.txt'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but it might be safer to include the full path like this:

File.read(Rails.root.join("prompt.txt"))

So it knows where that file is regardless of where a rails process is ran.

Copy link
Contributor

@ajkiessl ajkiessl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jlandiseigsti jlandiseigsti merged commit 087fbb1 into main Oct 21, 2025
3 checks passed
@jlandiseigsti jlandiseigsti deleted the 159-alt-text-sidekiq-job branch October 21, 2025 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alt text generation SideKiq job

2 participants