Spaces:
Configuration error
Configuration error
| ```typescript | |
| type Msg = { role: "system" | "user" | "assistant"; content: string }; | |
| export async function llmChat(messages: Msg[]) { | |
| const res = await fetch("http://localhost:11434/api/chat", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ | |
| model: "llama3.1", | |
| messages, | |
| stream: false | |
| }) | |
| }); | |
| if (!res.ok) { | |
| const txt = await res.text().catch(() => ""); | |
| return `Rosalinda: erreur LLM local (${res.status}). ${txt}`; | |
| } | |
| const data: any = await res.json(); | |
| return data?.message?.content ?? "Rosalinda: (réponse vide)"; | |
| } | |
| ``` |