Skip to content

Commit

Permalink
fix logic a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
KTibow committed Jan 11, 2025
1 parent 410f28f commit fe0751d
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions src/Chat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,52 @@
export let groqKey: string;
let textarea: HTMLTextAreaElement;
const getModel = async () => {
if (localStorage.model) return localStorage.model;
const hasSpecdec = async () => {
if (localStorage.bamHasSpecdec) return JSON.parse(localStorage.bamHasSpecdec);
const r = await fetch("https://api.groq.com/openai/v1/models", {
headers: {
Authorization: `Bearer ${groqKey}`,
},
});
const models = await r.json();
const model = models.data.find((m) => m.id == "llama-3.3-70b-specdec")
? "llama-3.3-70b-specdec"
: "llama-3.3-70b-versatile";
localStorage.model = model;
return model;
const hasSpecdec = models.data.find((m) => m.id == "llama-3.3-70b-specdec") != undefined;
localStorage.bamHasSpecdec = JSON.stringify(hasSpecdec);
return hasSpecdec;
};
const generate = async (prompt: string) => {
conversation = [...conversation, { role: "user", content: prompt }];
const r = await fetch("https://api.groq.com/openai/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${groqKey}`,
},
body: JSON.stringify({
model: await getModel(),
messages: conversation,
stream: true,
temperature: 0.7,
}),
});
let r: Response;
if (await hasSpecdec()) {
r = await fetch("https://api.groq.com/openai/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${groqKey}`,
},
body: JSON.stringify({
model: "llama-3.3-70b-specdec",
messages: conversation,
stream: true,
temperature: 0.7,
}),
});
}
if (!r || !r.ok) {
r = await fetch("https://api.groq.com/openai/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${groqKey}`,
},
body: JSON.stringify({
model: "llama-3.3-70b-versatile",
messages: conversation,
stream: true,
temperature: 0.7,
}),
});
}
const message = { role: "assistant", content: "" };
conversation = [...conversation, message];
Expand Down

0 comments on commit fe0751d

Please sign in to comment.