@sagentic-ai/sagentic-af / Client
Client ​
OpenAI Client wrapper
Constructors ​
new Client(openAIKey, model, options) ​
new Client(
openAIKey,
model,
options?): Client
Create a new Client.
Parameters ​
• openAIKey: string
OpenAI API Key
• model: ModelType
Model to use
• options?: ClientOptionsExteded
ClientOptions
Returns ​
Client
Source ​
Properties ​
#openai ​
private #openai: OpenAI;
OpenAI client
Source ​
debug ​
private debug: boolean = false;
Enable debug logging
Source ​
inflightTickets ​
private inflightTickets: Set<number>;
Set of inflight tickets
Source ​
maxRetries ​
private maxRetries: number = DEFAULT_MAX_RETRIES;
Maximum number of attempts to retry a failed request before giving up
Source ​
model ​
private model: ModelType;
Model to use
Source ​
queue ​
private queue: Ticket[] = [];
Queue of requests to be sent
Source ​
requestPool ​
private requestPool: number = 0;
Number of requests available for use
Source ​
requestPoolMax ​
private requestPoolMax: number = 0;
Maximum number of requests available for use
Source ​
requestTimer? ​
private optional requestTimer: Timeout;
Timer for resetting request pool
Source ​
resetInterval ​
private resetInterval: number = DEFAULT_RESET_INTERVAL;
Interval for fallback clearing limit counters
Source ​
resetTimer? ​
private optional resetTimer: Timeout;
Timer for clearing limit counters
Source ​
tokenPool ​
private tokenPool: number = 0;
Number of tokens available for use
Source ​
tokenPoolMax ​
private tokenPoolMax: number = 0;
Maximum number of tokens available for use
Source ​
tokenTimer? ​
private optional tokenTimer: Timeout;
Timer for resetting token pool
Source ​
Accessors ​
RPM ​
get RPM(): number
Number of allowed requests per minute
Returns ​
number
Source ​
TPM ​
get TPM(): number
Number of allowed tokens per minute
Returns ​
number
Source ​
Methods ​
createChatCompletion() ​
createChatCompletion(request): Promise<ChatCompletion>
Create a chat completion.
Parameters ​
• request: ChatCompletionCreateParamsNonStreaming
ChatCompletionCreateParamsNonStreaming
Returns ​
Promise
<ChatCompletion
>
Source ​
enqueue() ​
private enqueue(tokens, request): Promise<ChatCompletion>
Enqueue a request.
Parameters ​
• tokens: number
Number of tokens in the request
• request: ChatCompletionCreateParamsNonStreaming
ChatCompletionCreateParamsNonStreaming
Returns ​
Promise
<ChatCompletion
>
Source ​
start() ​
start(): void
Start the client. Must be called before using the client.
Returns ​
void
Source ​
stop() ​
stop(): void
Stop the client. Must be called when done using the client.
Returns ​
void
Source ​
tick() ​
private tick(caller): void
Tick the queue.
Parameters ​
• caller: string
Returns ​
void
Source ​
updatePools() ​
private updatePools(headers): void
Update pools based on API response.
Parameters ​
• headers: Headers
Returns ​
void