Skip to content

Commit

Permalink
feat: partially support multimodal_text
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Oct 16, 2023
1 parent 0aafea4 commit 7d5c7de
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.codeActionsOnSave": {
"source.fixAll": false,
"source.fixAll": "explicit",
"source.fixAll.eslint": true, // this allows ESLint to auto fix on save
"source.organizeImports": false
},
Expand Down
12 changes: 12 additions & 0 deletions packages/userscript/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ interface MessageMeta {

export type AuthorRole = 'system' | 'assistant' | 'user' | 'tool'

interface MultiModalInputImage {
asset_pointer: string
content_type: 'image_asset_pointer' & (string & {})
height: number
size_bytes: number
width: number
}

export interface ConversationNodeMessage {
author: {
role: AuthorRole
Expand Down Expand Up @@ -70,6 +78,10 @@ export interface ConversationNodeMessage {
content_type: 'tether_browsing_display'
result: string
summary?: string
} | {
// multi-modal input
content_type: 'multimodal_text'
parts: Array<MultiModalInputImage | string>
}
create_time: number
end_turn: boolean
Expand Down
9 changes: 8 additions & 1 deletion packages/userscript/src/exporter/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,15 @@ const transformContent = (
}
return ''
}
case 'multimodal_text': {
return content.parts?.map((part) => {
if (typeof part === 'string') return part
if (part.asset_pointer) return `![image](${part.asset_pointer})`
return '[Unsupported multimodal content]'
}).join('\n') || ''
}
default:
return ''
return '[Unsupported Content]'
}
}

Expand Down
9 changes: 8 additions & 1 deletion packages/userscript/src/exporter/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,15 @@ const transformContent = (
}
return ''
}
case 'multimodal_text': {
return content.parts?.map((part) => {
if (typeof part === 'string') return part
if (part.asset_pointer) return `![image](${part.asset_pointer})`
return '[Unsupported multimodal content]'
}).join('\n') || ''
}
default:
return ''
return '[Unsupported Content]'
}
}

Expand Down
9 changes: 8 additions & 1 deletion packages/userscript/src/exporter/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,15 @@ const transformContent = (
}
return ''
}
case 'multimodal_text': {
return content.parts?.map((part) => {
if (typeof part === 'string') return part
if (part.asset_pointer) return `![image](${part.asset_pointer})`
return '[Unsupported multimodal content]'
}).join('\n') || ''
}
default:
return ''
return '[Unsupported Content]'
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/userscript/src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import { getBase64FromImageUrl, getBase64FromImg } from './utils/dom'
declare global {
interface Window {
__NEXT_DATA__?: {
assetPrefix: string
buildId: string
gssp: boolean
isFallback: boolean
page: string
props: {
pageProps: {
allowBrowserStorage: boolean
canManageBrowserStorage: boolean
geoOk: boolean
isUserInCanPayGroup: boolean
serviceAnnouncement: {
Expand All @@ -27,6 +30,7 @@ declare global {
name: string
picture: string
}
userCountry: string
serverResponse?: {
type: 'data'
data: any // Basically ApiConversation
Expand Down

0 comments on commit 7d5c7de

Please sign in to comment.