From 16796f86c91e72121a7d30736216894b81879abb Mon Sep 17 00:00:00 2001 From: Jens Rapp Date: Sun, 18 Aug 2024 10:48:59 +0200 Subject: [PATCH 1/4] feature simple webclient --- examples/simple-webclient/README.md | 62 ++++++++ examples/simple-webclient/webcli.html | 195 ++++++++++++++++++++++++++ 2 files changed, 257 insertions(+) create mode 100644 examples/simple-webclient/README.md create mode 100644 examples/simple-webclient/webcli.html diff --git a/examples/simple-webclient/README.md b/examples/simple-webclient/README.md new file mode 100644 index 00000000..bbf89104 --- /dev/null +++ b/examples/simple-webclient/README.md @@ -0,0 +1,62 @@ +# a really really simple web client + +This is a web Client with almost NO features but a small starting point for +people who want to try for themselves. +It utilizes a simple XmlHttpRequest and prints the output to screen. + +I also implemented the use of marked for highlighting the chat. + +Since there is no on-the-fly-reception, getting an answer may take a while... + +# usage + +## using it locally + +if you just want to try, run firefox in your command line like this: + +``` +$ firefox file:///path/to/ollama/examples/simple-webclient/webcli.html?host=your_hostname +``` + +This opens your browser (eg firefox) and in this case, directly sets ollama host to +_http://your_hostname:11434_. +Default host is either the host where the script runs or just `localhost`. + +For more configuration, see `Configuring` + +## using behind nginx + +The most comfortable way I found was using the cli on nginx. + +! This is only an example. You should use a dedicated site in nginx ! + +Therefore, I just copied webcli.html to /var/www/html/. + +To make it run, you might need to edit the location in `/etc/nginx/sites-available/default` +and add + +``` +... + location / { + ... + add_header 'Access-Control-Allow-Origin' '*'; + ... + } +... +``` + +After that, you need to reload nginx. + +Now, you should be able to access webcli via `http://your_host/webcli.html` + + +## Configuring + +If you want to configure a bit more, just click the "Configure" link below your chat input. +A form opens and you can input hostname, port, whether using https, as well as the used +model, parameters and system input. + +# Todo + +Well, there's still something to do here. Source code formatting would be cool or maybe +saving the configuration somehow.. Feel free.. diff --git a/examples/simple-webclient/webcli.html b/examples/simple-webclient/webcli.html new file mode 100644 index 00000000..ea70b49b --- /dev/null +++ b/examples/simple-webclient/webcli.html @@ -0,0 +1,195 @@ + + + + + My<CR>Ollama + + + + +
+
+
+ + +
+ Configure + +
+
+ + + From 784f2530f9ce1624853b7418ce2cd8a8c155939b Mon Sep 17 00:00:00 2001 From: Jens Rapp Date: Sun, 18 Aug 2024 11:48:31 +0200 Subject: [PATCH 2/4] fix: Enter does not create a new line after sending the data --- examples/simple-webclient/webcli.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/simple-webclient/webcli.html b/examples/simple-webclient/webcli.html index ea70b49b..2c36c1a4 100644 --- a/examples/simple-webclient/webcli.html +++ b/examples/simple-webclient/webcli.html @@ -157,6 +157,7 @@ } function send_form(event) { + event.preventDefault(); const data = JSON.parse(document.getElementById("parameters").value) || {}; data.prompt = document.getElementById("textfield").value; document.getElementById("textfield").value = ""; @@ -170,6 +171,8 @@ // remove the context if (data.prompt == "/clear") { document.getElementById("context").value = "[]"; + append_text("Context has been cleared."); + return; } const xhr = new XMLHttpRequest(); From f6beea3272f4a02e1ac7677cbec8afa012c850aa Mon Sep 17 00:00:00 2001 From: Jens Rapp Date: Sun, 18 Aug 2024 11:51:54 +0200 Subject: [PATCH 3/4] fix: Enter does not create a new line after sending the data --- examples/simple-webclient/webcli.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/simple-webclient/webcli.html b/examples/simple-webclient/webcli.html index 2c36c1a4..5ba7abb7 100644 --- a/examples/simple-webclient/webcli.html +++ b/examples/simple-webclient/webcli.html @@ -159,7 +159,7 @@ function send_form(event) { event.preventDefault(); const data = JSON.parse(document.getElementById("parameters").value) || {}; - data.prompt = document.getElementById("textfield").value; + data.prompt = document.getElementById("textfield").textContent; document.getElementById("textfield").value = ""; data.system = document.getElementById("system").value; data.model = document.getElementById("model").value; From 89d4bf86c7dd33d0c4bd39a9e49e7a3fe1d604e0 Mon Sep 17 00:00:00 2001 From: Jens Rapp Date: Sun, 18 Aug 2024 14:25:50 +0200 Subject: [PATCH 4/4] feature: some cleanup --- examples/simple-webclient/webcli.html | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/examples/simple-webclient/webcli.html b/examples/simple-webclient/webcli.html index 5ba7abb7..bb8c26e3 100644 --- a/examples/simple-webclient/webcli.html +++ b/examples/simple-webclient/webcli.html @@ -63,6 +63,7 @@ background-color: #f0f0fc; } + // todo: format marked @@ -75,7 +76,6 @@
Configure