Skip to content

Commit 646d3b9

Browse files
committed
file content part in request body for bedrock
1 parent 2eed829 commit 646d3b9

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/providers/bedrock/chatComplete.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { BEDROCK, documentMimeTypes, imagesMimeTypes } from '../../globals';
1+
import {
2+
BEDROCK,
3+
documentMimeTypes,
4+
fileExtensionMimeTypeMap,
5+
imagesMimeTypes,
6+
} from '../../globals';
27
import {
38
Message,
49
Params,
@@ -176,6 +181,32 @@ const getMessageContent = (message: Message) => {
176181
},
177182
});
178183
}
184+
} else if (item.type === 'file') {
185+
const mimeType = item.file?.mime_type || fileExtensionMimeTypeMap.pdf;
186+
const fileFormat = mimeType.split('/')[1];
187+
if (item.file?.file_url) {
188+
out.push({
189+
document: {
190+
format: fileFormat,
191+
name: crypto.randomUUID(),
192+
source: {
193+
s3Location: {
194+
uri: item.file.file_url,
195+
},
196+
},
197+
},
198+
});
199+
} else if (item.file?.file_data) {
200+
out.push({
201+
document: {
202+
format: fileFormat,
203+
name: crypto.randomUUID(),
204+
source: {
205+
bytes: item.file.file_data,
206+
},
207+
},
208+
});
209+
}
179210
}
180211

181212
if (item.cache_control) {
@@ -377,7 +408,10 @@ type BedrockContentItem = {
377408
format: string;
378409
name: string;
379410
source: {
380-
bytes: string;
411+
bytes?: string;
412+
s3Location?: {
413+
uri: string;
414+
};
381415
};
382416
};
383417
cachePoint?: {

0 commit comments

Comments
 (0)