fix: truncate webfetch content to fit context
C++ / fmt (pull_request) Failing after 5s
C++ / build (pull_request) Failing after 2m18s
C++ / clang-tidy (pull_request) Failing after 2m7s
JS/TS / fmt (pull_request) Failing after 9s
JS/TS / lint (pull_request) Successful in 9s
Python / static (pull_request) Successful in 29s
Rust / build (pull_request) Successful in 50s
Python / verify (pull_request) Successful in 1m38s
Rust / fmt (pull_request) Successful in 26s
Rust / clippy (pull_request) Successful in 47s
C++ / fmt (pull_request) Failing after 5s
C++ / build (pull_request) Failing after 2m18s
C++ / clang-tidy (pull_request) Failing after 2m7s
JS/TS / fmt (pull_request) Failing after 9s
JS/TS / lint (pull_request) Successful in 9s
Python / static (pull_request) Successful in 29s
Rust / build (pull_request) Successful in 50s
Python / verify (pull_request) Successful in 1m38s
Rust / fmt (pull_request) Successful in 26s
Rust / clippy (pull_request) Successful in 47s
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#include "generation.hpp"
|
||||
|
||||
#include "llmclient.hpp"
|
||||
#include "messagemodel.hpp"
|
||||
#include "session.hpp"
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
namespace ZShell::llm {
|
||||
@@ -46,7 +50,7 @@ QString ChatGeneration::reasoning() const {
|
||||
bool ChatGeneration::reasoningActive() const {
|
||||
if (!m_streaming) return false;
|
||||
if (!content().isEmpty()) return false;
|
||||
return !hasRunningTool();
|
||||
return !hasRunningTool() && !hasPendingTool();
|
||||
}
|
||||
|
||||
qint64 ChatGeneration::reasoningElapsedMs() const {
|
||||
@@ -87,6 +91,45 @@ bool ChatGeneration::hasRunningTool() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ChatGeneration::hasPendingTool() const {
|
||||
for (const auto* segment : m_segments)
|
||||
if (segment->type() == LlmSegment::Type::ToolCall &&
|
||||
segment->status() == LlmSegment::Status::Pending)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void ChatGeneration::setApprovalPending(bool value) {
|
||||
if (m_approvalPending == value) return;
|
||||
m_approvalPending = value;
|
||||
Q_EMIT toolApprovalPendingChanged();
|
||||
}
|
||||
|
||||
QVariantList ChatGeneration::pendingToolCalls() const {
|
||||
QVariantList out;
|
||||
if (!m_approvalPending) return out;
|
||||
for (const auto* segment : m_segments)
|
||||
if (segment->type() == LlmSegment::Type::ToolCall &&
|
||||
segment->status() == LlmSegment::Status::Pending)
|
||||
out.append(QVariant::fromValue(segment));
|
||||
return out;
|
||||
}
|
||||
|
||||
void ChatGeneration::approveTools() {
|
||||
if (auto* llmClient = client()) llmClient->approveTools();
|
||||
}
|
||||
|
||||
void ChatGeneration::denyTools() {
|
||||
if (auto* llmClient = client()) llmClient->denyTools();
|
||||
}
|
||||
|
||||
LlmClient* ChatGeneration::client() const {
|
||||
if (auto* message = qobject_cast<ChatMessage*>(parent()))
|
||||
if (auto* model = qobject_cast<ChatMessageModel*>(message->parent()))
|
||||
if (auto* session = model->session()) return session->client();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ChatGeneration::updateReasoningActive() {
|
||||
const bool active = reasoningActive();
|
||||
if (m_reasoningActive == active) return;
|
||||
@@ -177,7 +220,9 @@ LlmSegment* ChatGeneration::beginToolCall(
|
||||
LlmSegment::Type::ToolCall, QDateTime::currentMSecsSinceEpoch(), this);
|
||||
segment->setName(name);
|
||||
segment->setToolCallId(toolCallId);
|
||||
segment->setStatus(LlmSegment::Status::Running);
|
||||
// Awaiting user approval until LlmClient::approveTools() promotes it
|
||||
// to Running; denyTools()/endStream() finalize it as an error.
|
||||
segment->setStatus(LlmSegment::Status::Pending);
|
||||
segment->begin();
|
||||
addSegment(segment);
|
||||
Q_EMIT toolStateChanged();
|
||||
|
||||
Reference in New Issue
Block a user