-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const apiUrl = 'http://127.0.0.1:11434/api/generate' | ||
|
||
async function handlePromptInput() { | ||
const inputText = document.getElementById('inputArea').value | ||
document.getElementById('displayArea').innerHTML += `<p><span class="who">You:</span> <span class="text">${inputText}</span></p>` | ||
console.log('Awaiting response...') | ||
document.getElementById('inputArea').value = '' | ||
const result = await createPrompt(inputText) | ||
console.log('Got response:', result) | ||
document.getElementById('displayArea').innerHTML += `<p><span class="who">Bot:</span> ${result.response}</span></p>` | ||
} | ||
|
||
async function createPrompt(message) { | ||
|
||
const controller = new AbortController() | ||
const timeoutId = setTimeout(() => { | ||
return controller.abort() | ||
}, 18000) | ||
|
||
const requestData = { | ||
model: 'phi3', | ||
stream: false, | ||
prompt: message | ||
} | ||
|
||
const requestOptions = { | ||
method: 'POST', // request method (GET, POST, PUT, DELETE, etc.) | ||
headers: { | ||
'Content-Type': 'application/json' // type of content in request body | ||
}, | ||
body: JSON.stringify(requestData), // convert requestData to JSON-format | ||
signal: controller.signal | ||
} | ||
|
||
try { | ||
return fetch(apiUrl, requestOptions).then((res) => res.json()) | ||
.then(data => data) | ||
} catch (error) { | ||
console.error(error) | ||
return { response: error.message } | ||
} finally { | ||
clearTimeout(timeoutId) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Ollama chatbot frontend</title> | ||
<script src="chatbotIO.js"></script> | ||
<style> | ||
body { | ||
font-family: Arial, Helvetica, sans-serif; | ||
font-size: 1.2rem; | ||
} | ||
p { | ||
margin-bottom: 10px; | ||
} | ||
.who { | ||
color: green; | ||
font-weight: 700; | ||
} | ||
.text { | ||
color: black; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h2>Chat</h2> | ||
<div id="displayArea"></div> | ||
<textarea id="inputArea" rows="4" cols="50"></textarea> | ||
<br /> | ||
<button onclick="handlePromptInput()">Submit</button> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Hvordan sette opp en chatbot på din egen maksin | ||
|
||
1. Last ned og staller Ollama: https://ollama.com/ | ||
a. Hvorfor heter dette "Ollama"?? | ||
2. Åpne ledetekst/cmd, og skriv ollama run tinyllama | ||
3. Booom! Du har din egen chatbot!! | ||
|
||
Funker? Vi skal nå kjøre Ollama som en server: | ||
|
||
Lukk cmd-vindet, åpne et nytt. Skriv inn følgende, en linje av gangen. | ||
|
||
NB: Du må også åpne et nytt cmd-vindu før du kaller `ollama serve` | ||
|
||
## Windows 10 | ||
|
||
``` | ||
set OLLAMA_ORIGINS=* | ||
set OLLAMA_HOST=127.0.0.1:11434 | ||
ollama serve | ||
``` | ||
|
||
## Windows 11 (Powershell) | ||
|
||
``` | ||
setx OLLAMA_ORIGINS * | ||
setx OLLAMA_HOST 127.0.0.1:11434 | ||
ollama serve | ||
``` | ||
|
||
Etter å ha gjort dette, må du åpne | ||
|
||
Bruke Ollama-APIet, her finner du dokumentasjon: https://github.com/ollama/ollama/blob/main/docs/api.md | ||
|
||
Koden under burde hjelpe deg i å komme i gang med API-et. Lag din egen KI-chat. Lykke til! | ||
|
||
```js | ||
const apiUrl = 'http://127.0.0.1:11434/api/generate' | ||
|
||
function createPrompt(message) { | ||
const requestData = { | ||
model: 'tinyllama', // must exist on the server (your computer) | ||
stream: false, | ||
prompt: message | ||
} | ||
|
||
const requestOptions = { | ||
method: 'POST', // request method (GET, POST, PUT, DELETE, etc.) | ||
headers: { | ||
'Content-Type': 'application/json' // type of content in request body | ||
}, | ||
body: JSON.stringify(requestData), // convert requestData to JSON-format | ||
signal: controller.signal | ||
} | ||
fetch(apiUrl, requestOptions) | ||
.then((response) => { | ||
console.log(response) | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok') | ||
} | ||
return response.json() // convert response to JSON-format | ||
}) | ||
.then((result) => { | ||
console.log(result) // this is the actual result | ||
}) | ||
.catch((error) => { | ||
console.error('There was a problem with the fetch operation:', error) | ||
}) | ||
} | ||
``` |
Empty file modified
0
3 - Objektorientert programmering/Avsluttende prosjekt/51 - Avsluttende oppgave.md
100755 → 100644
Empty file.
Empty file modified
0
3 - Objektorientert programmering/Forandre eksisterende kode/Eksamen h23 oppg 12.md
100755 → 100644
Empty file.
Empty file modified
0
3 - Objektorientert programmering/monster-generator/.gitignore
100755 → 100644
Empty file.
Empty file modified
0
3 - Objektorientert programmering/monster-generator/.vscode/extensions.json
100755 → 100644
Empty file.
Empty file.
Empty file modified
0
3 - Objektorientert programmering/monster-generator/index.html
100755 → 100644
Empty file.
Empty file modified
0
3 - Objektorientert programmering/monster-generator/jsconfig.json
100755 → 100644
Empty file.
Empty file modified
0
3 - Objektorientert programmering/monster-generator/package.json
100755 → 100644
Empty file.
Empty file modified
0
3 - Objektorientert programmering/monster-generator/public/vite.svg
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified
0
3 - Objektorientert programmering/monster-generator/src/App.svelte
100755 → 100644
Empty file.
Empty file modified
0
3 - Objektorientert programmering/monster-generator/src/app.css
100755 → 100644
Empty file.
Empty file modified
0
3 - Objektorientert programmering/monster-generator/src/assets/svelte.svg
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified
0
3 - Objektorientert programmering/monster-generator/src/lib/Monster.js
100755 → 100644
Empty file.
Empty file modified
0
3 - Objektorientert programmering/monster-generator/src/main.js
100755 → 100644
Empty file.
Empty file modified
0
3 - Objektorientert programmering/monster-generator/src/vite-env.d.ts
100755 → 100644
Empty file.
Empty file modified
0
3 - Objektorientert programmering/monster-generator/svelte.config.js
100755 → 100644
Empty file.
Empty file modified
0
3 - Objektorientert programmering/monster-generator/vite.config.js
100755 → 100644
Empty file.
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
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.