58enum class AiProviderKind { None = 0, Anthropic = 1, OpenAI = 2, Google = 3, Qwen = 4, Custom = 5 };
181 AiProvider(wxString baseUrl, wxString apiKey, wxString model)
182 : m_baseUrl(std::move(baseUrl)), m_apiKey(std::move(apiKey)),
183 m_model(std::move(model)) {}
194 void SetDisplayName(
const wxString &name) { m_displayName = name; }
209 static void SaveApiKey(
const wxString &service,
const wxString &apiKey);
213 static wxString
LoadApiKey(
const wxString &service);
214 static void DeleteApiKey(
const wxString &service);
233 virtual std::vector<std::pair<wxString, wxString>>
AuthHeaders()
const = 0;
241 const std::vector<AiChatMessage> &history)
const = 0;
246 virtual wxString
ParseReply(
const wxString &responseBody)
const = 0;
264 static void SendChat(std::shared_ptr<const AiProvider> self, wxEvtHandler *owner,
265 const wxString &context,
266 const std::vector<AiChatMessage> &history,
267 std::function<
void(
bool ok,
const wxString &replyOrError)> callback);
279 wxString m_displayName;
287 explicit AiProviderError(
const std::string &msg) : std::runtime_error(msg) {}
295 const wxString &model);
304 const wxString &displayName,
305 const wxString &baseUrl,
306 const wxString &apiKey,
307 const wxString &model);
wxString AiProviderApiKeyUrl(AiProviderKind kind)
Where to go to create/find an API key for this provider – shown as a link next to that provider's key...
Definition: AiProvider.cpp:230
std::vector< AiCustomProviderConfig > ParseAiCustomProviders(const wxString &json)
Parses Configuration::AiCustomProvidersJson() back into a list; returns an empty list for an empty or...
Definition: AiProvider.cpp:337
AiProviderShape
Which request/response wire format a provider uses. The four built-in AiProviderKinds each hardcode o...
Definition: AiProvider.h:71
std::vector< AiLocalServerPreset > AiKnownLocalServerPresets()
A short, hand-picked list of common local LLM servers – not exhaustive, just the ones popular enough ...
Definition: AiProvider.cpp:309
wxString AiProviderBaseUrl(AiProviderKind kind)
A built-in provider's fixed request URL (Google's own, without the "<model>:generateContent" suffix i...
Definition: AiProvider.cpp:251
wxString AiProviderShapeName(AiProviderShape shape)
Human-readable name for the shape picker in the "Add custom provider" dialog.
Definition: AiProvider.cpp:200
std::shared_ptr< AiProvider > MakeAiProviderForShape(AiProviderShape shape, const wxString &displayName, const wxString &baseUrl, const wxString &apiKey, const wxString &model)
Builds a provider for a user-added custom entry: reuses the exact same request/response-shape impleme...
Definition: AiProvider.cpp:284
wxString AiProviderModelListUrl(AiProviderKind kind)
Where to see this provider's current list of available model ids – shown as a link next to Options' m...
Definition: AiProvider.cpp:240
std::shared_ptr< AiProvider > MakeAiProvider(AiProviderKind kind, const wxString &apiKey, const wxString &model)
Builds the provider for this kind, or nullptr for AiProviderKind::None. Never called with AiProviderK...
Definition: AiProvider.cpp:263
wxString SerializeAiCustomProviders(const std::vector< AiCustomProviderConfig > &providers)
The inverse of ParseAiCustomProviders(), for Configuration:: AiCustomProvidersJson()'s setter.
Definition: AiProvider.cpp:374
wxString NewAiCustomProviderId()
A fresh id for a new custom provider (see AiCustomProviderConfig::id) – never shown to the user,...
Definition: AiProvider.cpp:322
wxString AiProviderKindName(AiProviderKind kind)
Human-readable name for Options/the sidebar's status line.
Definition: AiProvider.cpp:184
wxString AiProviderDefaultModel(AiProviderKind kind)
This provider's built-in default model id, shown as Options' initial value for a not-yet-configured m...
Definition: AiProvider.cpp:209
AiProviderKind
Which AI service to talk to. Persisted as a plain int in Configuration; keep existing values stable a...
Definition: AiProvider.h:58
Thrown by ParseReply() for a response that doesn't parse or doesn't have the expected shape – distinc...
Definition: AiProvider.h:285
Talks to one external AI provider's chat completion HTTP API.
Definition: AiProvider.h:179
static bool NetworkingAvailable()
True if this build of wxWidgets has wxWebRequest at all (>= 3.1.5, built with a working backend) – if...
Definition: AiProvider.cpp:455
virtual std::vector< std::pair< wxString, wxString > > AuthHeaders() const =0
Any additional headers this provider's auth scheme needs, name/value pairs, beyond the "POST JSON" co...
static void SaveApiKey(const wxString &service, const wxString &apiKey)
Saves (or, for an empty key, deletes) an API key for service – a stable identifier: AiProviderKindNam...
Definition: AiProvider.cpp:409
static wxString BuiltinProviderSecretService(AiProviderKind kind)
The secret-store service name for one of the four built-in kinds – just AiProviderKindName(kind),...
Definition: AiProvider.cpp:397
wxString Name() const
AiProviderKindName(Kind()) for a built-in provider, or the user's own chosen name for a custom one (K...
Definition: AiProvider.h:191
static wxString CustomProviderSecretService(const wxString &id)
The secret-store service name for a custom provider's own id – kept distinct from a bare built-in kin...
Definition: AiProvider.cpp:393
virtual wxString BuildRequestBody(const wxString &context, const std::vector< AiChatMessage > &history) const =0
Builds the JSON request body for one chat turn.
virtual wxString RequestUrl() const
The full URL SendChat() will POST to. Virtual so Google's provider can append the model id (its endpo...
Definition: AiProvider.h:229
static void SendChat(std::shared_ptr< const AiProvider > self, wxEvtHandler *owner, const wxString &context, const std::vector< AiChatMessage > &history, std::function< void(bool ok, const wxString &replyOrError)> callback)
Sends one chat turn asynchronously via wxWebRequest and calls callback(ok, replyOrError) exactly once...
Definition: AiProvider.cpp:463
virtual wxString ParseReply(const wxString &responseBody) const =0
Extracts the assistant's reply text from a successful (2xx) response body.
static bool SecretStoreAvailable()
True if this build of wxWidgets has a working wxSecretStore backend (>= 3.1.1, compiled with wxUSE_SE...
Definition: AiProvider.cpp:401
static wxString LoadApiKey(const wxString &service)
Returns the stored key for service, or an empty string if none is stored (also the result if !...
Definition: AiProvider.cpp:429
One turn of a chat conversation.
Definition: AiProvider.h:44
wxString role
"user" or "assistant" – never "system"/"model"/etc.; each provider's own request-building maps this p...
Definition: AiProvider.h:48
One user-added custom provider, as persisted in Configuration's AiCustomProvidersJson() (everything e...
Definition: AiProvider.h:81
wxString id
Stable, internally-generated identifier – never shown in the UI and never reused, so renaming a provi...
Definition: AiProvider.h:86
wxString baseUrl
Full request URL for OpenAI-compatible/Anthropic shapes; for Google's shape, the part before "<model>...
Definition: AiProvider.h:93
wxString name
User-chosen display name, shown in the provider dropdown.
Definition: AiProvider.h:88
One well-known local AI server's connection defaults, offered as a quick-fill preset in the "Add cust...
Definition: AiProvider.h:105