fix: truncate webfetch content to fit context

This commit is contained in:
2026-09-30 15:01:28 +02:00
parent e700a4f96b
commit e2786a3f1e
31 changed files with 1386 additions and 135 deletions
+22
View File
@@ -6,6 +6,20 @@ LlmTool::LlmTool(QObject* parent) : QObject(parent) {}
LlmTool::~LlmTool() = default;
void LlmTool::setContextSize(int value) {
if (m_contextSize == value) return;
m_contextSize = value;
}
int LlmTool::inlineBudgetChars() const {
if (m_contextSize <= 0) return DefaultInlineChars;
// About a quarter of the context window, clamped so tiny contexts
// still get a usable result and huge ones stay sane.
const int tokens =
qBound(512, m_contextSize / 4, DefaultInlineChars / CharsPerToken);
return tokens * CharsPerToken;
}
void LlmTool::cancel() {}
QJsonObject LlmTool::specification() const {
@@ -30,6 +44,7 @@ void ToolRegistry::setEnabled(bool value) {
void ToolRegistry::registerTool(LlmTool* tool) {
if (!tool || m_tools.contains(tool)) return;
tool->setParent(this);
tool->setContextSize(m_contextSize);
m_tools.append(tool);
}
@@ -52,4 +67,11 @@ void ToolRegistry::cancelAll() {
tool->cancel();
}
void ToolRegistry::setContextSize(int value) {
if (m_contextSize == value) return;
m_contextSize = value;
for (auto* tool : m_tools)
tool->setContextSize(value);
}
} // namespace ZShell::llm