Created
June 8, 2024 03:47
-
-
Save edutrul/937b7da982c6fb6f2402275d2768e438 to your computer and use it in GitHub Desktop.
AI WITHOUT EXTERNAL APIS IN THE BROWSER https://eduardotelaya.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>MLC AI Web LLM</title> | |
<script type="module"> | |
import { MLCEngine } from "https://esm.run/@mlc-ai/web-llm"; | |
async function initialize() { | |
const selectedModel = "Llama-2-7b-chat-hf-q4f16_1-MLC"; | |
const engine = new MLCEngine(); | |
engine.setInitProgressCallback(console.info); | |
try { | |
await engine.reload(selectedModel); | |
const messages = [ | |
{ role: "system", content: "You are a helpful AI assistant." }, | |
{ role: "user", content: "¡Hola! ¿Cuál es la capital de Francia?" } | |
]; | |
const reply = await engine.chat.completions.create({ messages }); | |
console.log(reply.choices[0].message.content); | |
} catch (error) { | |
console.error('Error al cargar el modelo:', error); | |
} | |
} | |
window.onload = initialize; | |
</script> | |
</head> | |
<body> | |
<h1>MLC AI Web LLM</h1> | |
<p>Abrí la consola para ver la respuesta de la IA</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment