Skip to content

Commit

Permalink
Increase size of images exposed to models (#9027)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraggle authored Nov 29, 2024
1 parent c954c49 commit dcbc79b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
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.

0 comments on commit dcbc79b

Please sign in to comment.