Skip to content

armgit / janas

Public Imported from GitHub
0

37 tok/s from Qwen3-Next-80B (48 GB) on a 32 GB laptop, 24 without drafts vs 2.8 for llama.cpp; reading 62 vs 16 tok/s. Faster than llama.cpp on all 13 models compared in Q4_K_M. LLMs bigger than your RAM, pure C, CPU or GPU.

Release 2026-10-12 (4): janas-bench takes a model by name, from the list, or a file

camauri98c8300c00c9
diff --git a/.github/ISSUE_TEMPLATE/01-hardware-report.yml b/.github/ISSUE_TEMPLATE/01-hardware-report.yml
index 964e9c3..d1bf983 100644
--- a/.github/ISSUE_TEMPLATE/01-hardware-report.yml
+++ b/.github/ISSUE_TEMPLATE/01-hardware-report.yml
@@ -13,9 +13,14 @@ body:
and the editor first, or the numbers are partly about them:
```sh
- bin/x86_64-linux/janas-bench <model.jns>
+ bin/x86_64-linux/janas-bench <model>
```
+ `<model>` is a name of the models Janas knows (`qwen3-4b`; with
+ none it shows the list and downloads the one you choose) or a
+ `.jns` file. From the binary package: `./janas-bench <model>`, on
+ Windows `.\janas-bench <model>`.
+
It leaves a `janas-bench-<date>.txt` in the current directory. That
file already carries the CPU, the core layout, the GPU if there is one,
and the speed of every configuration tried; the questions below are the
diff --git a/ChangeLog.md b/ChangeLog.md
index 0d6d4b1..ac85c55 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -2,6 +2,10 @@
> Curated, user-facing summary of completed work, newest first.
+## [2026-10-12] - janas-bench takes a model by name
+
+- **`janas-bench` takes the model as `janas-chat` does**: a name of the models Janas knows (`janas-bench qwen3-4b`), downloaded after asking if it is not there yet; with no model, the list to choose from; a `.jns` file as before. The model's prediction file comes with it as in the chat - the one the catalog names, or for another file the one beside it - so the drafts are measured as the chat uses them; `--no-mtp` leaves it out, `--models` says where the models are. Both programs share one way of finding a model (`src/common/model_pick.c`).
+
## [2026-10-12] - Janas on Windows
- **The same sources build for Windows x86-64**, with MinGW-w64 from Linux (`JANAS_OS=windows ./build.sh`): every program, the two libraries as DLLs, Janas's services (janas-system with Windows's own calls), the GPU through Vulkan; nothing needed but Windows's own DLLs. Run on Windows 11 (build 26300) on the development laptop on 12 October 2026: all 31 tests pass, and with the same files and commands as on Linux it writes as fast (Qwen3-4B 25.6 tok/s against 27, Qwen3-30B-A3B 34.2 against 32) and reads a prompt of 1,024 tokens as fast with the mixture (Qwen3-30B-A3B 132 against 135) and 1.8 times as fast with the dense model (Qwen3-4B 346 against 193), whose whole blocks go to the GPU, there through Intel's own driver.
diff --git a/INSTALL.md b/INSTALL.md
index e0a8ddf..76ed829 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -84,10 +84,10 @@ The engine tunes itself while it runs: it tries the configurations your machine
## Measuring your machine
```sh
-bin/x86_64-linux/janas-bench qwen3-next.jns --mtp qwen3-next-mtp.jns
+bin/x86_64-linux/janas-bench qwen3-next-80b-a3b
```
-It takes a few minutes: it measures prompt processing and generation speed for every configuration, fills the tuning profile (so chatting starts tuned) and writes a report, `janas-bench-<date>.txt`, in the current directory. The report lists your processor, memory, GPU, the speeds and the choices: send it along with any feedback.
+The model is a name of the catalog, downloaded after asking if it is not there yet, with its prediction file; a `.jns` file works too, and with no model it shows the list. It takes a few minutes: it measures prompt processing and generation speed for every configuration, fills the tuning profile (so chatting starts tuned) and writes a report, `janas-bench-<date>.txt`, in the current directory. The report lists your processor, memory, GPU, the speeds and the choices: send it along with any feedback.
## Troubleshooting
diff --git a/dist/README-windows.md b/dist/README-windows.md
index 192993a..e8a4d90 100644
--- a/dist/README-windows.md
+++ b/dist/README-windows.md
@@ -32,9 +32,10 @@ In a terminal (Windows Terminal, PowerShell or the Command Prompt), in the folde
.\janas-get list
.\janas-get qwen3-4b
.\janas-chat qwen3-4b
+.\janas-bench qwen3-4b
```
-The first says which models it knows, their size and the memory they want; the second downloads one, checked, into `%LOCALAPPDATA%\janas\models`; the third talks to it.
+The first says which models it knows, their size and the memory they want; the second downloads one, checked, into `%LOCALAPPDATA%\janas\models`; the third talks to it; the fourth measures how fast this machine runs it and writes a report to send back.
`.\janas-chat` with no model shows the list and downloads the one you choose, after asking. The models come already converted from Hugging Face ([prabanta-dev](https://huggingface.co/prabanta-dev)), each file checked against the fingerprints of `MODELS.md`.
diff --git a/dist/README.md b/dist/README.md
index e2a232a..2b35434 100644
--- a/dist/README.md
+++ b/dist/README.md
@@ -28,6 +28,7 @@ Janas-LLM, the inference engine of Janas, runs large language models on ordinary
./janas-get list # the models it knows, their size, the memory they want
./janas-get qwen3-4b # downloads it, checked, into ~/.local/share/janas/models
./janas-chat qwen3-4b # and talk to it
+./janas-bench qwen3-4b # how fast this machine runs it: a report to send back
```
`./janas-chat` with no model shows the list and downloads the one you choose, after asking. The models come already converted from Hugging Face ([prabanta-dev](https://huggingface.co/prabanta-dev)), each file checked against the fingerprints of `MODELS.md`.
diff --git a/docs/hardware.md b/docs/hardware.md
index 4c06ce8..55867c2 100644
--- a/docs/hardware.md
+++ b/docs/hardware.md
@@ -3,10 +3,10 @@
## Measuring your machine
```sh
-bin/x86_64-linux/janas-bench qwen3-next.jns
+bin/x86_64-linux/janas-bench qwen3-4b
```
-Close what you can before running it: it measures the machine you give it, and a browser with thirty tabs is part of the machine. It tries the configurations the machine offers — how many threads, which cores, with and without the GPU — on real passes of the model, keeps the fastest, writes them into `~/.cache/janas` so the next start begins from them, and leaves a report in the current directory. On the development laptop that report says, among other things (10 October 2026, ten models), that a single token and a prompt go fastest on the performance cores' 12 threads, while a draft check - a few tokens at once - goes fastest on all the usable cores: the kinds of pass want different threads, which is why each is tuned on its own.
+It takes the model as `janas-chat` does: a name of the models Janas knows (downloaded, after asking, if it is not there yet), a `.jns` file, or nothing, and then the list to choose from; the model's prediction file comes with it as in the chat (`--no-mtp`: without). Close what you can before running it: it measures the machine you give it, and a browser with thirty tabs is part of the machine. It tries the configurations the machine offers — how many threads, which cores, with and without the GPU — on real passes of the model, keeps the fastest, writes them into `~/.cache/janas` so the next start begins from them, and leaves a report in the current directory. On the development laptop that report says, among other things (10 October 2026, ten models), that a single token and a prompt go fastest on the performance cores' 12 threads, while a draft check - a few tokens at once - goes fastest on all the usable cores: the kinds of pass want different threads, which is why each is tuned on its own.
## Helping it run on more hardware
@@ -24,10 +24,10 @@ It builds Janas and runs its tests, downloads a model from Hugging Face (checkin
**What to send, by hand.** Run the benchmark and attach the report it writes (a `janas-bench-<date>.txt` in the current directory):
```sh
-bin/x86_64-linux/janas-bench <model.jns>
+bin/x86_64-linux/janas-bench <model>
```
-The report already carries the CPU's name, the core layout, the GPU if there is one, and the speed of every configuration tried. Add:
+`<model>` is a name from the list `janas-bench` shows when given none (`qwen3-4b`), or a `.jns` file. The report already carries the CPU's name, the core layout, the GPU if there is one, and the speed of every configuration tried. Add:
- the **distribution** and kernel (`uname -a`), and the **RAM** (`free -g`);
- the **disk** the model sits on (NVMe? SATA? over USB?);
diff --git a/src/bench/main.c b/src/bench/main.c
index 2a4c3b4..d60d9de 100644
--- a/src/bench/main.c
+++ b/src/bench/main.c
@@ -7,15 +7,21 @@
* makes from them. The measurements also fill the engine's tuning profile
* (~/.cache/janas/), so the next start is tuned already.
*
- * Usage: janas-bench <model.jns> [--mtp <file>] [--prompt <tokens>]
- * [--gen <tokens>] [--ctx <tokens>] [--cache <GiB>]
- * [--reserve <GiB>]
+ * Usage: janas-bench [<model>] [--models <dir>] [--mtp <file> | --no-mtp]
+ * [--prompt <tokens>] [--gen <tokens>] [--ctx <tokens>]
+ * [--cache <GiB>] [--reserve <GiB>]
* [--rounds <n>] (default 3, alternating the order)
* [--settle <seconds>] (after the warm-up, wait up to
* that long for the cache's background filling to end:
* the configurations measured on a warm cache, as a
* chat runs after its first minutes)
*
+ * The model is taken as janas-chat takes it (common/model_pick.c): a .jns
+ * file, a name of the catalog (qwen3-4b), downloaded if it is not there
+ * yet, or nothing, and then the list to choose from. Its prediction file
+ * comes with it as in the chat: the one the catalog names, or for a file
+ * of no catalog the one found beside it (--no-mtp: without).
+ *
* The prompt is prose that does not repeat itself (only a prompt longer
* than the text repeats it, and the report says so). The drafts of the
* prediction block are measured as a chat uses them: a question in the
@@ -35,6 +41,7 @@
#include <time.h>
#include "common/env_names.h"
+#include "common/model_pick.h"
#include "common/sysinfo.h"
#include "common/words.h"
#include "janas/llm.h"
@@ -180,11 +187,15 @@ static int measure_chat(janas_llm *llm, uint32_t n_gen, int sampled,
int main(int argc, char **argv)
{
janas_env_check("janas-bench");
- if (argc < 2 || argv[1][0] == '-') {
- fprintf(stderr, "usage: janas-bench <model.jns> [--mtp <file>] "
- "[--prompt <tokens>] [--gen <tokens>] [--ctx <tokens>] "
- "[--cache <GiB>] [--reserve <GiB>] [--rounds <n>] "
- "[--settle <seconds>]\n");
+ if (argc > 1 &&
+ (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0)) {
+ fprintf(stderr,
+ "usage: janas-bench [<model>] [--models <dir>] "
+ "[--mtp <file> | --no-mtp] [--prompt <tokens>] "
+ "[--gen <tokens>] [--ctx <tokens>] [--cache <GiB>] "
+ "[--reserve <GiB>] [--rounds <n>] [--settle <seconds>]\n"
+ "<model>: a .jns file, or a name of the models Janas knows "
+ "(downloaded if it is not there yet); none: the list\n");
return 2;
}
struct janas_llm_params p;
@@ -194,16 +205,30 @@ int main(int argc, char **argv)
uint32_t n_prompt = 256, n_gen = 64;
int rounds = 3;
long long settle = 0;
- static const char *const options[] = {"--mtp", "--prompt", "--gen",
- "--ctx", "--rounds", "--cache",
- "--reserve", "--settle"};
- for (int i = 2; i < argc; i += 2) {
+ const char *model = NULL, *models = NULL;
+ int no_mtp = 0;
+ static const char *const options[] = {
+ "--mtp", "--no-mtp", "--models", "--prompt", "--gen",
+ "--ctx", "--rounds", "--cache", "--reserve", "--settle"};
+ for (int i = 1; i < argc; i += 2) {
const char *a = argv[i], *v = i + 1 < argc ? argv[i + 1] : NULL;
char why[200] = "";
long long x = 0;
double r = 0;
+ if (a[0] != '-' && !model) {
+ model = a;
+ i--;
+ continue;
+ }
+ if (strcmp(a, "--no-mtp") == 0) {
+ no_mtp = 1;
+ i--;
+ continue;
+ }
if (strcmp(a, "--mtp") == 0 && v)
p.mtp_path = v;
+ else if (strcmp(a, "--models") == 0 && v)
+ models = v;
else if (strcmp(a, "--prompt") == 0 || strcmp(a, "--gen") == 0 ||
strcmp(a, "--ctx") == 0 || strcmp(a, "--rounds") == 0) {
if (janas_word_int(v, 1, UINT32_MAX, &x, why, sizeof why) == 0) {
@@ -239,6 +264,25 @@ int main(int argc, char **argv)
"context\n");
return 2;
}
+ if (no_mtp && p.mtp_path) {
+ fprintf(stderr, "janas-bench: --mtp and --no-mtp together\n");
+ return 2;
+ }
+ if (models)
+ setenv("JANAS_MODELS", models, 1);
+ struct janas_model_pick mp;
+ if (janas_model_pick("janas-bench", model, &mp) != 0)
+ return 1;
+ static char mtp_found[4400];
+ if (!p.mtp_path && !no_mtp &&
+ janas_model_pick_mtp(&mp, mtp_found, sizeof(mtp_found))) {
+ p.mtp_path = mtp_found;
+ const char *b = strrchr(mtp_found, '/');
+ fprintf(stderr,
+ "multi-token prediction from %s, found beside the model "
+ "(--no-mtp: without)\n",
+ b ? b + 1 : mtp_found);
+ }
char path[512], stamp[32];
time_t tt = time(NULL);
@@ -265,7 +309,7 @@ int main(int argc, char **argv)
mains < 0 ? "unknown" : (mains ? "mains" : "battery"));
janas_llm *llm;
- if (janas_llm_open(argv[1], &p, &llm) != JANAS_LLM_OK) {
+ if (janas_llm_open(mp.path, &p, &llm) != JANAS_LLM_OK) {
out("cannot open the model: %s\n", janas_llm_last_error());
return 1;
}
diff --git a/src/chat/main.c b/src/chat/main.c
index 9a03980..f92d31d 100644
--- a/src/chat/main.c
+++ b/src/chat/main.c
@@ -30,6 +30,7 @@
#include <unistd.h>
#include "common/env_names.h"
+#include "common/model_pick.h"
#include "common/sysinfo.h"
#include "common/words.h"
#include "edit.h"
@@ -37,7 +38,7 @@
#include "janas/llm.h"
#include "markdown.h"
#include "mcp_chat.h"
-#include "models.h"
+#include "options.h"
#include "tune.h"
#include "scroll.h"
#include "term.h"
@@ -1612,9 +1613,15 @@ int main(int argc, char **argv)
where = chat_words_last(cn, cw, "--models");
if (where)
setenv("JANAS_MODELS", where, 1);
- struct chat_model cm;
- if (chat_model_resolve(marg, &cm) != 0)
+ struct janas_model_pick cm;
+ if (janas_model_pick("janas-chat", marg, &cm) != 0)
return 1;
+ if (cm.entry && cm.entry->test_only)
+ fprintf(stderr,
+ "note: %s is a test model of the engine, not for chatting: "
+ "its answers are often wrong (janas-chat with no model lists "
+ "the others)\n",
+ cm.entry->name);
char mpath[1024];
char **mw = conf_path(mpath, sizeof(mpath), 0, cm.key) == 0
? conf_read(mpath, &mn, &mconf_text)
@@ -1696,9 +1703,9 @@ int main(int argc, char **argv)
int have = access(tpath, F_OK) == 0;
int go = tune == 1;
if (!go && !have && isatty(STDIN_FILENO) && isatty(STDERR_FILENO)) {
- go = chat_ask_yes("Measure how this model runs fastest on this "
- "machine (a reply or two each way, a minute "
- "or so on a large model)?");
+ go = janas_ask_yes("Measure how this model runs fastest on this "
+ "machine (a reply or two each way, a minute "
+ "or so on a large model)?");
if (!go) { /* asked once: the answer is kept */
FILE *f = fopen(tpath, "w");
if (f) {
@@ -1712,10 +1719,10 @@ int main(int argc, char **argv)
struct janas_llm_params probe = mp;
static char probe_mtp[4096], probe_draft[4096];
if (!probe.mtp_path && !probe.draft_path && !no_mtp &&
- !(probe.draft_path =
- chat_model_draft(&cm, probe_draft, sizeof(probe_draft))))
+ !(probe.draft_path = janas_model_pick_draft(
+ &cm, probe_draft, sizeof(probe_draft))))
probe.mtp_path =
- chat_model_mtp(&cm, probe_mtp, sizeof(probe_mtp));
+ janas_model_pick_mtp(&cm, probe_mtp, sizeof(probe_mtp));
chat_tune_run(cm.path, &probe, &cp, gpu, dims, tpath);
}
int tn = 0;
@@ -1751,12 +1758,12 @@ int main(int argc, char **argv)
no_mtp = 1;
if (!mp.mtp_path && !mp.draft_path && !no_mtp &&
(mp.draft_path =
- chat_model_draft(&cm, draft_found, sizeof(draft_found))))
+ janas_model_pick_draft(&cm, draft_found, sizeof(draft_found))))
fprintf(stderr,
"drafts from %s, as the catalog says (--no-mtp: without)\n",
cm.entry->draft);
if (!mp.mtp_path && !mp.draft_path && !no_mtp &&
- chat_model_mtp(&cm, mtp_found, sizeof(mtp_found))) {
+ janas_model_pick_mtp(&cm, mtp_found, sizeof(mtp_found))) {
mp.mtp_path = mtp_found;
const char *b = strrchr(mtp_found, '/');
fprintf(stderr,
diff --git a/src/chat/options.c b/src/chat/options.c
new file mode 100644
index 0000000..f0d4ef5
--- /dev/null
+++ b/src/chat/options.c
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later
+ Copyright (C) 2026 Maurizio Cammalleri */
+/*
+ * options.c - janas-chat's options: those of the command line and of its
+ * settings files (see options.h).
+ */
+#include "options.h"
+
+#include <string.h>
+
+const char *chat_words_last(int n, char *const *w, const char *opt)
+{
+ const char *v = NULL;
+ for (int i = 0; i + 1 < n; i++)
+ if (strcmp(w[i], opt) == 0)
+ v = w[i + 1];
+ return v;
+}
+
+int chat_words_any(int n, char *const *w, const char *const *opts)
+{
+ for (int i = 0; i < n; i++)
+ for (int k = 0; opts[k]; k++)
+ if (strcmp(w[i], opts[k]) == 0)
+ return 1;
+ return 0;
+}
diff --git a/src/chat/options.h b/src/chat/options.h
new file mode 100644
index 0000000..9f31834
--- /dev/null
+++ b/src/chat/options.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later
+ Copyright (C) 2026 Maurizio Cammalleri */
+/*
+ * options.h - janas-chat's options: those of the command line and of its
+ * settings files, looked through for an option.
+ */
+#ifndef JANAS_CHAT_OPTIONS_H
+#define JANAS_CHAT_OPTIONS_H
+
+/* The value of the last opt among n words, or NULL. */
+const char *chat_words_last(int n, char *const *w, const char *opt);
+
+/* 1 if one of the n words is one of opts (NULL-terminated). */
+int chat_words_any(int n, char *const *w, const char *const *opts);
+
+#endif
diff --git a/src/chat/models.c b/src/common/model_pick.c
similarity index 74%
rename from src/chat/models.c
rename to src/common/model_pick.c
index 9bdc300..eb3e9c3 100644
--- a/src/chat/models.c
+++ b/src/common/model_pick.c
@@ -1,10 +1,11 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
Copyright (C) 2026 Maurizio Cammalleri */
/*
- * models.c - janas-chat's models by name (see models.h).
+ * model_pick.c - a model by name, for janas-chat and janas-bench (see
+ * model_pick.h).
*/
#define _GNU_SOURCE
-#include "models.h"
+#include "common/model_pick.h"
#include <stdio.h>
#include <stdlib.h>
@@ -39,7 +40,7 @@ static char *ask_line(const char *question, char *buf, size_t len)
return buf;
}
-int chat_ask_yes(const char *question)
+int janas_ask_yes(const char *question)
{
char b[64];
fprintf(stderr, "%s [y/N] ", question);
@@ -49,7 +50,7 @@ int chat_ask_yes(const char *question)
return b[0] == 'y' || b[0] == 'Y';
}
-static void set_key(struct chat_model *cm, const char *base)
+static void set_key(struct janas_model_pick *cm, const char *base)
{
snprintf(cm->key, sizeof(cm->key), "%s", base);
size_t n = strlen(cm->key);
@@ -60,7 +61,7 @@ static void set_key(struct chat_model *cm, const char *base)
/* The catalog's chat models, numbered from 1, with what is already here. */
static void list(const char *dir)
{
- fprintf(stderr, "The models janas-chat knows (in %s):\n\n", dir);
+ fprintf(stderr, "The models Janas knows (in %s):\n\n", dir);
int k = 0;
for (int i = 0; i < janas_catalog_n; i++) {
const struct janas_model_entry *m = &janas_catalog[i];
@@ -88,7 +89,8 @@ static const struct janas_model_entry *nth(int k)
}
/* janas-get, beside this program, for the model into dir; 0 if it made it */
-static int fetch(const struct janas_model_entry *m, const char *dir)
+static int fetch(const char *prog, const struct janas_model_entry *m,
+ const char *dir)
{
char self[4096], tool[4200];
if (janas_exe_path(self, sizeof self) < 0)
@@ -103,7 +105,7 @@ static int fetch(const struct janas_model_entry *m, const char *dir)
char err[256];
if (janas_proc_start(&pr, argv, NULL, NULL, -1, -1, -1, 0, err,
sizeof err) != 0) {
- fprintf(stderr, "janas-chat: cannot start %s\n", tool);
+ fprintf(stderr, "%s: cannot start %s\n", prog, tool);
return -1;
}
int code = -1;
@@ -113,10 +115,10 @@ static int fetch(const struct janas_model_entry *m, const char *dir)
/*
* The folder for a first download: the proposed one, or another the user
- * types - and then a word on how janas-chat will find it again, since only
- * JANAS_MODELS or --models tell it.
+ * types - and then a word on how the programs will find it again, since
+ * only JANAS_MODELS or --models tell them.
*/
-static int choose_dir(char *dir, size_t len)
+static int choose_dir(const char *prog, char *dir, size_t len)
{
const char *e = getenv("JANAS_MODELS");
if ((e && *e) || is_dir(dir) || !isatty(STDIN_FILENO))
@@ -129,14 +131,15 @@ static int choose_dir(char *dir, size_t len)
if (b[0]) {
snprintf(dir, len, "%s", b);
fprintf(stderr,
- "Note: janas-chat looks in %s only when told - start it with "
+ "Note: %s looks in %s only when told - start it with "
"--models %s, or set JANAS_MODELS=%s.\n",
- dir, dir, dir);
+ prog, dir, dir, dir);
}
return 0;
}
-int chat_model_resolve(const char *arg, struct chat_model *cm)
+int janas_model_pick(const char *prog, const char *arg,
+ struct janas_model_pick *cm)
{
memset(cm, 0, sizeof(*cm));
if (arg && is_file(arg)) {
@@ -155,12 +158,13 @@ int chat_model_resolve(const char *arg, struct chat_model *cm)
return 0;
}
if (arg && (strchr(arg, '/') || strstr(arg, ".jns"))) {
- fprintf(stderr, "janas-chat: there is no file %s\n", arg);
+ fprintf(stderr, "%s: there is no file %s\n", prog, arg);
return -1;
}
if (janas_models_dir(cm->dir, sizeof(cm->dir)) != 0) {
- fprintf(stderr, "janas-chat: no home directory for the models: give "
- "a model's path\n");
+ fprintf(stderr,
+ "%s: no home directory for the models: give a model's path\n",
+ prog);
return -1;
}
const struct janas_model_entry *m = NULL;
@@ -168,14 +172,13 @@ int chat_model_resolve(const char *arg, struct chat_model *cm)
m = janas_catalog_find(arg);
if (!m || m->not_chat) {
fprintf(stderr,
- "janas-chat: no model called %s (janas-chat with no "
- "model lists them)\n",
- arg);
+ "%s: no model called %s (%s with no model lists them)\n",
+ prog, arg, prog);
return -1;
}
} else {
if (!isatty(STDIN_FILENO)) {
- fprintf(stderr, "janas-chat: no model given\n");
+ fprintf(stderr, "%s: no model given\n", prog);
return -1;
}
list(cm->dir);
@@ -193,23 +196,17 @@ int chat_model_resolve(const char *arg, struct chat_model *cm)
fprintf(stderr, "not in the list: %s\n", b);
}
}
- if (m->test_only)
- fprintf(stderr,
- "note: %s is a test model of the engine, not for chatting: "
- "its answers are often wrong (janas-chat with no model lists "
- "the others)\n",
- m->name);
cm->entry = m;
set_key(cm, m->name);
snprintf(cm->path, sizeof(cm->path), "%s/%s", cm->dir, m->out);
if (is_file(cm->path))
return 0;
if (!isatty(STDIN_FILENO)) {
- fprintf(stderr, "janas-chat: %s is not here yet: janas-get %s\n",
- m->name, m->name);
+ fprintf(stderr, "%s: %s is not here yet: janas-get %s\n", prog, m->name,
+ m->name);
return -1;
}
- if (choose_dir(cm->dir, sizeof(cm->dir)) != 0)
+ if (choose_dir(prog, cm->dir, sizeof(cm->dir)) != 0)
return -1;
snprintf(cm->path, sizeof(cm->path), "%s/%s", cm->dir, m->out);
if (is_file(cm->path))
@@ -227,16 +224,17 @@ int chat_model_resolve(const char *arg, struct chat_model *cm)
"%s is not here: download it (%.1f GB, and about %.0f GB "
"free while it is converted) with its prediction file?",
m->name, m->gguf_gb, m->gguf_gb * 2.0 + 0.5);
- if (!chat_ask_yes(q))
+ if (!janas_ask_yes(q))
return -1;
- if (fetch(m, cm->dir) != 0 || !is_file(cm->path)) {
- fprintf(stderr, "janas-chat: %s was not made\n", cm->path);
+ if (fetch(prog, m, cm->dir) != 0 || !is_file(cm->path)) {
+ fprintf(stderr, "%s: %s was not made\n", prog, cm->path);
return -1;
}
return 0;
}
-const char *chat_model_draft(const struct chat_model *cm, char *buf, size_t len)
+const char *janas_model_pick_draft(const struct janas_model_pick *cm, char *buf,
+ size_t len)
{
const struct janas_model_entry *d =
cm->entry && cm->entry->draft ? janas_catalog_find(cm->entry->draft)
@@ -247,16 +245,8 @@ const char *chat_model_draft(const struct chat_model *cm, char *buf, size_t len)
return is_file(buf) ? buf : NULL;
}
-int chat_words_any(int n, char *const *w, const char *const *opts)
-{
- for (int i = 0; i < n; i++)
- for (int k = 0; opts[k]; k++)
- if (strcmp(w[i], opts[k]) == 0)
- return 1;
- return 0;
-}
-
-const char *chat_model_mtp(const struct chat_model *cm, char *buf, size_t len)
+const char *janas_model_pick_mtp(const struct janas_model_pick *cm, char *buf,
+ size_t len)
{
if (cm->entry) {
if (cm->entry->extra == JANAS_EXTRA_NONE || !cm->entry->extra_out)
@@ -266,12 +256,3 @@ const char *chat_model_mtp(const struct chat_model *cm, char *buf, size_t len)
}
return janas_llm_find_mtp(cm->path, buf, len) == JANAS_LLM_OK ? buf : NULL;
}
-
-const char *chat_words_last(int n, char *const *w, const char *opt)
-{
- const char *v = NULL;
- for (int i = 0; i + 1 < n; i++)
- if (strcmp(w[i], opt) == 0)
- v = w[i + 1];
- return v;
-}
diff --git a/src/chat/models.h b/src/common/model_pick.h
similarity index 53%
rename from src/chat/models.h
rename to src/common/model_pick.h
index 22a30a0..4e3376a 100644
--- a/src/chat/models.h
+++ b/src/common/model_pick.h
@@ -1,50 +1,46 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
Copyright (C) 2026 Maurizio Cammalleri */
/*
- * models.h - janas-chat's models by name: a path, a name of the catalog
+ * model_pick.h - a model by name, for the programs that open one
+ * (janas-chat, janas-bench): a path, a name of the catalog
* (src/common/catalog.c), or none, and then a list to choose from. A model
* of the catalog that is not there yet is downloaded and converted by
* janas-get, with its prediction file or draft, once the user says so.
*/
-#ifndef JANAS_CHAT_MODELS_H
-#define JANAS_CHAT_MODELS_H
+#ifndef JANAS_COMMON_MODEL_PICK_H
+#define JANAS_COMMON_MODEL_PICK_H
#include <stddef.h>
#include "common/catalog.h"
-struct chat_model {
+struct janas_model_pick {
char path[4400]; /* the .jns to open */
char dir[4096]; /* the folder it is in */
char key[128]; /* its settings file: the catalog name, or the file's */
const struct janas_model_entry *entry; /* NULL: not in the catalog */
};
-/* arg: a path, a catalog name, or NULL for the list. 0, or -1 with the
- reason printed. */
-int chat_model_resolve(const char *arg, struct chat_model *cm);
+/* arg: a path, a catalog name, or NULL for the list; prog names the
+ program in what is printed. 0, or -1 with the reason printed. */
+int janas_model_pick(const char *prog, const char *arg,
+ struct janas_model_pick *mp);
/* The draft the catalog names for the model, if its file is beside it:
the path in buf, or NULL. */
-const char *chat_model_draft(const struct chat_model *cm, char *buf,
- size_t len);
+const char *janas_model_pick_draft(const struct janas_model_pick *mp, char *buf,
+ size_t len);
/* The model's prediction file: for a model of the catalog the one the
catalog names, beside it (none if it names none: a file that merely fits
may be another model's - Qwen3-Coder-Next took Qwen3-Next-80B's, and
drafted slower than from the conversation); otherwise the one
janas_llm_find_mtp finds beside it. The path in buf, or NULL. */
-const char *chat_model_mtp(const struct chat_model *cm, char *buf,
- size_t len);
+const char *janas_model_pick_mtp(const struct janas_model_pick *mp, char *buf,
+ size_t len);
-/* The value of the last opt among n words, or NULL. */
-const char *chat_words_last(int n, char *const *w, const char *opt);
-
-/* 1 if one of the n words is one of opts (NULL-terminated). */
-int chat_words_any(int n, char *const *w, const char *const *opts);
-
-/* A question answered y or n on standard input (before the chat's own
- terminal is set up); anything but y is no. */
-int chat_ask_yes(const char *question);
+/* A question answered y or n on standard input (before a terminal of the
+ program's own is set up); anything but y is no. */
+int janas_ask_yes(const char *question);
#endif