No description
  • C++ 99.7%
  • Makefile 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-14 00:51:18 -05:00
.vscode Initial working version 2026-11-08 21:55:40 -05:00
.gitignore Initial working version 2026-11-08 21:55:40 -05:00
channel.hpp Initial working version 2026-11-08 21:55:40 -05:00
client.cpp Added initial tool support 2026-11-13 22:58:34 -05:00
common.h Initial working version 2026-11-08 21:55:40 -05:00
Makefile Initial working version 2026-11-08 21:55:40 -05:00
manager.hpp Add manager checks for available client model pairs 2026-11-14 00:51:18 -05:00
models.hpp Added initial tool support 2026-11-13 22:58:34 -05:00
quic_transport.hpp ASR returns transcription events, automatic HTTP port selection, Better HTTP close detection, and initial work for LLM tool support 2026-11-13 22:29:09 -05:00
README.md Added initial tool support 2026-11-13 22:58:34 -05:00
rpc.hpp Allow checking if a model is online from the client 2026-11-14 00:50:04 -05:00
server.cpp Added initial tool support 2026-11-13 22:58:34 -05:00
test.cpp Added initial tool support 2026-11-13 22:58:34 -05:00
wire.hpp Initial working version 2026-11-08 21:55:40 -05:00

Model RPC over QUIC (ngtcp2)

Files

File Purpose Edit it?
models.hpp Model types, capabilities, methods, Server and Client classes Yes - this is the one
manager.hpp Manager: several clients, auto-reconnect, fail-over across (client, model) pairs Yes - If large changes are made in models.hpp
rpc.hpp Calls, streaming, cancellation, model-list updates No
quic_transport.hpp All ngtcp2 / GnuTLS / socket code No
wire.hpp Binary serialization (+ Kwargs) Rarely
channel.hpp Your Channel<T> (unchanged) -
example_server.cpp, example_client.cpp Runnable demo with fake models copy from these
test.cpp Self-checking test of everything -

Install

Debian 13 (trixie; Debian 12 ships ngtcp2 0.12 whose API is different):

sudo apt install g++ make pkg-config libngtcp2-dev libngtcp2-crypto-gnutls-dev libgnutls28-dev

MSYS2 (mingw64 shell):

pacman -S make mingw-w64-x86_64-gcc mingw-w64-x86_64-pkgconf mingw-w64-x86_64-ngtcp2 mingw-w64-x86_64-gnutls

Needs C++23 (std::expected). Build with make, test with make test.

Using it

Server:

Server server({.port = 4433});                    // no cert given -> self-signed
server.add_llm("llm1", std::make_shared<MyLlm>()); // MyLlm derives from LlmModel
server.start();
// any thread, any time:  server.add_tts(...);  server.remove_llm("llm1");

Client:

Client client({.host = "192.168.1.5", .port = 4433});
client.connect();                                       // returns once the model list arrived
auto& llm = client.llmModels["llm1"];                   // handle with .capabilities
auto r = llm.count_tokens({"some text"});               // Result<Final> (std::expected)
auto call = llm.generate({"prompt", 256, 0.7f});        // streaming output
for (auto& tok : call->output()) ...;                   // iterate the Channel
auto fin = call->final();                               // blocks until done
call->cancel();                                         // final still arrives

Input streaming: pass a std::shared_ptr<Channel<T>>, send into it, close() it when done.

Tests / several servers on one machine: Server server({.port = 0}); binds any free port; server.port() returns it after start().

Cancelling outside I/O (server side): a model blocked on an HTTP request, websocket connect, ... can register a hook that runs as soon as the call is cancelled, instead of polling cancelled():

auto hook = call.on_cancel([&] { http.abort(); });  // removed when `hook` is destroyed

Tools (LLM): a tool is a name, a description and a function; it runs on the client when the model on the server asks for it. Put tools in the params of any llm method (run, run_stream, run_dual_stream, and the Manager versions):

llm::Tool get_time("get_time", "Returns the current local time", [] { return now_as_text(); });
llm::Tool add("add", "Adds a and b", [](const std::string& args_json) { ... },
              R"({"type":"object","properties":{"a":{"type":"number"},"b":{"type":"number"}}})");
auto call = llm.run_stream({history, 256, 0.7f, {get_time, add}});
for (auto& item : call->output()) ...;   // text, tool calls and tool results
auto fin = call->final();                // covers the whole exchange
history.insert(history.end(), fin->added_history.begin(), fin->added_history.end());

The call runs every tool the model asks for and gives it the results (for run/run_stream by calling the model again with them appended to the history, at most RunParams::max_tool_rounds times; for run_dual_stream in the input stream). On the server, a model reads call.params.tools (name, description, parameters), sends {"assistant", "", {llm::ToolCall{id, name, args_json}}} and returns RunFinal{"tool_calls"} (see FakeLlm in server.cpp).

ASR streaming: asr::run_stream sends asr::Transcript{text, final, replace} events (final text, partials, replacements); asr::TranscriptBuilder turns them into text.

Behaviour worth knowing

  • Reconnection: QUIC itself rides out outages shorter than the idle timeout (kIdleTimeout, 10 s; keep-alive pings every 3 s). Longer outages close the connection: running calls fail with ErrorCode::Disconnected, the *Models maps empty and client.on_disconnected fires. A plain Client does not reconnect by itself - call connect() again, or use Manager (manager.hpp), which keeps retrying every client in the background.
  • Security: TLS 1.3 always. By default the client does NOT verify the server certificate (ClientOptions::ca_file empty). To verify, give the server cert_file/key_file (CN/SAN must match the host you connect to) and give the client that cert as ca_file. There is no client authentication yet.
  • Big data: one message may be up to 64 MB, but send audio/video in chunks (tens of KB to ~1 MB) so playback starts early and cancel reacts quickly.
  • Backpressure: server call.send() blocks when the client is slower than the model. The server's input channel is unbounded, so a very fast client can queue memory if a model reads input slowly.
  • Threads: one thread per running call on the server; callbacks (on_added, ...) run on the I/O thread, keep them short and don't call disconnect() from them.
  • Capabilities are read once when a model is added; to change them, remove and re-add the model.