Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Brave search tool #2737

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f4fb3df
Brave search tool calling.
manyoso Jul 25, 2024
a71db10
Change the name to announce the beta.
manyoso Jul 25, 2024
1c9911a
Fix problem with only displaying one source for tool call excerpts.
manyoso Jul 25, 2024
c78c95a
Add the extra snippets to the source excerpts.
manyoso Jul 25, 2024
dda59a9
Fix the way we're injecting the context back into the model for web s…
manyoso Jul 27, 2024
d2ee235
Change the suggestion mode to turn on for tool calls by default.
manyoso Jul 27, 2024
b0578e2
Change the name to inc the beta.
manyoso Jul 27, 2024
b9684ff
Inc again for new beta.
manyoso Jul 28, 2024
7c7558e
Stop hardcoding the tool call checking and rely upon the format advoc…
manyoso Jul 30, 2024
fffd9f3
Refactor to handle errors in tool calling better and add source comme…
manyoso Jul 30, 2024
dfe3e95
Refactor the brave search and introduce an abstraction for tool calls.
manyoso Jul 31, 2024
01f67c7
Begin converting the localdocs to a tool.
manyoso Aug 1, 2024
27b86da
Serialize the source excerpts from and to pure json
manyoso Aug 1, 2024
5fc2ff8
Use parameters which is in keeping with other standard practices.
manyoso Aug 1, 2024
244b826
Implement error handling for tool calls.
manyoso Aug 7, 2024
cedba6c
Tool model.
manyoso Aug 8, 2024
f93b764
Move the usearch submodule to third_party dir.
manyoso Aug 10, 2024
00ecbb7
Add jinja third party dependency.
manyoso Aug 10, 2024
c3cfaff
Refactor and make use of jinja templates.
manyoso Aug 9, 2024
587dd55
Get rid of the name change now that 3.2.0 has been released.
manyoso Aug 13, 2024
227dbfd
Use an enum for tool usage mode.
manyoso Aug 13, 2024
48117cd
Move the jinja processing to mysettings and validation.
manyoso Aug 13, 2024
a673087
Move to a brave search specific settings page.
manyoso Aug 13, 2024
f118720
Don't advertise brave.
manyoso Aug 14, 2024
75dbf9d
Handle the forced usage of tool calls outside of the recursive prompt…
manyoso Aug 14, 2024
991afc6
Abstract the built-in web search completely away from ChatLLM.
manyoso Aug 14, 2024
4cb9569
Breakout the ask before running which can be thought of as a security…
manyoso Aug 14, 2024
054ca43
Display the antenna by introducing notion of privacy scopes to tools.
manyoso Aug 14, 2024
3a56468
Implement all the settings for the web search.
manyoso Aug 14, 2024
4ae6acd
Force tool usage and refactor.
manyoso Aug 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Display the antenna by introducing notion of privacy scopes to tools.
Signed-off-by: Adam Treat <[email protected]>
  • Loading branch information
manyoso committed Aug 14, 2024
commit 054ca43d52437ee086fca59db7d1d2e143f3d729
1 change: 1 addition & 0 deletions gpt4all-chat/bravesearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class BraveSearch : public Tool {
QString name() const override { return tr("Web Search"); }
QString description() const override { return tr("Search the web"); }
QString function() const override { return "web_search"; }
ToolEnums::PrivacyScope privacyScope() const override { return ToolEnums::PrivacyScope::None; }
QJsonObject paramSchema() const override;
QJsonObject exampleParams() const override;
bool isBuiltin() const override { return true; }
Expand Down
1 change: 1 addition & 0 deletions gpt4all-chat/localdocssearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class LocalDocsSearch : public Tool {
QString name() const override { return tr("LocalDocs Search"); }
QString description() const override { return tr("Search the local docs"); }
QString function() const override { return "localdocs_search"; }
ToolEnums::PrivacyScope privacyScope() const override { return ToolEnums::PrivacyScope::Local; }
QJsonObject paramSchema() const override;
bool isBuiltin() const override { return true; }
ToolEnums::UsageMode usageMode() const override { return ToolEnums::UsageMode::ForceUsage; }
Expand Down
3 changes: 3 additions & 0 deletions gpt4all-chat/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "modellist.h"
#include "mysettings.h"
#include "network.h"
#include "toolmodel.h"

#include "../gpt4all-backend/llmodel.h"

Expand Down Expand Up @@ -67,6 +68,8 @@ int main(int argc, char *argv[])
qmlRegisterSingletonInstance("download", 1, 0, "Download", Download::globalInstance());
qmlRegisterSingletonInstance("network", 1, 0, "Network", Network::globalInstance());
qmlRegisterSingletonInstance("localdocs", 1, 0, "LocalDocs", LocalDocs::globalInstance());
qmlRegisterSingletonInstance("toollist", 1, 0, "ToolList", ToolModel::globalInstance());
qmlRegisterUncreatableMetaObject(ToolEnums::staticMetaObject, "toolenums", 1, 0, "ToolEnums", "Error: only enums");
qmlRegisterUncreatableMetaObject(MySettingsEnums::staticMetaObject, "mysettingsenums", 1, 0, "MySettingsEnums", "Error: only enums");

const QUrl url(u"qrc:/gpt4all/main.qml"_qs);
Expand Down
12 changes: 10 additions & 2 deletions gpt4all-chat/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import network
import gpt4all
import localdocs
import mysettings
import toollist
import toolenums

Window {
id: window
Expand Down Expand Up @@ -413,7 +415,11 @@ Window {

ColorOverlay {
id: antennaColored
visible: ModelList.selectableModels.count !== 0 && (currentChat.isServer || currentChat.modelInfo.isOnline || MySettings.networkIsActive)
visible: ModelList.selectableModels.count !== 0
&& (MySettings.networkIsActive
|| currentChat.modelInfo.isOnline
|| currentChat.isServer
|| ToolList.privacyScope === ToolEnums.PrivacyScope.None)
anchors.fill: antennaImage
source: antennaImage
color: theme.styledTextColor
Expand All @@ -422,8 +428,10 @@ Window {
return qsTr("The datalake is enabled")
else if (currentChat.modelInfo.isOnline)
return qsTr("Using a network model")
else if (currentChat.modelInfo.isOnline)
else if (currentChat.isServer)
return qsTr("Server mode is enabled")
else if (ToolList.privacyScope === ToolEnums.PrivacyScope.None)
return qsTr("One or more enabled tools is not private")
return ""
}
ToolTip.visible: maAntenna.containsMouse
Expand Down
12 changes: 12 additions & 0 deletions gpt4all-chat/tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,22 @@ namespace ToolEnums {
ForceUsage, // Attempt to force usage of the tool rather than let the LLM decide. NOTE: Not always possible.
};
Q_ENUM_NS(UsageMode)

// Ordered in increasing levels of privacy
enum class PrivacyScope {
None = 0, // Tool call data does not have any privacy scope
LocalOrg = 1, // Tool call data does not leave the local organization
Local = 2 // Tool call data does not leave the machine
};
Q_ENUM_NS(PrivacyScope)
}

class Tool : public QObject {
Q_OBJECT
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QString description READ description CONSTANT)
Q_PROPERTY(QString function READ function CONSTANT)
Q_PROPERTY(ToolEnums::PrivacyScope privacyScope READ privacyScope CONSTANT)
Q_PROPERTY(QJsonObject paramSchema READ paramSchema CONSTANT)
Q_PROPERTY(QJsonObject exampleParams READ exampleParams CONSTANT)
Q_PROPERTY(QUrl url READ url CONSTANT)
Expand All @@ -54,6 +63,9 @@ class Tool : public QObject {
// [Required] Must be unique. Name of the function to invoke. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
virtual QString function() const = 0;

// [Required] The privacy scope
virtual ToolEnums::PrivacyScope privacyScope() const = 0;

// [Optional] Json schema describing the tool's parameters. An empty object specifies no parameters.
// https://json-schema.org/understanding-json-schema/
// https://platform.openai.com/docs/api-reference/runs/createRun#runs-createrun-tools
Expand Down
11 changes: 11 additions & 0 deletions gpt4all-chat/toolmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ ToolModel::ToolModel()
Tool* localDocsSearch = new LocalDocsSearch;
m_tools.append(localDocsSearch);
m_toolMap.insert(localDocsSearch->function(), localDocsSearch);
connect(localDocsSearch, &Tool::usageModeChanged, this, &ToolModel::privacyScopeChanged);

Tool *braveSearch = new BraveSearch;
m_tools.append(braveSearch);
m_toolMap.insert(braveSearch->function(), braveSearch);
connect(braveSearch, &Tool::usageModeChanged, this, &ToolModel::privacyScopeChanged);
}

bool ToolModel::eventFilter(QObject *obj, QEvent *ev)
Expand All @@ -34,3 +36,12 @@ bool ToolModel::eventFilter(QObject *obj, QEvent *ev)
emit dataChanged(index(0, 0), index(m_tools.size() - 1, 0));
return false;
}

ToolEnums::PrivacyScope ToolModel::privacyScope() const
{
ToolEnums::PrivacyScope scope = ToolEnums::PrivacyScope::Local; // highest scope
for (const Tool *t : m_tools)
if (t->usageMode() != ToolEnums::UsageMode::Disabled)
scope = std::min(scope, t->privacyScope());
return scope;
}
9 changes: 9 additions & 0 deletions gpt4all-chat/toolmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ToolModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(ToolEnums::PrivacyScope privacyScope READ privacyScope NOTIFY privacyScopeChanged)

public:
static ToolModel *globalInstance();
Expand All @@ -17,6 +18,7 @@ class ToolModel : public QAbstractListModel
NameRole = Qt::UserRole + 1,
DescriptionRole,
FunctionRole,
PrivacyScopeRole,
ParametersRole,
UrlRole,
ApiKeyRole,
Expand Down Expand Up @@ -46,6 +48,8 @@ class ToolModel : public QAbstractListModel
return item->description();
case FunctionRole:
return item->function();
case PrivacyScopeRole:
return QVariant::fromValue(item->privacyScope());
case ParametersRole:
return item->paramSchema();
case UrlRole:
Expand All @@ -69,6 +73,7 @@ class ToolModel : public QAbstractListModel
roles[NameRole] = "name";
roles[DescriptionRole] = "description";
roles[FunctionRole] = "function";
roles[PrivacyScopeRole] = "privacyScope";
roles[ParametersRole] = "parameters";
roles[UrlRole] = "url";
roles[ApiKeyRole] = "apiKey";
Expand All @@ -94,8 +99,12 @@ class ToolModel : public QAbstractListModel

int count() const { return m_tools.size(); }

// Returns the least private scope of all enabled tools
ToolEnums::PrivacyScope privacyScope() const;

Q_SIGNALS:
void countChanged();
void privacyScopeChanged();
void valueChanged(int index, const QString &value);

protected:
Expand Down