v0.8.15: custom providers and model parameters under Advanced options
The settings dialog could pick a preset, a model and a key and nothing else.
Two things were missing: a provider the presets do not know, and what the
model is asked to do while it answers. Both live under "Advanced options"
now, next to the entry they belong to.
Custom providers (engine)
- cst_models_user_set_provider() / cst_models_user_drop_provider() write the
engine's own user layer, <config>/cst-agent/models.json:
{"providers": {"myllm": {"api_base": ..., "key_env": ...,
"default_model": ..., "models": [...]}}}
and reload the registry, so the provider is at once in the provider list,
in the wire models[] and in the CLI's /provider -- the file a hand-written
override would go into is the same one, so the GUI and an editor agree.
The name is checked (1-31 of letters, digits, '.', '_', '-'), a preset's
name overrides that preset (a self-hosted endpoint, a proxy), everything
else in the file (model rules) is kept, and a file that is not a JSON
object is never overwritten. Dropping only removes the user's own entry.
- AgentCore::providers() gained "custom" (source == "user"), and
addProvider() / removeProvider() drive the two calls above.
Model parameters (engine + wire)
- cst_agent_config_t and cst_llm_request_t carry temperature, top_p and
max_tokens. 0 means the field is not sent at all -- an absent field is the
provider's own default, which "temperature": 0 is not (deterministic
decoding is a real choice), so cst_llm_build_body() only adds what was set.
tests/test_llm_body.c:test_gen_params pins both halves.
- settings.json keeps them per provider ("params": {...}) via
cst_settings_remember_params(); cst_settings_remember() carries them along
with the provider choice, and cst_agent_create() reads them, so a CLI or
TUI run sends what the window was set to. An all-zero config (the CLI)
leaves what the GUI saved alone.
- AgentCore::genParams() / setGenParams(), and useProvider() applies both the
remembered parameters of the provider it lands on and a base URL that was
edited in the dialog.
The dialog
- Rewritten around one scrolling body with a fixed footer: a long model list
used to push the key field and the buttons out of the dialog. The model
chips are filtered (a filter field appears past twelve) and capped at 40
with "... +N more", which is what a router with hundreds of models needs.
- "Advanced options" folds out the provider entry (name, base URL, key
variable, default model, models; Save provider / Remove from models.json)
and the model parameters (temperature, top-p, max tokens; empty = not
sent). The fields follow the picked provider and are what gets saved, so a
hand-typed edit is never lost to a stale property.
Verified: --uitest 67/67 (15 new checks: parameters round-trip through the
engine, a provider added through the form and removed again, a bad name
refused, a preset not removable), --selftest, ctest cst-app-selftest, and
make check with the new body test.
Version 0.8.15.
mode = coding
This commit is contained in:
@@ -75,6 +75,40 @@ static void test_escaping(void) {
|
||||
cJSON_Delete(j);
|
||||
}
|
||||
|
||||
/* Settings -> Advanced: the generation parameters go on the wire only when
|
||||
* they were set. An absent field is the provider's own default, which
|
||||
* "temperature": 0 would not be. */
|
||||
static void test_gen_params(void) {
|
||||
cst_message_t m[1] = {msg(CST_ROLE_USER, "hi")};
|
||||
cst_llm_request_t r;
|
||||
memset(&r, 0, sizeof(r));
|
||||
r.model = "test-model";
|
||||
r.msgs = m;
|
||||
r.nmsgs = 1;
|
||||
r.temperature = 0.2;
|
||||
r.top_p = 0.9;
|
||||
r.max_tokens = 4096;
|
||||
char *body = cst_llm_build_body(&r);
|
||||
EXPECT(body != NULL, "body with parameters");
|
||||
cJSON *j = body ? cJSON_Parse(body) : NULL;
|
||||
free(body);
|
||||
const cJSON *t = cJSON_GetObjectItemCaseSensitive(j, "temperature");
|
||||
const cJSON *p = cJSON_GetObjectItemCaseSensitive(j, "top_p");
|
||||
const cJSON *mt = cJSON_GetObjectItemCaseSensitive(j, "max_tokens");
|
||||
EXPECT(cJSON_IsNumber(t) && t->valuedouble > 0.19 && t->valuedouble < 0.21,
|
||||
"temperature is sent as a number");
|
||||
EXPECT(cJSON_IsNumber(p) && cJSON_IsNumber(mt) && mt->valueint == 4096,
|
||||
"top_p and max_tokens are sent");
|
||||
cJSON_Delete(j);
|
||||
/* unset: none of the three is in the body at all */
|
||||
cJSON *plain = build(m, 1, 0, 0);
|
||||
EXPECT(!cJSON_GetObjectItemCaseSensitive(plain, "temperature") &&
|
||||
!cJSON_GetObjectItemCaseSensitive(plain, "top_p") &&
|
||||
!cJSON_GetObjectItemCaseSensitive(plain, "max_tokens"),
|
||||
"an unset parameter is not sent at all");
|
||||
cJSON_Delete(plain);
|
||||
}
|
||||
|
||||
static void test_invalid_utf8(void) {
|
||||
const char text[] = "ok \xff\xfe bad \xe4\xb8 trunc";
|
||||
cst_message_t m[1] = {msg(CST_ROLE_USER, text)};
|
||||
@@ -526,6 +560,7 @@ int main(void) {
|
||||
test_reasoning_and_prefix();
|
||||
test_cache_hints();
|
||||
test_tools_snapshot();
|
||||
test_gen_params();
|
||||
test_escaping();
|
||||
test_invalid_utf8();
|
||||
test_tool_calls_and_null_content();
|
||||
|
||||
Reference in New Issue
Block a user