NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
rate_limited_provider.h
Go to the documentation of this file.
1
10#pragma once
11
12#include <neograph/api.h>
13#include <neograph/provider.h>
14
15#include <memory>
16#include <string>
17
18namespace neograph::llm {
19
44class NEOGRAPH_API RateLimitedProvider : public Provider {
45public:
47 struct Config {
48 int max_retries = 3;
49 int default_wait_seconds = 30;
50 int max_wait_seconds = 120;
59 int max_total_wait_seconds = 0;
60 };
61
68 static std::unique_ptr<RateLimitedProvider> create(
69 std::shared_ptr<Provider> inner, Config cfg);
70
72 static std::unique_ptr<RateLimitedProvider> create(
73 std::shared_ptr<Provider> inner) {
74 return create(std::move(inner), Config{});
75 }
76
82 asio::awaitable<ChatCompletion>
83 complete_async(const CompletionParams& params) override;
84
90 const StreamCallback& on_chunk) override;
91
98 asio::awaitable<ChatCompletion>
99 invoke(const CompletionParams& params, StreamCallback on_chunk) override;
100
101 std::string get_name() const override;
102
103private:
104 RateLimitedProvider(std::shared_ptr<Provider> inner, Config cfg);
105
106 std::shared_ptr<Provider> inner_;
107 Config cfg_;
108};
109
110} // namespace neograph::llm
NEOGRAPH_API export/import macro for shared-library builds.
Abstract base class for LLM providers.
Definition provider.h:127
Decorator that retries on RateLimitError according to its Retry-After hint.
static std::unique_ptr< RateLimitedProvider > create(std::shared_ptr< Provider > inner)
Convenience: build with default Config.
ChatCompletion complete_stream(const CompletionParams &params, const StreamCallback &on_chunk) override
Streaming retry path remains synchronous — complete_stream() has no awaitable peer on Provider,...
asio::awaitable< ChatCompletion > invoke(const CompletionParams &params, StreamCallback on_chunk) override
v1.0 single-dispatch override (Candidate 6 PR6).
static std::unique_ptr< RateLimitedProvider > create(std::shared_ptr< Provider > inner, Config cfg)
Build a decorator around an inner provider.
asio::awaitable< ChatCompletion > complete_async(const CompletionParams &params) override
Async completion that retries on RateLimitError with a non- blocking asio::steady_timer sleep.
std::string get_name() const override
Get the provider name (e.g., "openai", "claude").
Abstract LLM provider interface.
std::function< void(const std::string &chunk)> StreamCallback
Callback invoked per token during streaming completion.
Definition provider.h:52
LLM completion response including the message and token usage.
Definition types.h:60
Parameters for an LLM completion request.
Definition provider.h:57
Configuration for rate-limit handling.