mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-06-29 16:58:18 +00:00
Use an enum for tool usage mode.
Signed-off-by: Adam Treat <treat.adam@gmail.com>
This commit is contained in:
parent
587dd55b73
commit
227dbfd18b
@ -80,16 +80,10 @@ QJsonObject BraveSearch::exampleParams() const
|
||||
return exampleDoc.object();
|
||||
}
|
||||
|
||||
bool BraveSearch::isEnabled() const
|
||||
ToolEnums::UsageMode BraveSearch::usageMode() const
|
||||
{
|
||||
// FIXME: Refer to mysettings
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BraveSearch::forceUsage() const
|
||||
{
|
||||
// FIXME: Refer to mysettings
|
||||
return false;
|
||||
// FIXME: This needs to be a setting
|
||||
return ToolEnums::UsageMode::Enabled;
|
||||
}
|
||||
|
||||
void BraveAPIWorker::request(const QString &apiKey, const QString &query, int count)
|
||||
|
@ -53,9 +53,8 @@ public:
|
||||
QString function() const override { return "brave_search"; }
|
||||
QJsonObject paramSchema() const override;
|
||||
QJsonObject exampleParams() const override;
|
||||
bool isEnabled() const override;
|
||||
bool isBuiltin() const override { return true; }
|
||||
bool forceUsage() const override;
|
||||
ToolEnums::UsageMode usageMode() const override;
|
||||
bool excerpts() const override { return true; }
|
||||
|
||||
private:
|
||||
|
@ -766,6 +766,8 @@ bool ChatLLM::promptInternal(const QList<QString> &collectionList, const QString
|
||||
if (!isModelLoaded())
|
||||
return false;
|
||||
|
||||
// FIXME: This should be made agnostic to localdocs and rely upon the force usage usage mode
|
||||
// and also we have to honor the ask before running mode.
|
||||
QList<SourceExcerpt> localDocsExcerpts;
|
||||
if (!collectionList.isEmpty() && !isToolCallResponse) {
|
||||
LocalDocsSearch localdocs;
|
||||
@ -1345,7 +1347,7 @@ void ChatLLM::processSystemPrompt()
|
||||
int c = ToolModel::globalInstance()->count();
|
||||
for (int i = 0; i < c; ++i) {
|
||||
Tool *t = ToolModel::globalInstance()->get(i);
|
||||
if (t->isEnabled() && !t->forceUsage())
|
||||
if (t->usageMode() == ToolEnums::UsageMode::Enabled)
|
||||
toolList.push_back(t->jinjaValue());
|
||||
}
|
||||
params.insert({"toolList", toolList});
|
||||
|
@ -38,9 +38,8 @@ public:
|
||||
QString description() const override { return tr("Search the local docs"); }
|
||||
QString function() const override { return "localdocs_search"; }
|
||||
QJsonObject paramSchema() const override;
|
||||
bool isEnabled() const override { return true; }
|
||||
bool isBuiltin() const override { return true; }
|
||||
bool forceUsage() const override { return true; }
|
||||
ToolEnums::UsageMode usageMode() const override { return ToolEnums::UsageMode::ForceUsage; }
|
||||
bool excerpts() const override { return true; }
|
||||
|
||||
private:
|
||||
|
@ -174,21 +174,21 @@ MySettingsTab {
|
||||
MyTextArea {
|
||||
id: systemPromptArea
|
||||
anchors.fill: parent
|
||||
text: root.currentModelInfo.systemPrompt
|
||||
text: root.currentModelInfo.systemPromptTemplate
|
||||
Connections {
|
||||
target: MySettings
|
||||
function onSystemPromptChanged() {
|
||||
systemPromptArea.text = root.currentModelInfo.systemPrompt;
|
||||
systemPromptArea.text = root.currentModelInfo.systemPromptTemplate;
|
||||
}
|
||||
}
|
||||
Connections {
|
||||
target: root
|
||||
function onCurrentModelInfoChanged() {
|
||||
systemPromptArea.text = root.currentModelInfo.systemPrompt;
|
||||
systemPromptArea.text = root.currentModelInfo.systemPromptTemplate;
|
||||
}
|
||||
}
|
||||
onTextChanged: {
|
||||
MySettings.setModelSystemPrompt(root.currentModelInfo, text)
|
||||
MySettings.setModelSystemPromptTemplate(root.currentModelInfo, text)
|
||||
}
|
||||
Accessible.role: Accessible.EditableText
|
||||
}
|
||||
|
@ -15,6 +15,14 @@ namespace ToolEnums {
|
||||
UnknownError = 499,
|
||||
};
|
||||
Q_ENUM_NS(Error)
|
||||
|
||||
enum class UsageMode {
|
||||
Disabled, // Completely disabled
|
||||
Enabled, // Enabled and the model decides whether to run
|
||||
AskBeforeRunning, // Enabled and model decides but the user is queried whether they want the tool to run in every instance
|
||||
ForceUsage, // Attempt to force usage of the tool rather than let the LLM decide. NOTE: Not always possible.
|
||||
};
|
||||
Q_ENUM_NS(UsageMode)
|
||||
}
|
||||
|
||||
class Tool : public QObject {
|
||||
@ -25,9 +33,8 @@ class Tool : public QObject {
|
||||
Q_PROPERTY(QJsonObject paramSchema READ paramSchema CONSTANT)
|
||||
Q_PROPERTY(QJsonObject exampleParams READ exampleParams CONSTANT)
|
||||
Q_PROPERTY(QUrl url READ url CONSTANT)
|
||||
Q_PROPERTY(bool isEnabled READ isEnabled NOTIFY isEnabledChanged)
|
||||
Q_PROPERTY(bool isBuiltin READ isBuiltin CONSTANT)
|
||||
Q_PROPERTY(bool forceUsage READ forceUsage NOTIFY forceUsageChanged)
|
||||
Q_PROPERTY(ToolEnums::UsageMode usageMode READ usageMode NOTIFY usageModeChanged)
|
||||
Q_PROPERTY(bool excerpts READ excerpts CONSTANT)
|
||||
|
||||
public:
|
||||
@ -61,14 +68,11 @@ public:
|
||||
// [Optional] The local file or remote resource use to invoke the tool.
|
||||
virtual QUrl url() const { return QUrl(); }
|
||||
|
||||
// [Optional] Whether the tool is currently enabled
|
||||
virtual bool isEnabled() const { return false; }
|
||||
|
||||
// [Optional] Whether the tool is built-in
|
||||
virtual bool isBuiltin() const { return false; }
|
||||
|
||||
// [Optional] Whether we should attempt to force usage of the tool rather than let the LLM decide. NOTE: Not always possible.
|
||||
virtual bool forceUsage() const { return false; }
|
||||
// [Optional] The current usage mode
|
||||
virtual ToolEnums::UsageMode usageMode() const { return ToolEnums::UsageMode::Disabled; }
|
||||
|
||||
// [Optional] Whether json result produces source excerpts.
|
||||
virtual bool excerpts() const { return false; }
|
||||
@ -83,9 +87,7 @@ public:
|
||||
jinja2::Value jinjaValue() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void isEnabledChanged();
|
||||
void forceUsageChanged();
|
||||
|
||||
void usageModeChanged();
|
||||
};
|
||||
|
||||
#endif // TOOL_H
|
||||
|
@ -21,9 +21,8 @@ public:
|
||||
UrlRole,
|
||||
ApiKeyRole,
|
||||
KeyRequiredRole,
|
||||
IsEnabledRole,
|
||||
IsBuiltinRole,
|
||||
ForceUsageRole,
|
||||
UsageModeRole,
|
||||
ExcerptsRole,
|
||||
};
|
||||
|
||||
@ -50,12 +49,10 @@ public:
|
||||
return item->paramSchema();
|
||||
case UrlRole:
|
||||
return item->url();
|
||||
case IsEnabledRole:
|
||||
return item->isEnabled();
|
||||
case IsBuiltinRole:
|
||||
return item->isBuiltin();
|
||||
case ForceUsageRole:
|
||||
return item->forceUsage();
|
||||
case UsageModeRole:
|
||||
return QVariant::fromValue(item->usageMode());
|
||||
case ExcerptsRole:
|
||||
return item->excerpts();
|
||||
}
|
||||
@ -73,9 +70,8 @@ public:
|
||||
roles[UrlRole] = "url";
|
||||
roles[ApiKeyRole] = "apiKey";
|
||||
roles[KeyRequiredRole] = "keyRequired";
|
||||
roles[IsEnabledRole] = "isEnabled";
|
||||
roles[IsBuiltinRole] = "isBuiltin";
|
||||
roles[ForceUsageRole] = "forceUsage";
|
||||
roles[UsageModeRole] = "usageMode";
|
||||
roles[ExcerptsRole] = "excerpts";
|
||||
return roles;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user