ai-comic-factory / src /app /queries /predictWithGroq.ts
jbilcke-hf's picture
jbilcke-hf HF staff
work on Groq support
a2c0551
raw
history blame
712 Bytes
"use server"
import Groq from "groq-sdk"
export async function predict(inputs: string, nbPanels: number): Promise<string> {
const groqApiKey = `${process.env.AUTH_GROQ_API_KEY || ""}`
const groqApiModel = `${process.env.LLM_GROQ_API_MODEL || "mixtral-8x7b-32768"}`
const groq = new Groq({
apiKey: groqApiKey,
})
const messages: Groq.Chat.Completions.CompletionCreateParams.Message[] = [
{ role: "assistant", content: "" },
]
try {
const res = await groq.chat.completions.create({
messages: messages,
model: groqApiModel,
})
return res.choices[0].message.content || ""
} catch (err) {
console.error(`error during generation: ${err}`)
return ""
}
}