(
content: RequestMessage["content"],
transformImageUrl: (url: string) => Promise<{ [key: string]: any }>,
)
| 71 | } |
| 72 | |
| 73 | export async function preProcessImageContentBase( |
| 74 | content: RequestMessage["content"], |
| 75 | transformImageUrl: (url: string) => Promise<{ [key: string]: any }>, |
| 76 | ) { |
| 77 | if (typeof content === "string") { |
| 78 | return content; |
| 79 | } |
| 80 | const result = []; |
| 81 | for (const part of content) { |
| 82 | if (part?.type == "image_url" && part?.image_url?.url) { |
| 83 | try { |
| 84 | const url = await cacheImageToBase64Image(part?.image_url?.url); |
| 85 | result.push(await transformImageUrl(url)); |
| 86 | } catch (error) { |
| 87 | console.error("Error processing image URL:", error); |
| 88 | } |
| 89 | } else { |
| 90 | result.push({ ...part }); |
| 91 | } |
| 92 | } |
| 93 | return result; |
| 94 | } |
| 95 | |
| 96 | export async function preProcessImageContent( |
| 97 | content: RequestMessage["content"], |
no test coverage detected