MCPcopy Index your code
hub / github.com/ChatGPTNextWeb/NextChat / preProcessImageContentBase

Function preProcessImageContentBase

app/utils/chat.ts:73–94  ·  view source on GitHub ↗
(
  content: RequestMessage["content"],
  transformImageUrl: (url: string) => Promise<{ [key: string]: any }>,
)

Source from the content-addressed store, hash-verified

71}
72
73export 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
96export async function preProcessImageContent(
97 content: RequestMessage["content"],

Calls 2

cacheImageToBase64ImageFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected