Skip to content
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

Increase size of images exposed to models #9027

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions front/lib/api/files/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,17 @@ const resizeAndUploadToFileStorage: ProcessingFunction = async (
version: "original",
});

// Resize the image, preserving the aspect ratio. Longest side is max 768px.
const resizedImageStream = sharp().resize(768, 768, {
fit: sharp.fit.inside, // Ensure longest side is 768px.
withoutEnlargement: true, // Avoid upscaling if image is smaller than 768px.
// Anthropic https://docs.anthropic.com/en/docs/build-with-claude/vision#evaluate-image-size
// OpenAI https://platform.openai.com/docs/guides/vision#calculating-costs

// Anthropic recommends <= 1568px on any side.
// OpenAI recommends <= 2048px on the longuest side, 768px on the shortest side.

// Resize the image, preserving the aspect ratio based on the longest side compatible with both models.
// In case of GPT, it might incure a resize on their side as well but doing the math here would mean downloading the file first instead of streaming it.
const resizedImageStream = sharp().resize(1568, 1568, {
fit: sharp.fit.inside, // Ensure longest side is 1568px.
withoutEnlargement: true, // Avoid upscaling if image is smaller than 1568px.
});

const writeStream = file.getWriteStream({
Expand Down
29 changes: 0 additions & 29 deletions front/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.