* Convert unified MessageContent to OpenAI format
( content: MessageContent, )
| 171 | * Convert unified MessageContent to OpenAI format |
| 172 | */ |
| 173 | function convertFromMessageContent( |
| 174 | content: MessageContent, |
| 175 | ): string | Array<any> { |
| 176 | if (typeof content === "string") { |
| 177 | return content; |
| 178 | } |
| 179 | |
| 180 | if (Array.isArray(content)) { |
| 181 | return content.map((part: any) => { |
| 182 | if (part.type === "text") { |
| 183 | return { |
| 184 | type: "text", |
| 185 | text: part.text, |
| 186 | }; |
| 187 | } else if (part.type === "imageUrl") { |
| 188 | return { |
| 189 | type: "image_url", |
| 190 | image_url: { url: part.imageUrl.url }, |
| 191 | }; |
| 192 | } |
| 193 | throw new Error(`Unsupported content part type: ${part.type}`); |
| 194 | }); |
| 195 | } |
| 196 | |
| 197 | throw new Error(`Unsupported content type: ${typeof content}`); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Create a ChatHistoryItem from a ChatMessage |
no outgoing calls
no test coverage detected