Skip to content

Commit

Permalink
feat: compatible old openai message
Browse files Browse the repository at this point in the history
  • Loading branch information
Hk-Gosuto committed Dec 27, 2023
1 parent 42ee0e0 commit 3782c48
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions app/client/platforms/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,41 @@ export class ChatGPTApi implements LLMApi {
const base64 = Buffer.from(response.data, "binary").toString("base64");
return base64;
};
for (const v of options.messages) {
let message: {
role: string;
content: { type: string; text?: string; image_url?: { url: string } }[];
} = {
role: v.role,
content: [],
};
message.content.push({
type: "text",
text: v.content,
});
if (v.image_url) {
var base64Data = await getImageBase64Data(v.image_url);
if (options.config.model === "gpt-4-vision-preview") {
for (const v of options.messages) {
let message: {
role: string;
content: {
type: string;
text?: string;
image_url?: { url: string };
}[];
} = {
role: v.role,
content: [],
};
message.content.push({
type: "image_url",
image_url: {
url: `data:image/jpeg;base64,${base64Data}`,
},
type: "text",
text: v.content,
});
if (v.image_url) {
var base64Data = await getImageBase64Data(v.image_url);
message.content.push({
type: "image_url",
image_url: {
url: `data:image/jpeg;base64,${base64Data}`,
},
});
}
messages.push(message);
}
messages.push(message);
} else {
options.messages.map((v) =>
messages.push({
role: v.role,
content: v.content,
}),
);
}

const modelConfig = {
Expand Down

0 comments on commit 3782c48

Please sign in to comment.