chore: restructure llm plugin to be more coherent & fix various bugs in llm ui
C++ / fmt (pull_request) Failing after 6s
C++ / build (pull_request) Failing after 10s
C++ / clang-tidy (pull_request) Failing after 9s
JS/TS / fmt (pull_request) Successful in 10s
JS/TS / lint (pull_request) Successful in 8s
Python / static (pull_request) Successful in 30s
Rust / build (pull_request) Successful in 49s
Python / verify (pull_request) Successful in 1m35s
Rust / fmt (pull_request) Successful in 36s
Rust / clippy (pull_request) Successful in 54s
C++ / fmt (pull_request) Failing after 6s
C++ / build (pull_request) Failing after 10s
C++ / clang-tidy (pull_request) Failing after 9s
JS/TS / fmt (pull_request) Successful in 10s
JS/TS / lint (pull_request) Successful in 8s
Python / static (pull_request) Successful in 30s
Rust / build (pull_request) Successful in 49s
Python / verify (pull_request) Successful in 1m35s
Rust / fmt (pull_request) Successful in 36s
Rust / clippy (pull_request) Successful in 54s
This commit is contained in:
+29
-26
@@ -2,20 +2,14 @@
|
||||
|
||||
namespace ZShell::llm {
|
||||
|
||||
LlmTool::LlmTool(QObject* parent) : QObject(parent) {}
|
||||
LlmTool::LlmTool(ToolRegistry* registry, QObject* parent)
|
||||
: QObject(parent), m_registry(registry) {}
|
||||
|
||||
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;
|
||||
const int tokens =
|
||||
qBound(512, m_contextSize / 4, DefaultInlineChars / CharsPerToken);
|
||||
return tokens * CharsPerToken;
|
||||
bool LlmTool::available(const ToolContext& context) const {
|
||||
Q_UNUSED(context);
|
||||
return true;
|
||||
}
|
||||
|
||||
void LlmTool::cancel() {}
|
||||
@@ -33,30 +27,22 @@ QJsonObject LlmTool::specification() const {
|
||||
|
||||
ToolRegistry::ToolRegistry(QObject* parent) : QObject(parent) {}
|
||||
|
||||
void ToolRegistry::setEnabled(bool value) {
|
||||
if (m_enabled == value) return;
|
||||
m_enabled = value;
|
||||
Q_EMIT enabledChanged();
|
||||
}
|
||||
|
||||
void ToolRegistry::registerTool(LlmTool* tool) {
|
||||
if (!tool || m_tools.contains(tool)) return;
|
||||
tool->setParent(this);
|
||||
tool->setContextSize(m_contextSize);
|
||||
m_tools.append(tool);
|
||||
}
|
||||
|
||||
LlmTool* ToolRegistry::tool(const QString& name) const {
|
||||
for (const auto* tool : m_tools)
|
||||
if (tool->name() == name) return const_cast<LlmTool*>(tool);
|
||||
for (auto* tool : m_tools)
|
||||
if (tool->name() == name) return tool;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QJsonArray ToolRegistry::specifications() const {
|
||||
if (!m_enabled) return {};
|
||||
QJsonArray ToolRegistry::specifications(const ToolContext& context) const {
|
||||
QJsonArray specs;
|
||||
for (const auto* tool : m_tools)
|
||||
specs.append(tool->specification());
|
||||
for (auto* tool : m_tools)
|
||||
if (tool->available(context)) specs.append(tool->specification());
|
||||
return specs;
|
||||
}
|
||||
|
||||
@@ -68,8 +54,25 @@ void ToolRegistry::cancelAll() {
|
||||
void ToolRegistry::setContextSize(int value) {
|
||||
if (m_contextSize == value) return;
|
||||
m_contextSize = value;
|
||||
for (auto* tool : m_tools)
|
||||
tool->setContextSize(value);
|
||||
}
|
||||
|
||||
void ToolRegistry::setEnabled(bool value) {
|
||||
if (m_enabled == value) return;
|
||||
m_enabled = value;
|
||||
}
|
||||
|
||||
void ToolRegistry::setSandboxEnabled(bool value) {
|
||||
if (m_sandbox == value) return;
|
||||
m_sandbox = value;
|
||||
}
|
||||
|
||||
int ToolRegistry::outputBudgetChars(int callCount) const {
|
||||
if (m_contextSize <= 0) return DefaultInlineChars;
|
||||
const int tokens = qBound(
|
||||
MinBudgetTokens,
|
||||
m_contextSize / qMax(1, callCount),
|
||||
DefaultInlineChars / CharsPerToken);
|
||||
return tokens * CharsPerToken;
|
||||
}
|
||||
|
||||
} // namespace ZShell::llm
|
||||
|
||||
Reference in New Issue
Block a user