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

work on #261: avoid hang #262

Merged
merged 2 commits into from
Oct 13, 2024
Merged
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
10 changes: 7 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,19 @@ async function fetchImageFromPointer(uri: string) {
}

/** replaces `file-service://` pointers with data uris containing the image */
/** avoid errors in parsing multimodal parts we don't understand */
async function replaceImageAssets(conversation: ApiConversation): Promise<void> {
const isMultiModalInputImage = (part: string | MultiModalInputImage): part is MultiModalInputImage => {
return typeof part !== 'string' && part.asset_pointer.startsWith('file-service://')
const isMultiModalInputImage = (part: any): part is MultiModalInputImage => {
return typeof part === 'object' && part !== null && 'asset_pointer' in part
&& typeof part.asset_pointer === 'string' && part.asset_pointer.startsWith('file-service://')
}

const imageAssets = Object.values(conversation.mapping).flatMap((node) => {
if (!node.message) return []
if (node.message.content.content_type !== 'multimodal_text') return []

return node.message.content.parts.filter(isMultiModalInputImage)
return (Array.isArray(node.message.content.parts) ? node.message.content.parts : [])
.filter(isMultiModalInputImage)
})

const executionOutputs = Object.values(conversation.mapping).flatMap((node) => {
Expand Down