Skip to content

Commit

Permalink
feat: vision llama
Browse files Browse the repository at this point in the history
  • Loading branch information
Googlefan committed Jun 6, 2024
1 parent e0aeee8 commit 048163f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/chat/llama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ import { evar } from "../var";

const endpoint = evar("LLAMA_CPP_ENDPOINT");

async function* generate(chat: Chat[], system?: string) {
for (const c of chat) {
if (c.attachment) {
throw new Error("Llama3 does not support attachments");
}
function resolveAttachment(attachment?: {
mime: string;
data: string;
}) {
if (!attachment) {
return;
}
if (["image/png", "image/jpeg", "image/gif"].includes(attachment.mime)) {
return attachment.data;
}
return;
}

async function* generate(chat: Chat[], system?: string) {
if (system) {
chat.unshift({
role: "system",
Expand All @@ -25,6 +33,7 @@ async function* generate(chat: Chat[], system?: string) {
chat.map((c) => ({
content: c.text,
role: c.role,
image: resolveAttachment(c.attachment),
})),
),
});
Expand Down

0 comments on commit 048163f

Please sign in to comment.