Images: --mmproj PATH loads the Qwen3.8 Flash-Next projector through llama.cpp's mtmd library and encodes image_url parts on the CPU (frontend/vision.hpp). The embeddings go to the engine as a GENI request, its existing vision path, with the prompt's <|image_pad|> runs standing in for each image. --vision-tokens caps the tokens per image. GET /v1/models lists "image" under input_modalities when the encoder is loaded. Checked on an RTX 4090: screenshots, photos, several images in one message, and pi's file attachments and clipboard paste. Engine process: the engine is started and watched from frontend/engine.hpp; when it exits or its stall watchdog fires, the front end exits too, for a supervisor to restart. Stall reports add the current stage and thread wait channels. Reasoning streams; content and tool calls are sent once the whole message is parsed, so partial JSON never changes arguments already sent. Tests: make test-frontend (child exit, protocol, backpressure; no model needed) and make test-chat-parser MODEL=<gguf> (template and tool-call parsing against the real GGUF). The image path and the supervision were written by a Codex session; this commit finishes, documents and checks them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
50 lines
2.3 KiB
C++
50 lines
2.3 KiB
C++
#include "engine.hpp"
|
|
#include <cassert>
|
|
#include <stdexcept>
|
|
|
|
int main(int argc, char** argv) {
|
|
if (argc > 1 && std::string(argv[1]) == "--fake-engine") {
|
|
std::puts("READY"); std::fflush(stdout);
|
|
char* line = nullptr; size_t capacity = 0;
|
|
while (::getline(&line, &capacity, stdin) > 0) {
|
|
const std::string request(line);
|
|
if (request == "QUIT\n") break;
|
|
if (request == "STOP\n") continue;
|
|
if (request.rfind("GEN ", 0) != 0) continue;
|
|
if (request.find("88") != std::string::npos) {
|
|
std::printf("T 88\nDONE 1 2 1 1 stop 0 0\n");
|
|
std::fflush(stdout);
|
|
continue;
|
|
}
|
|
const int base = request.find("99") != std::string::npos ? 99 : 11;
|
|
std::printf("T %d\nT %d\nDONE 2 1 1 1 stop 0 0\n", base, base+1);
|
|
std::fflush(stdout);
|
|
}
|
|
std::free(line);
|
|
return 0;
|
|
}
|
|
strata_frontend::Engine engine;
|
|
std::string error;
|
|
assert(engine.start({argv[0], "--fake-engine"}, error, argv[0]));
|
|
assert(engine.wait_ready(error));
|
|
auto failed = engine.generate("GEN 2 ", {11}, [](int32_t) -> bool {
|
|
throw std::runtime_error("synthetic partial tool JSON diff error");
|
|
});
|
|
assert(!failed.ok && failed.error.find("synthetic") != std::string::npos);
|
|
std::vector<int32_t> tokens;
|
|
auto next = engine.generate("GEN 2 ", {99}, [&](int32_t token) { tokens.push_back(token); return true; });
|
|
assert(next.ok && (tokens == std::vector<int32_t>{99,100}));
|
|
auto cancelled = engine.generate("GEN 2 ", {11}, [](int32_t) { return false; });
|
|
assert(cancelled.ok);
|
|
tokens.clear();
|
|
next = engine.generate("GEN 2 ", {99}, [&](int32_t token) { tokens.push_back(token); return true; });
|
|
assert(next.ok && (tokens == std::vector<int32_t>{99,100}));
|
|
auto mismatched = engine.generate("GEN 2 ", {88}, [](int32_t) { return true; });
|
|
assert(!mismatched.ok && !engine.alive());
|
|
assert(mismatched.error.find("prompt size mismatch") != std::string::npos);
|
|
auto rejected = engine.generate("GEN 2 ", {99}, [](int32_t) { return true; });
|
|
assert(!rejected.ok && rejected.produced == 0);
|
|
engine.quit();
|
|
std::puts("PASS: formatter exceptions and client cancellation drain the old request before the next request");
|
|
}
|