v0.7.0: image input, model registry, prefix-cache savings
Images - vision gate: text-only models get a note instead of image parts and no view_image tool; unknown models retry once without images on HTTP 400 - paste: Ctrl+V and /attach paste read the clipboard (wl-paste, xclip, pngpaste/osascript, Win32 PNG or CF_DIB converted to PNG); pasting image file paths attaches them - MCP image content is stored in the session and sent with the tool result - attach: rel path validation, base64 decode, /retry keeps images Model registry - built-in src/models_builtin.json embedded at build time, merged with <config>/models.json and cached GET /models metadata (context, vision, pricing); most specific rule wins per field - /model labels, /status source, --list-models [provider] Cache and cost - stable request prefix (frozen tools, notes as messages), DeepSeek prefix completion, OpenAI/Anthropic cache hints, /cost and hit rate in the status
This commit is contained in:
+70
-2
@@ -3,6 +3,8 @@
|
||||
#endif
|
||||
|
||||
#include "cst_agent.h"
|
||||
#include "cst_models.h"
|
||||
#include "os_compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -72,11 +74,51 @@ static int start_server(void) {
|
||||
"Connection: close\r\n\r\n" body
|
||||
|
||||
int main(void) {
|
||||
char cfgdir[1024];
|
||||
CHECK(test_tmpdir(cfgdir, sizeof(cfgdir), "cst-models-cfg") == 0);
|
||||
setenv("XDG_CONFIG_HOME", cfgdir, 1); /* ignore a real models-cache */
|
||||
const cst_provider_t *tr = cst_provider_find("teamorouter");
|
||||
CHECK(tr && strcmp(tr->api_base, "https://api.teamorouter.com/v1") == 0);
|
||||
CHECK(tr->model[0] == 0); /* picked from GET /models */
|
||||
CHECK(cst_model_context_tokens("anthropic/claude-sonnet-4") == 200000);
|
||||
CHECK(cst_model_context_tokens("deepseek-flash") == 128000);
|
||||
CHECK(cst_model_context_tokens("deepseek-flash") == 1000000);
|
||||
CHECK(cst_model_context_tokens("deepseek/deepseek-v4-pro") == 1000000);
|
||||
CHECK(cst_model_context_tokens("google/gemini-2.5-pro") == 1048576);
|
||||
CHECK(cst_model_context_tokens("unknown-model") == 128000);
|
||||
|
||||
cst_model_caps_t caps;
|
||||
cst_model_caps("deepseek", "https://api.deepseek.com/v1", "deepseek-flash",
|
||||
&caps);
|
||||
CHECK(caps.reasoning_passback && caps.prefix_completion);
|
||||
CHECK(caps.cache_style == CST_CACHE_AUTO);
|
||||
cst_model_caps("teamorouter", "https://api.teamorouter.com/v1",
|
||||
"deepseek-flash", &caps);
|
||||
CHECK(!caps.reasoning_passback && !caps.prefix_completion);
|
||||
cst_model_caps("teamorouter", NULL, "anthropic/claude-sonnet-4", &caps);
|
||||
CHECK(caps.cache_style == CST_CACHE_ANTHROPIC);
|
||||
cst_model_caps("openai", NULL, "gpt-4.1", &caps);
|
||||
CHECK(caps.cache_style == CST_CACHE_OPENAI);
|
||||
cst_model_caps("openai", NULL, "o3-mini", &caps);
|
||||
CHECK(caps.cache_style == CST_CACHE_OPENAI);
|
||||
cst_model_caps("minimax", NULL, "MiniMax-M2", &caps);
|
||||
CHECK(caps.cache_style == CST_CACHE_AUTO);
|
||||
|
||||
/* Beijing time: Thu 10:00 peak, Thu 13:00 and Sat 10:00 off-peak */
|
||||
CHECK(cst_price_is_peak((time_t)1791424800));
|
||||
CHECK(!cst_price_is_peak((time_t)1791435600));
|
||||
CHECK(!cst_price_is_peak((time_t)1791597600));
|
||||
cst_price_t pr;
|
||||
CHECK(cst_model_price("deepseek-flash", &pr) == 0);
|
||||
CHECK(pr.offpeak_half && pr.hit < pr.miss);
|
||||
double peak = cst_price_cost(&pr, 1000000, 1000000, 0, 1000000,
|
||||
(time_t)1791424800);
|
||||
CHECK(peak > 9.99 && peak < 10.05); /* 2 + 0.04 + 8 */
|
||||
double off = cst_price_cost(&pr, 1000000, 1000000, 0, 1000000,
|
||||
(time_t)1791435600);
|
||||
CHECK(off > peak / 2 - 0.001 && off < peak / 2 + 0.001);
|
||||
CHECK(cst_model_price("anthropic/claude-sonnet-4", &pr) == 0);
|
||||
CHECK(pr.write > pr.miss && strcmp(pr.currency, "$") == 0);
|
||||
CHECK(cst_model_price("MiniMax-M2", &pr) != 0);
|
||||
|
||||
g_responses[0] = RESP("200 OK", "{\"object\":\"list\",\"data\":["
|
||||
"{\"id\":\"deepseek-flash\"},"
|
||||
@@ -87,7 +129,21 @@ int main(void) {
|
||||
g_responses[3] = RESP("200 OK", "{\"models\":[{\"name\":\"m1\"},"
|
||||
"{\"name\":\"m2\"}]}");
|
||||
g_responses[4] = RESP("500 Internal Server Error", "{}");
|
||||
g_nresp = 5;
|
||||
/* OpenRouter-style metadata; prices are USD per token, as strings */
|
||||
g_responses[5] = RESP(
|
||||
"200 OK",
|
||||
"{\"data\":[{\"id\":\"anthropic/claude-sonnet-4\","
|
||||
"\"context_length\":1000000,"
|
||||
"\"architecture\":{\"input_modalities\":[\"text\",\"image\"]},"
|
||||
"\"pricing\":{\"prompt\":\"0.000003\",\"completion\":\"0.000015\","
|
||||
"\"input_cache_read\":\"0.0000003\"}},"
|
||||
"{\"id\":\"old/text-model\","
|
||||
"\"architecture\":{\"modality\":\"text->text\"},"
|
||||
"\"pricing\":{\"prompt\":\"-1\",\"completion\":\"-1\"}},"
|
||||
"{\"id\":\"vllm-model\",\"max_model_len\":32768,"
|
||||
"\"modalities\":{\"input\":[\"text\"]}},"
|
||||
"{\"id\":\"plain\"}]}");
|
||||
g_nresp = 6;
|
||||
int port = start_server();
|
||||
pthread_t th;
|
||||
CHECK(pthread_create(&th, NULL, serve, NULL) == 0);
|
||||
@@ -118,6 +174,17 @@ int main(void) {
|
||||
n = cst_llm_list_models(base, "sk-test", ids, 8, err, sizeof(err));
|
||||
CHECK(n == -1 && strstr(err, "500") != NULL);
|
||||
|
||||
cst_model_meta_t meta[8];
|
||||
n = cst_llm_list_models_meta(base, "sk-test", meta, 8, err, sizeof(err));
|
||||
CHECK(n == 4);
|
||||
CHECK(meta[0].context == 1000000 && meta[0].vision == 1);
|
||||
CHECK(meta[0].has_price && meta[0].miss > 2.99 && meta[0].miss < 3.01 &&
|
||||
meta[0].out > 14.99 && meta[0].out < 15.01 && meta[0].hit < 0.31 &&
|
||||
meta[0].write == meta[0].miss);
|
||||
CHECK(meta[1].vision == 0 && !meta[1].has_price && meta[1].context == 0);
|
||||
CHECK(meta[2].context == 32768 && meta[2].vision == 0);
|
||||
CHECK(meta[3].vision == -1 && meta[3].context == 0 && !meta[3].has_price);
|
||||
|
||||
pthread_join(th, NULL);
|
||||
test_sock_close(g_listen);
|
||||
|
||||
@@ -125,6 +192,7 @@ int main(void) {
|
||||
n = cst_llm_list_models(base, "sk-test", ids, 8, err, sizeof(err));
|
||||
CHECK(n == -1);
|
||||
|
||||
test_rmrf(cfgdir);
|
||||
puts("test_models: ok");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user