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
79 lines
1.9 KiB
C++
79 lines
1.9 KiB
C++
#include "tool.hpp"
|
|
|
|
namespace ZShell::llm {
|
|
|
|
LlmTool::LlmTool(ToolRegistry* registry, QObject* parent)
|
|
: QObject(parent), m_registry(registry) {}
|
|
|
|
LlmTool::~LlmTool() = default;
|
|
|
|
bool LlmTool::available(const ToolContext& context) const {
|
|
Q_UNUSED(context);
|
|
return true;
|
|
}
|
|
|
|
void LlmTool::cancel() {}
|
|
|
|
QJsonObject LlmTool::specification() const {
|
|
QJsonObject function;
|
|
function[QStringLiteral("name")] = name();
|
|
function[QStringLiteral("description")] = description();
|
|
function[QStringLiteral("parameters")] = parameters();
|
|
QJsonObject spec;
|
|
spec[QStringLiteral("type")] = QStringLiteral("function");
|
|
spec[QStringLiteral("function")] = function;
|
|
return spec;
|
|
}
|
|
|
|
ToolRegistry::ToolRegistry(QObject* parent) : QObject(parent) {}
|
|
|
|
void ToolRegistry::registerTool(LlmTool* tool) {
|
|
if (!tool || m_tools.contains(tool)) return;
|
|
tool->setParent(this);
|
|
m_tools.append(tool);
|
|
}
|
|
|
|
LlmTool* ToolRegistry::tool(const QString& name) const {
|
|
for (auto* tool : m_tools)
|
|
if (tool->name() == name) return tool;
|
|
return nullptr;
|
|
}
|
|
|
|
QJsonArray ToolRegistry::specifications(const ToolContext& context) const {
|
|
QJsonArray specs;
|
|
for (auto* tool : m_tools)
|
|
if (tool->available(context)) specs.append(tool->specification());
|
|
return specs;
|
|
}
|
|
|
|
void ToolRegistry::cancelAll() {
|
|
for (auto* tool : m_tools)
|
|
tool->cancel();
|
|
}
|
|
|
|
void ToolRegistry::setContextSize(int value) {
|
|
if (m_contextSize == value) return;
|
|
m_contextSize = 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
|