LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
Loading...
Searching...
No Matches
ai::OpenAIClient Class Reference

Client for OpenAI-compatible APIs (OpenAI, xAI Grok, etc.) More...

#include <OpenAIClient.hpp>

Inheritance diagram for ai::OpenAIClient:
Inheritance graph
Collaboration diagram for ai::OpenAIClient:
Collaboration graph

Public Member Functions

 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.)
 

Private Member Functions

std::string SendHttpPost (const std::string &endpoint, const std::string &jsonBody, const std::string &authHeader) const
 

Private Attributes

std::string m_apiKey
 
std::string m_model
 
std::string m_baseUrl
 
std::string m_providerName
 

Detailed Description

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).

Constructor & Destructor Documentation

◆ 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

Member Function Documentation

◆ GetModelName()

std::string ai::OpenAIClient::GetModelName ( ) const
inlineoverridevirtual

Get the name of the model being used.

Implements ai::IAIService.

◆ GetProviderName()

virtual std::string ai::OpenAIClient::GetProviderName ( ) const
inlineoverridevirtual

Get the name of the AI provider.

Implements ai::IAIService.

◆ GetServiceId()

std::string ai::OpenAIClient::GetServiceId ( ) const
overridevirtual

Unique identifier for this service instance.

Implements services::IService.

◆ GetServiceType()

std::string ai::IAIService::GetServiceType ( ) const
inlineoverridevirtualinherited

Type of service ("ai", "analyzer", "exporter", etc.)

Implements services::IService.

◆ 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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
promptThe text prompt to send
callbackFunction called with response chunks as they arrive
Returns
Complete response text

Implements ai::IAIService.

Here is the call graph for this function:

◆ SetModelName()

void ai::OpenAIClient::SetModelName ( const std::string &  model)
overridevirtual

Implements ai::IAIService.

Member Data Documentation

◆ 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: