Skip to content

Commit c1e2491

Browse files
fix(ai): keep standard base64 data URIs for LM Studio integration
Removes the obsolete `normalizeLmStudioImageUrls` helper function which was incorrectly stripping the `data:image/jpeg;base64,` prefix from vision image URLs. Modern versions of LM Studio expect standard OpenAI-compatible Base64 Data URIs, and stripping this prefix results in an "Invalid url" error. Passing `processedMessages` directly allows LM Studio to correctly parse and process captured screenshots. Co-authored-by: Oxygen-Low <95589118+Oxygen-Low@users.noreply.github.com>
1 parent 0b0588b commit c1e2491

1 file changed

Lines changed: 1 addition & 32 deletions

File tree

server/routes/ai.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,37 +33,6 @@ const DEFAULT_HORDE_MODELS = [
3333
{ provider: "horde", model_id: "Code" },
3434
];
3535

36-
/**
37-
* LM Studio's OpenAI-compatible endpoint currently accepts raw base64 in an
38-
* image_url block, rather than the data URI used by the OpenAI API. Keep the
39-
* data URI for every other provider and only remove its prefix for LM Studio.
40-
*/
41-
const normalizeLmStudioImageUrls = (messages: any[]) =>
42-
messages.map((message) => {
43-
if (!Array.isArray(message.content)) return message;
44-
45-
return {
46-
...message,
47-
content: message.content.map((part: any) => {
48-
if (part?.type !== "image_url") return part;
49-
50-
const url = part.image_url?.url || part.image_url;
51-
if (typeof url !== "string") return part;
52-
53-
const match = url.match(/^data:image\/[a-zA-Z0-9.+-]+;base64,(.+)$/);
54-
if (!match) return part;
55-
56-
return {
57-
...part,
58-
image_url: {
59-
...(typeof part.image_url === "object" ? part.image_url : {}),
60-
url: match[1],
61-
},
62-
};
63-
}),
64-
};
65-
});
66-
6736
export const handleGetLocalProviders: RequestHandler = async (_req, res) => {
6837
const localModels = [...DEFAULT_HORDE_MODELS];
6938

@@ -568,7 +537,7 @@ export const handleProxyAiRequest: RequestHandler = async (req, res) => {
568537
"http://127.0.0.1:1234/v1/chat/completions",
569538
{
570539
model,
571-
messages: normalizeLmStudioImageUrls(processedMessages),
540+
messages: processedMessages,
572541
stream,
573542
},
574543
axiosOptions,

0 commit comments

Comments
 (0)