mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2024-10-01 01:06:10 -04:00
01f67c74ea
Signed-off-by: Adam Treat <treat.adam@gmail.com>
72 lines
2.3 KiB
C++
72 lines
2.3 KiB
C++
#ifndef TOOL_H
|
|
#define TOOL_H
|
|
|
|
#include <QObject>
|
|
#include <QJsonObject>
|
|
|
|
using namespace Qt::Literals::StringLiterals;
|
|
|
|
namespace ToolEnums {
|
|
Q_NAMESPACE
|
|
enum class ConnectionType {
|
|
Builtin = 0, // A built-in tool with bespoke connection type
|
|
Local = 1, // Starts a local process and communicates via stdin/stdout/stderr
|
|
LocalServer = 2, // Connects to an existing local process and communicates via stdin/stdout/stderr
|
|
Remote = 3, // Starts a remote process and communicates via some networking protocol TBD
|
|
RemoteServer = 4 // Connects to an existing remote process and communicates via some networking protocol TBD
|
|
};
|
|
Q_ENUM_NS(ConnectionType)
|
|
}
|
|
using namespace ToolEnums;
|
|
|
|
struct ToolInfo {
|
|
Q_GADGET
|
|
Q_PROPERTY(QString name MEMBER name)
|
|
Q_PROPERTY(QString description MEMBER description)
|
|
Q_PROPERTY(QJsonObject parameters MEMBER parameters)
|
|
Q_PROPERTY(bool isEnabled MEMBER isEnabled)
|
|
Q_PROPERTY(ConnectionType connectionType MEMBER connectionType)
|
|
|
|
public:
|
|
QString name;
|
|
QString description;
|
|
QJsonObject parameters;
|
|
bool isEnabled;
|
|
ConnectionType connectionType;
|
|
|
|
// FIXME: Should we go with essentially the OpenAI/ollama consensus for these tool
|
|
// info files? If you install a tool in GPT4All should it need to meet the spec for these:
|
|
// https://platform.openai.com/docs/api-reference/runs/createRun#runs-createrun-tools
|
|
// https://github.com/ollama/ollama/blob/main/docs/api.md#chat-request-with-tools
|
|
QJsonObject toJson() const
|
|
{
|
|
QJsonObject result;
|
|
result.insert("name", name);
|
|
result.insert("description", description);
|
|
result.insert("parameters", parameters);
|
|
return result;
|
|
}
|
|
|
|
static ToolInfo fromJson(const QString &json);
|
|
|
|
bool operator==(const ToolInfo &other) const {
|
|
return name == other.name;
|
|
}
|
|
bool operator!=(const ToolInfo &other) const {
|
|
return !(*this == other);
|
|
}
|
|
};
|
|
Q_DECLARE_METATYPE(ToolInfo)
|
|
|
|
class Tool : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
Tool() : QObject(nullptr) {}
|
|
virtual ~Tool() {}
|
|
|
|
// FIXME: How to handle errors?
|
|
virtual QString run(const QJsonObject ¶meters, qint64 timeout = 2000) = 0;
|
|
};
|
|
|
|
#endif // TOOL_H
|