Distribute and run LLMs with a single file.
C++ cross-platformggufllama-cpplocal-ailocal-inferencelocal-llmopen-source-aisingle-file-executablespeech-to-text
Display name of model at top of web ui
Justine Tunney38a77c88378d
diff --git a/llamafile/server/flagz.cpp b/llamafile/server/flagz.cppindex 1e81039f..5e6f462e 100644--- a/llamafile/server/flagz.cpp+++ b/llamafile/server/flagz.cpp@@ -18,6 +18,7 @@#include "client.h"#include "llama.cpp/llama.h"#include "llamafile/llamafile.h"+#include "llamafile/string.h"#include "llamafile/server/json.h"namespace lf {@@ -27,6 +28,7 @@ boolClient::flagz(){jt::Json json;+ json["model"] = stripext(basename(FLAG_model));json["prompt"] = FLAG_prompt;json["no_display_prompt"] = FLAG_no_display_prompt;json["nologo"] = FLAG_nologo;diff --git a/llamafile/server/worker.cpp b/llamafile/server/worker.cppindex 668a115c..b04741a4 100644--- a/llamafile/server/worker.cpp+++ b/llamafile/server/worker.cpp@@ -24,6 +24,7 @@#include "llamafile/server/tokenbucket.h"#include "llamafile/threadlocal.h"#include "llamafile/trust.h"+#include <cosmo.h>#include <cassert>#include <exception>#include <pthread.h>@@ -109,7 +110,11 @@ voidWorker::handle(){if ((client_.fd_ = server_->accept(&client_.client_ip_)) == -1) {- SLOG("accept returned %m");+ if (IsWindows() && errno == ENOTSOCK) {+ // Server::shutdown() calls close() on the listening socket+ } else {+ SLOG("accept returned %m");+ }return;}diff --git a/llamafile/server/www/chatbot.js b/llamafile/server/www/chatbot.jsindex f0fc3699..19104f2c 100644--- a/llamafile/server/www/chatbot.js+++ b/llamafile/server/www/chatbot.js@@ -21,6 +21,7 @@ const DEFAULT_SYSTEM_PROMPT ="detailed, and polite answers to the human's questions.";const DEFAULT_FLAGZ = {+ "model": null,"prompt": null,"no_display_prompt": false,"frequency_penalty": 0,@@ -342,6 +343,12 @@ function getSystemPrompt() {return prompt;}+function updateModelInfo() {+ if (flagz.model) {+ document.getElementById("model").textContent = flagz.model;+ }+}+function startChat(history) {chatHistory = history;chatMessages.innerHTML = "";@@ -356,6 +363,7 @@ function startChat(history) {async function chatbot() {flagz = await fetchFlagz();+ updateModelInfo();startChat([{ role: "system", content: getSystemPrompt() }]);sendButton.addEventListener("click", sendMessage);stopButton.addEventListener("click", stopMessage);diff --git a/llamafile/server/www/index.html b/llamafile/server/www/index.htmlindex 8866a784..b01c5fb1 100644--- a/llamafile/server/www/index.html+++ b/llamafile/server/www/index.html@@ -8,7 +8,10 @@<div class="chat-container"><div class="chat-header">- <h1><img src="chatbot.png" alt="[logo]" width="64" height="64"> llamafile</h1>+ <h1>+ <img src="chatbot.png" alt="[llamafile]" title="llamafile" width="64" height="64">+ <span id="model">llamafile</span>+ </h1></div><div class="chat-messages" id="chat-messages"><div class="message system">diff --git a/llamafile/string.cpp b/llamafile/string.cppindex 8462d79d..ef67d581 100644--- a/llamafile/string.cpp+++ b/llamafile/string.cpp@@ -102,6 +102,14 @@ std::string basename(const std::string_view &path) {}}+std::string stripext(const std::string &path) {+ size_t i = path.size();+ while (i--)+ if (path[i] == '.')+ return path.substr(0, i);+ return path;+}+std::string_view extname(const std::string_view &path) {size_t i = path.size();while (i--)diff --git a/llamafile/string.h b/llamafile/string.hindex 5b9b49eb..9a74b235 100644--- a/llamafile/string.h+++ b/llamafile/string.h@@ -33,6 +33,7 @@ std::string format(const char *, ...) __attribute__((format(printf, 1, 2)));std::string iso8601(struct timespec);std::string join(const std::vector<std::string> &, const std::string_view &);std::string resolve(const std::string_view &, const std::string_view &);+std::string stripext(const std::string &);std::string tolower(const std::string_view &);std::string_view extname(const std::string_view &);void append_wchar(std::string *, wchar_t);