From bb219b3cad19b428686d6aaade2614b029060e9a Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Sun, 3 Mar 2024 01:07:27 -0700 Subject: [PATCH] Add ollama api calls --- manifest.json | 5 ++++- src/main.js | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 7e19909..59fcf16 100644 --- a/manifest.json +++ b/manifest.json @@ -6,5 +6,8 @@ "action": { "default_popup": "src/main.html", "default_icon": "assets/logo.png" - } + }, + "host_permissions": [ + "http://localhost/*" + ] } diff --git a/src/main.js b/src/main.js index 0fa4e87..3bb5c60 100644 --- a/src/main.js +++ b/src/main.js @@ -1 +1,37 @@ -console.log("Popup") +const ollama_get_models = async () => { + const res = await fetch('http://localhost:11434/api/tags') + + if (res.status !== 200) { + console.error("Failed to make request to Ollama") + return + } + + const js = await res.json() + return js +} + +const ollama_chat_complete = async (model, messages) => { + const body = { + model: "gemmachad:latest", + messages: { role: "user", content: "why is the sky blue?" }, + stream: false + } + + console.log(body) + + const res = await fetch('http://localhost:11434/api/chat', { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(body) + }) + + if (res.status !== 200) { + console.error("Failed to make request to Ollama") + return + } + + const js = await res.json() + return js +}