logfilesrefsstats
path: root/toucan.html
diff options
context:
space:
mode:
authorGiacomo <initframs@duck.com>2026-11-21 21:30:10 +0000
committerGiacomo <initframs@duck.com>2026-11-21 21:30:10 +0000
commit0ca76d90ff885ddde0e95453189983fe9c2c6e02 (patch)
treed8552f15ffa38fb014c11b3c5da50ba22695819b /toucan.html
parent48eceaa8e9ea0c9cc0cc29591aa6b8c0fe38ed25 (diff)
first draft
Diffstat (limited to 'toucan.html')
-rw-r--r--toucan.html220
1 files changed, 220 insertions, 0 deletions
diff --git a/toucan.html b/toucan.html
new file mode 100644
index 0000000..bb1ce50
--- /dev/null
+++ b/toucan.html
@@ -0,0 +1,220 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>🦜 toucan</title>
+</head>
+<body>
+<div id="content">
+ <div id="nav">
+ <h1>🦜 toucan</h1>
+ <div>
+ <label for="model">select model:</label>
+ <select id="model"></select>
+ </div>
+ <div>
+ <label for="ollama">ollama address:</label>
+ <input id="ollama" type="text" placeholder="127.0.0.1"/>
+ <button id="connect">connect</button>
+ </div>
+ </div>
+
+ <div id="chat"></div>
+
+ <div id="prompt">
+ <input type="text" id="prompt-input" placeholder="enter a prompt"/>
+ <button id="send">send</button>
+ </div>
+</div>
+<style>
+* {
+ box-sizing: border-box;
+}
+
+html, body {
+ width: 100%;
+ height: 100%;
+ margin: 0;
+ background: #1a1a1a;
+ color: white;
+ font-family:sans-serif;
+}
+
+#content {
+ height: 100dvh;
+ display: flex;
+ flex-direction: column;
+}
+
+#nav {
+ height: 10vh;
+ background: #2a2aa0;
+ display: flex;
+ align-items: center;
+ justify-content: space-evenly;
+ flex-shrink: 0;
+}
+
+#chat {
+ flex: 1;
+ min-height: 0;
+ padding: 20px;
+ overflow-y: auto;
+ font-family:serif;
+}
+
+#prompt {
+ height: 5vh;
+ display: flex;
+ align-items: center;
+ padding: 10px;
+ gap: 10px;
+ flex-shrink: 0;
+}
+
+#prompt input {
+ flex: 1;
+ min-width: 0;
+ height: 100%;
+ padding: 12px 16px;
+ background: #2a2a2a;
+ color: white;
+ border: 1px solid #1a1a1a;
+ border-radius: 5px;
+ outline: none;
+}
+
+#prompt input:focus {
+ border-color: #2a2aa0;
+}
+
+#prompt button {
+ width: 20%;
+ height: 100%;
+ background: #2a2aa0;
+ color: white;
+ border: none;
+ border-radius: 5px;
+ cursor: pointer;
+}
+
+#prompt button:hover {
+ background: #3838bb;
+}
+
+.user {
+ color:#ff6464;
+ font-size:20px;
+}
+</style>
+<script type="module">
+import { Ollama } from 'https://esm.sh/ollama/browser';
+
+const ollamalocation = document.getElementById("ollama");
+
+let ollama;
+
+const connectButton = document.getElementById("connect");
+
+connectButton.addEventListener("click", async () => {
+ ollama = new Ollama({
+ host: 'http://' + ollamalocation.value + ":11434"
+ });
+
+ try {
+ model.innerHTML = "";
+ await loadModels();
+ addMessage("assistant", "connected to ollama");
+ } catch (error) {
+ addMessage("assistant", "could not connect: " + error.message);
+ }
+});
+
+const model = document.getElementById("model");
+const chat = document.getElementById("chat");
+const promptInput = document.getElementById("prompt-input");
+const sendButton = document.getElementById("send");
+
+let messages = [];
+
+async function loadModels() {
+ const result = await ollama.list();
+
+ result.models.forEach(m => {
+ const option = document.createElement("option");
+ option.value = m.name;
+ option.textContent = m.name;
+ model.appendChild(option);
+ });
+}
+
+function addMessage(role, content = "") {
+ const message = document.createElement("div");
+ message.className = role;
+ message.textContent = content;
+
+ const br = document.createElement("br");
+
+ chat.appendChild(message);
+ chat.appendChild(br);
+ return message;
+}
+
+async function sendMessage() {
+ const text = promptInput.value.trim();
+
+ if (!text || !model.value || sendButton.disabled) return;
+
+ promptInput.value = "";
+
+ addMessage("user", text);
+
+ messages.push({
+ role: "user",
+ content: text
+ });
+
+ const reply = addMessage("assistant");
+ const assistantMessage = {
+ role: "assistant",
+ content: ""
+ };
+
+ sendButton.disabled = true;
+
+ try {
+ const response = await ollama.chat({
+ model: model.value,
+ messages: messages,
+ stream: true
+ });
+
+ for await (const part of response) {
+ const token = part.message.content;
+
+ assistantMessage.content += token;
+ reply.textContent += token;
+ }
+
+ messages.push(assistantMessage);
+
+ } catch (error) {
+ reply.textContent = `error: ${error.message}`;
+ }
+
+ sendButton.disabled = false;
+ promptInput.focus();
+}
+
+sendButton.addEventListener("click", sendMessage);
+
+promptInput.addEventListener("keydown", event => {
+ if (event.key === "Enter") {
+ sendMessage();
+ }
+});
+</script>
+
+</body>
+</html> \ No newline at end of file