-
I've been working with the example provided in the following link: In the example, when I upload a Is there any way to resolve this issue? I tried reading the file URL in |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
When calling A possible solution: // It might cause the pending time to be longer.
// PERFORMANCE: JUST PROCESS THE LAST MESSAGE ATTACHMENTS, Trade-off between performance and message completeness.
const processedMessagesPromises = messages.map(
async (message: ResponseMessage) => {
if (message.experimental_attachments) {
const processedAttachments = await Promise.all(
message.experimental_attachments.map(async (attachment) => {
switch (attachment.contentType) {
case 'text/plain':
case 'text/csv':
const resText = await fetch(attachment.url)
const text = await resText.text()
const base64 = Buffer.from(text).toString('base64')
attachment.url = `data:${attachment.contentType};base64,${base64}`
break
}
return attachment
})
)
return {
...message,
experimental_attachments: processedAttachments
}
}
return message
}
)
const processedMessages = await Promise.all(processedMessagesPromises)
// ....
await streamText(
messages: convertToCoreMessages(processedMessages),
) |
Beta Was this translation helpful? Give feedback.
-
@lesenelir I'm encountering the same issue. Based on the documentation, I assumed text files would be handled, if not other file types. Since the AI recognizes images, I expected it would also recognize text files. My current workflow:
Despite this approach, the AI still fails to recognize the text files. Have you received an official response from the team regarding the solution you proposed? Is it the recommended method, or is there a more effective way to handle this situation? |
Beta Was this translation helpful? Give feedback.
-
for files, I tested with pdf, it worked with google generative ui, gpt image only, I understood it as a limitation of the model. The option to use base64 can overload the sum of input tokens, it would be the same as sending raw text as context, I imagine that these feature parts should solve this problem. But I confess that I haven't been able to look into this topic yet. |
Beta Was this translation helpful? Give feedback.
convertToCoreMessages
attachmentsToParts
When calling
convertToCoreMessages
,attachments
are converted to base64. So if a URL is from the database, it also needs to be converted to base64 in/api/chat/route.ts
.A possible solution: