Commit a2d34cd2 authored by jan.koester's avatar jan.koester
Browse files

test

parent 373de29a
Loading
Loading
Loading
Loading
+5 −6
Changes for editor/src/webedit_api.cpp: 5 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -3336,8 +3336,6 @@ void webedit::Api::handleAiSettings(libhttppp::HttpRequest &curreq) {

namespace {

constexpr int kMaxAiToolRounds = 6;

json_object *aiToolFunction(const char *name, const char *description, json_object *schema) {
    json_object *fn = json_object_new_object();
    json_object_object_add(fn, "name", json_object_new_string(name));
@@ -3647,8 +3645,8 @@ json_object *webedit::Api::callAiTool(const std::string &sessionid, const std::s
void webedit::Api::handleAiPrompt(libhttppp::HttpRequest &curreq,
                                   const std::string &sessionid) {
    // Admission control: this handler can block its worker thread for
    // minutes if the AI backend is slow/stuck (see kMaxAiToolRounds's
    // per-round connect/read timeouts below). The server's worker pool is
    // minutes if the AI backend is slow/stuck (see the AI_MAX_TOOL_ROUNDS
    // setting's per-round connect/read timeouts below). The server's worker pool is
    // small and fixed-size (roughly one per CPU core) and shared by every
    // route, so letting unbounded concurrent AI requests pile up can starve
    // completely unrelated endpoints. Reject early instead of queuing up
@@ -3700,6 +3698,7 @@ void webedit::Api::handleAiPrompt(libhttppp::HttpRequest &curreq,
    std::string aiUrl = _db.getOption("AI_URL", "http://localhost:11434");
    std::string aiModel = _db.getOption("AI_MODEL", "");
    int maxTokens = std::stoi(_db.getOption("AI_MAX_TOKENS", "16384"));
    int maxToolRounds = std::stoi(_db.getOption("AI_MAX_TOOL_ROUNDS", "20"));

    if (aiUrl.empty() || aiModel.empty()) {
        sendJsonError(curreq, 400, "AI not configured");
@@ -3759,7 +3758,7 @@ void webedit::Api::handleAiPrompt(libhttppp::HttpRequest &curreq,
        bool haveFinal = false;

        try {
            for (int round = 0; round < kMaxAiToolRounds && !haveFinal; ++round) {
            for (int round = 0; round < maxToolRounds && !haveFinal; ++round) {
                json_object *aiReq = json_object_new_object();
                json_object_object_add(aiReq, "model", json_object_new_string(aiModel.c_str()));
                json_object_object_add(aiReq, "max_tokens", json_object_new_int(maxTokens));
@@ -3939,7 +3938,7 @@ void webedit::Api::handleAiPrompt(libhttppp::HttpRequest &curreq,
    bool haveFinal = false;

    try {
        for (int round = 0; round < kMaxAiToolRounds && !haveFinal && !clientGone; ++round) {
        for (int round = 0; round < maxToolRounds && !haveFinal && !clientGone; ++round) {
            json_object *aiReq = json_object_new_object();
            json_object_object_add(aiReq, "model", json_object_new_string(aiModel.c_str()));
            json_object_object_add(aiReq, "max_tokens", json_object_new_int(maxTokens));