[GH-ISSUE #3294] [BUG]: Custom refusal message #2117

Closed
opened 2026-02-22 18:28:13 -05:00 by yindo · 2 comments
Owner

Originally created by @ImOP12138 on GitHub (Feb 20, 2025).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/3294

How are you running AnythingLLM?

AnythingLLM desktop app

What happened?

When I chat with LLM by calling the API,which is supported by ollama, it will reply "Custom refusal message" for me.

When I make this workspace quote(Pin) at least one file this issue finally get down.

Are there known steps to reproduce?

just new a blank workspace and chat with the LLM by calling the API.

Originally created by @ImOP12138 on GitHub (Feb 20, 2025). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/3294 ### How are you running AnythingLLM? AnythingLLM desktop app ### What happened? When I chat with LLM by calling the API,which is supported by ollama, it will reply "Custom refusal message" for me. When I make this workspace quote(Pin) at least one file this issue finally get down. ### Are there known steps to reproduce? just new a blank workspace and chat with the LLM by calling the API.
yindo added the possible bug label 2026-02-22 18:28:13 -05:00
yindo closed this issue 2026-02-22 18:28:13 -05:00
Author
Owner

@shatfield4 commented on GitHub (Feb 20, 2025):

This is the intended functionality. When in query mode, the chat will only respond if there are documents found. When pinning a document, this is forcing the entire document into the model's context and this counts as a document and will allow the chat to go through without sending the refusal message.

@shatfield4 commented on GitHub (Feb 20, 2025): This is the intended functionality. When in query mode, the chat will only respond if there are documents found. When pinning a document, this is forcing the entire document into the model's context and this counts as a document and will allow the chat to go through without sending the refusal message.
Author
Owner

@ImOP12138 commented on GitHub (Feb 20, 2025):

No , I'm in chat mode.There are the settings .

Image

Image

And when I unpinned the txt as follows, the issue came again.

Image

Image

my code about chatting request is as follows:

void QT_checkFiles::on_sendButton_clicked()
{
    qDebug() << "connecting...";
    QString input = ui.inputEdit->toPlainText().trimmed();
    if (input.isEmpty()) {
        qDebug() << "Input is empty. Aborting request.";
        return;
    }
    qDebug() << "User input:" << input;

    // 添加用户消息到历史
    addMessageToHistory("user", input);
    displayMessage("You", input);
    ui.inputEdit->clear();

    QJsonArray messagesArray;
    for (const auto& msg : chatHistory) {
        messagesArray.append(msg);
    }

    // 设置目标 URL
    QUrl url("http://localhost:3001/api/v1/workspace/test/chat");
    QNetworkRequest request(url);

    // 设置请求头
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
    request.setRawHeader("accept", "application/json");
    request.setRawHeader("Authorization", "Bearer MJ0TZ5V-STHMNNR-JKMC6P3-SBPG3WW");

    // 构造 JSON 数据
    QJsonObject json;
    json["message"] = input;
    QJsonDocument doc(json);
    QByteArray data = doc.toJson();

    // 发送 POST 请求
    QNetworkReply* reply = networkManager->post(request, data);

    // 连接信号槽,处理异步响应
    connect(reply, &QNetworkReply::finished, this, [this, reply]() {
        if (reply->error() == QNetworkReply::NoError) {
            QByteArray responseData = reply->readAll();
            qDebug() << "Raw response data from server:" << responseData;

            int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
            qDebug() << "HTTP status code:" << statusCode;

            QJsonParseError parseError;
            QJsonDocument response = QJsonDocument::fromJson(responseData, &parseError);
            if (response.isNull()) {
                qDebug() << "Failed to parse JSON response. Parse error:" << parseError.errorString();
                QMessageBox::critical(this, "Error", "Failed to parse JSON response.");
                reply->deleteLater();
                return;
            }

            QJsonObject responseObj = response.object();

            // 检查是否有错误信息
            if (responseObj.contains("error") && !responseObj["error"].isNull()) {
                QString errorMessage = responseObj["error"].toObject()["message"].toString();
                qDebug() << "API returned an error:" << errorMessage;
                QMessageBox::critical(this, "API Error", errorMessage);
                reply->deleteLater();
                return;
            }

            // 检查 textResponse 字段
            if (responseObj.contains("textResponse")) {
                QString textResponse = responseObj["textResponse"].toString();
                qDebug() << "Server text response:" << textResponse;

                // 如果 textResponse 是拒绝消息,显示给用户
                if (!textResponse.isEmpty()) {
                    displayMessage("AI", textResponse);
                    addMessageToHistory("assistant", textResponse);
                }
            }
            else {
                qDebug() << "Unexpected response format. Missing 'textResponse' field.";
                QMessageBox::critical(this, "Error", "Unexpected response format from server.");
            }
        }
        else {
            QByteArray errorResponse = reply->readAll();
            qDebug() << "Network error:" << reply->errorString();
            qDebug() << "Error response from server:" << errorResponse;
            QMessageBox::critical(this, "Network Error", reply->errorString());
        }

        reply->deleteLater();
        });
}

void QT_checkFiles::addMessageToHistory(const QString& role, const QString& content)
{
    QJsonObject message;
    message["role"] = role;
    message["content"] = content;
    chatHistory.append(message);
    qDebug() << "Added message to history:" << message;
}

void QT_checkFiles::displayMessage(const QString& sender, const QString& message)
{
    ui.chatBrowser->append(QString("<b>%1:</b> %2").arg(sender, message));
    qDebug() << "Displayed message:" << sender << ":" << message;
}

@ImOP12138 commented on GitHub (Feb 20, 2025): **No , I'm in chat mode.There are the settings .** ![Image](https://github.com/user-attachments/assets/2374e9b1-f912-4175-ba25-b40c38f65d08) ![Image](https://github.com/user-attachments/assets/db53ba60-22a8-4793-9261-986a7f56e93c) **And when I unpinned the txt as follows, the issue came again.** ![Image](https://github.com/user-attachments/assets/2312135b-fbc5-418d-8d2d-e68e1d85f278) ![Image](https://github.com/user-attachments/assets/f96d6f06-d852-4228-9f89-7fe6d6ad053d) **my code about chatting request is as follows:** ``` void QT_checkFiles::on_sendButton_clicked() { qDebug() << "connecting..."; QString input = ui.inputEdit->toPlainText().trimmed(); if (input.isEmpty()) { qDebug() << "Input is empty. Aborting request."; return; } qDebug() << "User input:" << input; // 添加用户消息到历史 addMessageToHistory("user", input); displayMessage("You", input); ui.inputEdit->clear(); QJsonArray messagesArray; for (const auto& msg : chatHistory) { messagesArray.append(msg); } // 设置目标 URL QUrl url("http://localhost:3001/api/v1/workspace/test/chat"); QNetworkRequest request(url); // 设置请求头 request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); request.setRawHeader("accept", "application/json"); request.setRawHeader("Authorization", "Bearer MJ0TZ5V-STHMNNR-JKMC6P3-SBPG3WW"); // 构造 JSON 数据 QJsonObject json; json["message"] = input; QJsonDocument doc(json); QByteArray data = doc.toJson(); // 发送 POST 请求 QNetworkReply* reply = networkManager->post(request, data); // 连接信号槽,处理异步响应 connect(reply, &QNetworkReply::finished, this, [this, reply]() { if (reply->error() == QNetworkReply::NoError) { QByteArray responseData = reply->readAll(); qDebug() << "Raw response data from server:" << responseData; int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); qDebug() << "HTTP status code:" << statusCode; QJsonParseError parseError; QJsonDocument response = QJsonDocument::fromJson(responseData, &parseError); if (response.isNull()) { qDebug() << "Failed to parse JSON response. Parse error:" << parseError.errorString(); QMessageBox::critical(this, "Error", "Failed to parse JSON response."); reply->deleteLater(); return; } QJsonObject responseObj = response.object(); // 检查是否有错误信息 if (responseObj.contains("error") && !responseObj["error"].isNull()) { QString errorMessage = responseObj["error"].toObject()["message"].toString(); qDebug() << "API returned an error:" << errorMessage; QMessageBox::critical(this, "API Error", errorMessage); reply->deleteLater(); return; } // 检查 textResponse 字段 if (responseObj.contains("textResponse")) { QString textResponse = responseObj["textResponse"].toString(); qDebug() << "Server text response:" << textResponse; // 如果 textResponse 是拒绝消息,显示给用户 if (!textResponse.isEmpty()) { displayMessage("AI", textResponse); addMessageToHistory("assistant", textResponse); } } else { qDebug() << "Unexpected response format. Missing 'textResponse' field."; QMessageBox::critical(this, "Error", "Unexpected response format from server."); } } else { QByteArray errorResponse = reply->readAll(); qDebug() << "Network error:" << reply->errorString(); qDebug() << "Error response from server:" << errorResponse; QMessageBox::critical(this, "Network Error", reply->errorString()); } reply->deleteLater(); }); } void QT_checkFiles::addMessageToHistory(const QString& role, const QString& content) { QJsonObject message; message["role"] = role; message["content"] = content; chatHistory.append(message); qDebug() << "Added message to history:" << message; } void QT_checkFiles::displayMessage(const QString& sender, const QString& message) { ui.chatBrowser->append(QString("<b>%1:</b> %2").arg(sender, message)); qDebug() << "Displayed message:" << sender << ":" << message; } ```
yindo changed title from [BUG]: Custom refusal message to [GH-ISSUE #3294] [BUG]: Custom refusal message 2026-06-05 14:44:38 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#2117