Skip to content

Commit

Permalink
Display name of model at top of web ui
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Nov 23, 2024
1 parent 12c3761 commit 38a77c8
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions llamafile/server/flagz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -27,6 +28,7 @@ bool
Client::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;
Expand Down
7 changes: 6 additions & 1 deletion llamafile/server/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -109,7 +110,11 @@ void
Worker::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;
}

Expand Down
8 changes: 8 additions & 0 deletions llamafile/server/www/chatbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = "";
Expand All @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion llamafile/server/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
8 changes: 8 additions & 0 deletions llamafile/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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--)
Expand Down
1 change: 1 addition & 0 deletions llamafile/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 38a77c8

Please sign in to comment.