Distribute and run LLMs with a single file.
C++ cross-platformggufllama-cpplocal-ailocal-inferencelocal-llmopen-source-aisingle-file-executablespeech-to-text
Sync with bestline upstream
Justine Tunney041a73d5116d
diff --git a/llamafile/bestline.c b/llamafile/bestline.cindex a028c760..56e2b300 100644--- a/llamafile/bestline.c+++ b/llamafile/bestline.c@@ -2008,20 +2008,22 @@ static ssize_t bestlineCompleteLine(struct bestlineState *ls, char *seq, int sizssize_t nread;size_t i, n, stop;bestlineCompletions lc;- struct bestlineState saved;+ struct bestlineState original, saved;nread = 0;memset(&lc, 0, sizeof(lc));- completionCallback(ls->buf, &lc);+ completionCallback(ls->buf, ls->pos, &lc);if (!lc.len) {bestlineBeep();} else {i = 0;stop = 0;+ original = *ls;while (!stop) {/* Show completion or original buffer */if (i < lc.len) {saved = *ls;- ls->len = ls->pos = strlen(lc.cvec[i]);+ ls->len = strlen(lc.cvec[i]);+ ls->pos = original.pos + ls->len - original.len;ls->buf = lc.cvec[i];bestlineRefreshLine(ls);ls->len = saved.len;@@ -2046,7 +2048,8 @@ static ssize_t bestlineCompleteLine(struct bestlineState *ls, char *seq, int sizn = strlen(lc.cvec[i]);if (bestlineGrow(ls, n + 1)) {memcpy(ls->buf, lc.cvec[i], n + 1);- ls->len = ls->pos = n;+ ls->len = n;+ ls->pos = original.pos + n - original.len;}}stop = 1;diff --git a/llamafile/bestline.h b/llamafile/bestline.hindex 73ee564b..0107bdb1 100644--- a/llamafile/bestline.h+++ b/llamafile/bestline.h@@ -8,7 +8,8 @@ typedef struct bestlineCompletions {char **cvec;} bestlineCompletions;-typedef void(bestlineCompletionCallback)(const char *, bestlineCompletions *);+typedef void(bestlineCompletionCallback)(const char *, int,+ bestlineCompletions *);typedef char *(bestlineHintsCallback)(const char *, const char **, const char **);typedef void(bestlineFreeHintsCallback)(void *);typedef unsigned(bestlineXlatCallback)(unsigned);diff --git a/llamafile/chatbot.cpp b/llamafile/chatbot.cppindex 5105840d..984524f5 100644--- a/llamafile/chatbot.cpp+++ b/llamafile/chatbot.cpp@@ -98,7 +98,7 @@ __attribute__((format(printf, 1, 2))) static std::string format(const char *fmt,return res;}-static void on_completion(const char *line, bestlineCompletions *comp) {+static void on_completion(const char *line, int pos, bestlineCompletions *comp) {static const char *const kCompletions[] = {"/context", //"/exit", //