Client for OpenAI-compatible APIs (OpenAI, xAI Grok, etc.)
More...
#include <OpenAIClient.hpp>
|
| | OpenAIClient (const std::string &apiKey, const std::string &model="gpt-4o-mini", const std::string &baseUrl="https://api.openai.com/v1", const std::string &providerName="openai") |
| |
| | ~OpenAIClient () override=default |
| |
| std::string | SendPrompt (const std::string &prompt, std::function< void(const std::string &)> callback=nullptr) override |
| | Send a prompt to the AI and get a response.
|
| |
| bool | IsAvailable () const override |
| | Check if the AI service is available.
|
| |
| std::string | GetModelName () const override |
| | Get the name of the model being used.
|
| |
| void | SetModelName (const std::string &model) override |
| |
| virtual std::string | GetProviderName () const override |
| | Get the name of the AI provider.
|
| |
| std::string | GetServiceId () const override |
| | Unique identifier for this service instance.
|
| |
| std::string | GetServiceType () const override |
| | Type of service ("ai", "analyzer", "exporter", etc.)
|
| |
|
| std::string | SendHttpPost (const std::string &endpoint, const std::string &jsonBody, const std::string &authHeader) const |
| |
Client for OpenAI-compatible APIs (OpenAI, xAI Grok, etc.)
Supports any OpenAI-compatible endpoint. Pass the correct baseUrl and providerName when constructing for non-OpenAI providers (e.g. xAI).
◆ OpenAIClient()
| ai::OpenAIClient::OpenAIClient |
( |
const std::string & |
apiKey, |
|
|
const std::string & |
model = "gpt-4o-mini", |
|
|
const std::string & |
baseUrl = "https://api.openai.com/v1", |
|
|
const std::string & |
providerName = "openai" |
|
) |
| |
|
explicit |
◆ ~OpenAIClient()
| ai::OpenAIClient::~OpenAIClient |
( |
| ) |
|
|
overridedefault |
◆ GetModelName()
| std::string ai::OpenAIClient::GetModelName |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ GetProviderName()
| virtual std::string ai::OpenAIClient::GetProviderName |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ GetServiceId()
| std::string ai::OpenAIClient::GetServiceId |
( |
| ) |
const |
|
overridevirtual |
◆ GetServiceType()
| std::string ai::IAIService::GetServiceType |
( |
| ) |
const |
|
inlineoverridevirtualinherited |
◆ IsAvailable()
| bool ai::OpenAIClient::IsAvailable |
( |
| ) |
const |
|
overridevirtual |
Check if the AI service is available.
- Returns
- true if service can be reached
Implements ai::IAIService.
◆ SendHttpPost()
| std::string ai::OpenAIClient::SendHttpPost |
( |
const std::string & |
endpoint, |
|
|
const std::string & |
jsonBody, |
|
|
const std::string & |
authHeader |
|
) |
| const |
|
private |
◆ SendPrompt()
| std::string ai::OpenAIClient::SendPrompt |
( |
const std::string & |
prompt, |
|
|
std::function< void(const std::string &)> |
callback = nullptr |
|
) |
| |
|
overridevirtual |
Send a prompt to the AI and get a response.
- Parameters
-
| prompt | The text prompt to send |
| callback | Function called with response chunks as they arrive |
- Returns
- Complete response text
Implements ai::IAIService.
◆ SetModelName()
| void ai::OpenAIClient::SetModelName |
( |
const std::string & |
model | ) |
|
|
overridevirtual |
◆ m_apiKey
| std::string ai::OpenAIClient::m_apiKey |
|
private |
◆ m_baseUrl
| std::string ai::OpenAIClient::m_baseUrl |
|
private |
◆ m_model
| std::string ai::OpenAIClient::m_model |
|
private |
◆ m_providerName
| std::string ai::OpenAIClient::m_providerName |
|
private |
The documentation for this class was generated from the following files: