NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
neograph::llm::OpenAIProvider Class Reference

LLM provider for OpenAI-compatible APIs. More...

#include <openai_provider.h>

Inheritance diagram for neograph::llm::OpenAIProvider:
[legend]
Collaboration diagram for neograph::llm::OpenAIProvider:
[legend]

Classes

struct  Config
 Configuration for OpenAI-compatible API connections. More...
 

Public Member Functions

asio::awaitable< ChatCompletioncomplete_async (const CompletionParams &params) override
 Async completion — dispatches over the owned ConnPool so successive calls reuse a kept-alive TCP+TLS connection.
 
ChatCompletion complete_stream (const CompletionParams &params, const StreamCallback &on_chunk) override
 Sync completion is inherited from Provider::complete(), which drives complete_async via neograph::async::run_sync.
 
std::string get_name () const override
 Get the provider name (e.g., "openai", "claude").
 
asio::awaitable< ChatCompletioninvoke (const CompletionParams &params, StreamCallback on_chunk) override
 v1.0 single-dispatch override (Candidate 6 PR6).
 
 ~OpenAIProvider ()
 Destructor — shuts down the long-lived HTTP loop + worker thread held alongside the ConnPool.
 
- Public Member Functions inherited from neograph::Provider
virtual ChatCompletion complete (const CompletionParams &params)
 Perform a synchronous LLM completion.
 
virtual asio::awaitable< ChatCompletioncomplete_stream_async (const CompletionParams &params, const StreamCallback &on_chunk)
 Async streaming completion.
 

Static Public Member Functions

static std::unique_ptr< OpenAIProvidercreate (const Config &config)
 Create an OpenAI provider instance.
 
static std::shared_ptr< Providercreate_shared (const Config &config)
 Same as create but returns a shared_ptr<Provider>.
 

Detailed Description

LLM provider for OpenAI-compatible APIs.

Connects to any endpoint following the OpenAI chat completions API format (/v1/chat/completions). Configure via Config struct.

auto provider = OpenAIProvider::create({
.api_key = "sk-...",
.default_model = "gpt-4o-mini"
});
static std::unique_ptr< OpenAIProvider > create(const Config &config)
Create an OpenAI provider instance.
See also
SchemaProvider for multi-vendor support (Claude, Gemini).

Definition at line 38 of file openai_provider.h.

Member Function Documentation

◆ complete_async()

asio::awaitable< ChatCompletion > neograph::llm::OpenAIProvider::complete_async ( const CompletionParams params)
overridevirtual

Async completion — dispatches over the owned ConnPool so successive calls reuse a kept-alive TCP+TLS connection.

The previous "fresh socket per call" comment has aged out: the pool is bound to a long-lived background io_context owned by this provider, so run_sync per-call destruction no longer affects pool lifetime.

Reimplemented from neograph::Provider.

◆ create()

static std::unique_ptr< OpenAIProvider > neograph::llm::OpenAIProvider::create ( const Config config)
static

Create an OpenAI provider instance.

Parameters
configConnection and authentication configuration.
Returns
A unique_ptr to the created provider.

◆ create_shared()

static std::shared_ptr< Provider > neograph::llm::OpenAIProvider::create_shared ( const Config config)
static

Same as create but returns a shared_ptr<Provider>.

Useful when one provider needs to be reused across multiple NodeFactory closures, A2A servers, or threads — capturing a unique_ptr into a copyable lambda is impossible without an explicit release(). This peer drops the boilerplate.

◆ get_name()

std::string neograph::llm::OpenAIProvider::get_name ( ) const
inlineoverridevirtual

Get the provider name (e.g., "openai", "claude").

Opaque debug identifier, not a typed dispatch key. Different subclasses pick different conventions:

  • OpenAIProvider always returns "openai".
  • SchemaProvider returns whatever's in the schema's name field — could be "openai", "claude", "openai-responses", "gemini", or a user-defined schema id.
  • RateLimitedProvider delegates to its inner provider.

Code branching on the exact string (e.g. if (get_name() == "openai-responses")) is brittle — a custom schema named "openai-responses-v2" slips through, or a future rename silently breaks the branch. Use it for logging, telemetry, or version-pinning diagnostics. For typed behaviour, add a typed ProviderKind accessor or branch on the schema's actual fields.

Returns
Opaque provider identifier string.

Implements neograph::Provider.

Definition at line 104 of file openai_provider.h.

◆ invoke()

asio::awaitable< ChatCompletion > neograph::llm::OpenAIProvider::invoke ( const CompletionParams params,
StreamCallback  on_chunk 
)
overridevirtual

v1.0 single-dispatch override (Candidate 6 PR6).

Native invoke() that directly drives the ConnPool — no extra hop through complete_stream_async's default worker-thread bridge for streaming, no extra hop through complete_async for non- streaming. The 4 legacy overrides above stay as thin adapters over invoke() through the v0.9 deprecation window; v1.0 deletes them along with the base-class virtuals.

Reimplemented from neograph::Provider.


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