Add ollama api calls

This commit is contained in:
Akemi Izuko 2024-03-03 01:07:27 -07:00
parent 9f2768acd6
commit bb219b3cad
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC
2 changed files with 41 additions and 2 deletions

View file

@ -6,5 +6,8 @@
"action": {
"default_popup": "src/main.html",
"default_icon": "assets/logo.png"
}
},
"host_permissions": [
"http://localhost/*"
]
}

View file

@ -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
}