Skip to content

Commit dcbc79b

Browse files
authored
Increase size of images exposed to models (#9027)
1 parent c954c49 commit dcbc79b

File tree

2 files changed

+11
-33
lines changed

2 files changed

+11
-33
lines changed

front/lib/api/files/upload.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,17 @@ const resizeAndUploadToFileStorage: ProcessingFunction = async (
8181
version: "original",
8282
});
8383

84-
// Resize the image, preserving the aspect ratio. Longest side is max 768px.
85-
const resizedImageStream = sharp().resize(768, 768, {
86-
fit: sharp.fit.inside, // Ensure longest side is 768px.
87-
withoutEnlargement: true, // Avoid upscaling if image is smaller than 768px.
84+
// Anthropic https://docs.anthropic.com/en/docs/build-with-claude/vision#evaluate-image-size
85+
// OpenAI https://platform.openai.com/docs/guides/vision#calculating-costs
86+
87+
// Anthropic recommends <= 1568px on any side.
88+
// OpenAI recommends <= 2048px on the longuest side, 768px on the shortest side.
89+
90+
// Resize the image, preserving the aspect ratio based on the longest side compatible with both models.
91+
// 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.
92+
const resizedImageStream = sharp().resize(1568, 1568, {
93+
fit: sharp.fit.inside, // Ensure longest side is 1568px.
94+
withoutEnlargement: true, // Avoid upscaling if image is smaller than 1568px.
8895
});
8996

9097
const writeStream = file.getWriteStream({

front/package-lock.json

Lines changed: 0 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)