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:
+37
-22
@@ -10,61 +10,76 @@
|
||||
|
||||
namespace ZShell::llm {
|
||||
|
||||
struct ToolResult {
|
||||
bool ok = false;
|
||||
QString text;
|
||||
};
|
||||
|
||||
struct ToolContext {
|
||||
QString toolCallId;
|
||||
QString workspace;
|
||||
int outputBudgetChars = 0;
|
||||
};
|
||||
|
||||
using ToolDone = std::function<void(const ToolResult&)>;
|
||||
|
||||
class ToolRegistry;
|
||||
|
||||
class LlmTool : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LlmTool(QObject* parent = nullptr);
|
||||
explicit LlmTool(ToolRegistry* registry, QObject* parent = nullptr);
|
||||
~LlmTool() override;
|
||||
|
||||
[[nodiscard]] virtual QString name() const = 0;
|
||||
[[nodiscard]] virtual QString description() const = 0;
|
||||
[[nodiscard]] virtual QJsonObject parameters() const = 0;
|
||||
|
||||
[[nodiscard]] virtual bool available(const ToolContext& context) const;
|
||||
|
||||
virtual void execute(
|
||||
const QString& toolCallId,
|
||||
const QJsonObject& args,
|
||||
int outputBudgetChars,
|
||||
std::function<void(const QJsonObject& result)> done) = 0;
|
||||
const ToolContext& context, const QJsonObject& args, ToolDone done) = 0;
|
||||
|
||||
virtual void cancel();
|
||||
|
||||
[[nodiscard]] QJsonObject specification() const;
|
||||
|
||||
[[nodiscard]] int contextSize() const { return m_contextSize; }
|
||||
void setContextSize(int value);
|
||||
[[nodiscard]] ToolRegistry* registry() const { return m_registry; }
|
||||
|
||||
[[nodiscard]] int inlineBudgetChars() const;
|
||||
|
||||
static constexpr int CharsPerToken = 4;
|
||||
static constexpr int DefaultInlineChars = 64 * 1024;
|
||||
|
||||
protected:
|
||||
int m_contextSize = 0;
|
||||
private:
|
||||
ToolRegistry* m_registry;
|
||||
};
|
||||
|
||||
class ToolRegistry : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
|
||||
|
||||
public:
|
||||
explicit ToolRegistry(QObject* parent = nullptr);
|
||||
|
||||
[[nodiscard]] bool enabled() const { return m_enabled; }
|
||||
void setEnabled(bool value);
|
||||
|
||||
void registerTool(LlmTool* tool);
|
||||
[[nodiscard]] LlmTool* tool(const QString& name) const;
|
||||
[[nodiscard]] QJsonArray specifications() const;
|
||||
[[nodiscard]] QList<LlmTool*> tools() const { return m_tools; }
|
||||
[[nodiscard]] QJsonArray specifications(const ToolContext& context) const;
|
||||
void cancelAll();
|
||||
|
||||
[[nodiscard]] bool enabled() const { return m_enabled; }
|
||||
void setEnabled(bool value);
|
||||
[[nodiscard]] bool sandboxEnabled() const { return m_sandbox; }
|
||||
void setSandboxEnabled(bool value);
|
||||
|
||||
[[nodiscard]] int contextSize() const { return m_contextSize; }
|
||||
void setContextSize(int value);
|
||||
|
||||
Q_SIGNALS:
|
||||
void enabledChanged();
|
||||
[[nodiscard]] int outputBudgetChars(int callCount) const;
|
||||
|
||||
static constexpr int CharsPerToken = 4;
|
||||
static constexpr int DefaultInlineChars = 64 * 1024;
|
||||
static constexpr int MinBudgetTokens = 512;
|
||||
|
||||
private:
|
||||
bool m_enabled = true;
|
||||
bool m_sandbox = true;
|
||||
int m_contextSize = 0;
|
||||
QList<LlmTool*> m_tools;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user