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

Generic client for communicating with LLM services. More...

#include <LLMClient.hpp>

Inheritance diagram for ai::LLMClient:
Inheritance graph
Collaboration diagram for ai::LLMClient:
Collaboration graph

Public Member Functions

 LLMClient (LLMProvider provider=LLMProvider::Ollama, const std::string &model="llama3.2", const std::string &baseUrl="")
 
 ~LLMClient () 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
 
std::string GetProviderName () const override
 Get the name of the AI provider.
 
std::string GetServiceId () const override
 Unique identifier for this service instance.
 
void SetBaseUrl (const std::string &url)
 
void SetProvider (LLMProvider provider)
 
void SetApiKey (const std::string &apiKey)
 
LLMProvider GetProvider () const
 
std::string GetBaseUrl () const
 
std::vector< ModelInfo > GetInstalledModels () const
 Get list of installed models (Ollama/LM Studio only)
 
std::string GetServiceType () const override
 Type of service ("ai", "analyzer", "exporter", etc.)
 

Static Public Member Functions

static std::string GetDefaultBaseUrl (LLMProvider provider)
 Get default base URL for a provider.
 

Private Member Functions

std::string SendHttpPost (const std::string &endpoint, const std::string &jsonBody) const
 
std::string SendHttpGet (const std::string &endpoint) const
 
std::string BuildRequestBody (const std::string &prompt) const
 
std::string ParseResponse (const std::string &response) const
 

Private Attributes

LLMProvider m_provider
 
std::string m_model
 
std::string m_baseUrl
 
std::string m_apiKey
 

Detailed Description

Generic client for communicating with LLM services.

Supports multiple providers:

Constructor & Destructor Documentation

◆ LLMClient()

ai::LLMClient::LLMClient ( LLMProvider  provider = LLMProvider::Ollama,
const std::string &  model = "llama3.2",
const std::string &  baseUrl = "" 
)
explicit

◆ ~LLMClient()

ai::LLMClient::~LLMClient ( )
overridedefault

Member Function Documentation

◆ BuildRequestBody()

std::string ai::LLMClient::BuildRequestBody ( const std::string &  prompt) const
private

◆ GetBaseUrl()

std::string ai::LLMClient::GetBaseUrl ( ) const
inline

◆ GetDefaultBaseUrl()

std::string ai::LLMClient::GetDefaultBaseUrl ( LLMProvider  provider)
static

Get default base URL for a provider.

Here is the caller graph for this function:

◆ GetInstalledModels()

std::vector< ModelInfo > ai::LLMClient::GetInstalledModels ( ) const

Get list of installed models (Ollama/LM Studio only)

Returns
Vector of model information

◆ GetModelName()

std::string ai::LLMClient::GetModelName ( ) const
overridevirtual

Get the name of the model being used.

Implements ai::IAIService.

◆ GetProvider()

LLMProvider ai::LLMClient::GetProvider ( ) const
inline

◆ GetProviderName()

std::string ai::LLMClient::GetProviderName ( ) const
overridevirtual

Get the name of the AI provider.

Implements ai::IAIService.

Here is the caller graph for this function:

◆ GetServiceId()

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

Unique identifier for this service instance.

Implements services::IService.

Here is the call graph for this function:

◆ GetServiceType()

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

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

Implements services::IService.

◆ IsAvailable()

bool ai::LLMClient::IsAvailable ( ) const
overridevirtual

Check if the AI service is available.

Returns
true if service can be reached

Implements ai::IAIService.

◆ ParseResponse()

std::string ai::LLMClient::ParseResponse ( const std::string &  response) const
private

◆ SendHttpGet()

std::string ai::LLMClient::SendHttpGet ( const std::string &  endpoint) const
private

◆ SendHttpPost()

std::string ai::LLMClient::SendHttpPost ( const std::string &  endpoint,
const std::string &  jsonBody 
) const
private

◆ SendPrompt()

std::string ai::LLMClient::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.

◆ SetApiKey()

void ai::LLMClient::SetApiKey ( const std::string &  apiKey)

◆ SetBaseUrl()

void ai::LLMClient::SetBaseUrl ( const std::string &  url)

◆ SetModelName()

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

Implements ai::IAIService.

◆ SetProvider()

void ai::LLMClient::SetProvider ( LLMProvider  provider)
Here is the call graph for this function:

Member Data Documentation

◆ m_apiKey

std::string ai::LLMClient::m_apiKey
private

◆ m_baseUrl

std::string ai::LLMClient::m_baseUrl
private

◆ m_model

std::string ai::LLMClient::m_model
private

◆ m_provider

LLMProvider ai::LLMClient::m_provider
private

The documentation for this class was generated from the following files: