Utils::AiAssistance Namespace
namespace Utils::AiAssistanceThe AiAssistance namespace connects code that wants an AI to do something with the plugins that can do it. More...
| Header: | #include <aiassistance.h> |
Functions
| Utils::Id | clipboardProviderId() |
| QAction * | createAction(const QString &text, const std::function<AiRequest ()> &request, QObject *parent) |
| QString | excerpt(const Utils::FilePath &filePath, const Utils::Text::Range &range) |
| bool | hasTargets(Utils::AiRequest::Mode mode = AiRequest::Interactive) |
| void | onTargetsChanged(QObject *guard, const std::function<void ()> &callback) |
| Utils::AiProvider * | provider(Utils::Id providerId) |
| QList<Utils::AiProvider *> | providers() |
| std::optional<Utils::AiTargetSelection> | rememberedSelection(Utils::Id requestId) |
| Utils::AiResponse * | submit(const Utils::AiRequest &request) |
| Utils::AiResponse * | submit(const Utils::AiRequest &request, const Utils::AiTargetSelection &selection) |
| QString | toPlainText(const Utils::AiRequest &request) |
Detailed Description
A requester describes the work in an AiRequest: a prompt, context items such as files, text snippets and images, and whether the user is meant to continue the conversation (AiRequest::Interactive) or the requester wants the answer back (AiRequest::Headless). It passes the request to submit(), which lets the user pick a target, or to the overload taking an AiTargetSelection to bypass the picker.
An AI integration derives from AiProvider, announces what it can talk to with setTargets(), and carries out requests in AiProvider::execute().
A built-in provider copies the request to the clipboard as plain text, so a user can always paste it into an agent Qt Creator does not know about.
Function Documentation
Utils::Id AiAssistance::clipboardProviderId()
Returns the id of the built-in provider that copies requests to the clipboard.
QAction *AiAssistance::createAction(const QString &text, const std::function<AiRequest ()> &request, QObject *parent)
Creates an action with text and parent that submits the request request returns when triggered. The action is disabled while no target is available.
QString AiAssistance::excerpt(const Utils::FilePath &filePath, const Utils::Text::Range &range)
Returns the lines of filePath that range covers, from its first to its last line, or an empty string if the file cannot be read.
bool AiAssistance::hasTargets(Utils::AiRequest::Mode mode = AiRequest::Interactive)
Returns whether a target can run requests in mode.
void AiAssistance::onTargetsChanged(QObject *guard, const std::function<void ()> &callback)
Calls callback whenever a provider is added or removed or changes its targets, until guard is destroyed.
Utils::AiProvider *AiAssistance::provider(Utils::Id providerId)
Returns the provider with providerId, if it is registered.
QList<Utils::AiProvider *> AiAssistance::providers()
Returns the registered providers. The clipboard provider comes last.
std::optional<Utils::AiTargetSelection> AiAssistance::rememberedSelection(Utils::Id requestId)
Returns the target the user picked the last time a request with requestId was submitted, or for any request if there was none with that id yet.
Utils::AiResponse *AiAssistance::submit(const Utils::AiRequest &request)
Lets the user pick a target for request, with the target picked last time for the same request id preselected, and carries it out there.
If the user cancels, the response finishes with an error.
Utils::AiResponse *AiAssistance::submit(const Utils::AiRequest &request, const Utils::AiTargetSelection &selection)
Carries out request on the target in selection, without asking the user.
QString AiAssistance::toPlainText(const Utils::AiRequest &request)
Returns request as text for an agent that gets nothing else: the prompt, followed by the context. Files are referenced by path, with the lines a range covers quoted. Images cannot be put into text and are only named.
Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.