e2e: LLM ChatClient via HttpPost + 61 tools RegisterAll exec OK; static openssl-only route

This commit is contained in:
2026-10-24 07:27:00 +02:00
parent 10a8f38720
commit 4ccd269354
8 changed files with 15 additions and 2 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+2
View File
@@ -12,6 +12,8 @@ std::string Parser::helpText() {
" --serve-mcp KEY --mcp-port PORT --mcp-bind HOST\n"
" --telegram --scheduler --install --install-telegram --uninstall-telegram\n"
" --plexer-wrap --mplex COMMAND... --demo --demo-shot --tui --tui-local --theme NAME\n"
" --model MODEL --task TASK --cwd DIR --driver D --binary B --argv A\n"
" --allow-tool T --deny-tool T --max-risk R --auto-answer A\n"
" --help (-h)\n version ") + std::string(kVersion) + "\n";
}
Options Parser::parseOpts(int argc, char** argv) {
+11 -2
View File
@@ -1,4 +1,6 @@
#include "llm.h"
#include "util/http.h"
#include <cstdlib>
#include <sstream>
namespace detz::llm {
static std::string esc(const std::string& s) {
@@ -45,13 +47,20 @@ ProviderInfo provider_info(const std::string& p) {
return {p == "openai" ? "openai" : "openai", "https://api.openai.com", "/v1/chat/completions"};
}
std::string provider_names() { return "openai,anthropic,google,deepseek,xai,openrouter"; }
static std::string curl_post(const std::string& url, const std::string& body, const std::map<std::string,std::string>& h) {
auto r = detz::HttpPost(url, body, h, 60);
return r.body;
}
ChatClient::ChatClient(std::string provider, std::string model, HttpPost post)
: provider_(std::move(provider)), model_(std::move(model)), post_(std::move(post)) {}
: provider_(std::move(provider)), model_(std::move(model)), post_(post ? std::move(post) : HttpPost(curl_post)) {
const char* k = std::getenv("OPENAI_API_KEY");
if (k && *k) default_headers_["Authorization"] = std::string("Bearer ")+k;
}
ChatResponse ChatClient::chat(const ChatRequest& req) {
if (!post_) throw BackendError("no transport (mock required)", -1);
auto info = provider_info(provider_);
ChatRequest r = req; if (r.model.empty()) r.model = model_;
std::string body = post_(info.base_url + info.chat_path, req_json(r), {});
std::string body = post_(info.base_url + info.chat_path, req_json(r), default_headers_);
if (body.empty()) throw BackendError("empty backend response", 502);
ChatResponse out; out.model = r.model;
std::string t = grab(body, "content"); if (t.empty()) t = grab(body, "text");
+2
View File
@@ -33,6 +33,7 @@ class ChatClient {
const std::string& provider() const { return provider_; }
private:
std::string provider_, model_; HttpPost post_;
std::map<std::string,std::string> default_headers_;
};
struct ModelSample { std::string model; bool ok; int latency_ms; };
class ModelHealth {
@@ -50,5 +51,6 @@ class Opencode {
ChatResponse complete(const std::string& model, const std::vector<Message>& msgs);
private:
std::string base_; HttpPost post_;
std::map<std::string,std::string> default_headers_;
};
} // namespace detz::llm