1#if !defined(_LLMCONNECTION_H_)
2#define _LLMCONNECTION_H_
274 const std::string&
getName()
const {
return name; }
292 const std::vector<LLMHeader>&
getHeaders()
const {
return headers; }
350 void* userData, std::string* fullReply = NULL);
368 std::string applyTemplates(
const std::string& text,
const char* input)
const;
370 static bool extractJSONPath(
const char* json, uint32 size,
const char* path,
376 LLMResult resolveStreamTransport(
const char* transportAttr);
377 void resolveSecret();
378 static bool nodeHasInlineSecret(
const XMLNode& node);
383 void* userData, std::string* fullReply);
391 std::string vendorTypeName;
392 std::string endpoint;
394 bool globalConnection;
395 std::string schemaVersion;
396 std::string apiKeyRef;
397 std::string secretsFile;
398 std::string apiKeySecret;
399 std::string requestTemplate;
400 std::string responseTemplate;
401 std::vector<LLMHeader> headers;
404 std::vector<std::string> models;
405 std::string selectedModel;
409 void accountUsageJSON(
const char* json, uint32 size);
412 void notifyOwnerEnded();
419 volatile bool cancelRequested;
420 uint64 connectTimeMS;
Cross-platform utility toolbox for CMSDK: threading, synchronization, shared memory,...
Named, node-owned connection to an LLM endpoint.
const std::string & getVendorTypeName() const
LLMResult getLastError() const
Most recent typed error recorded by this connection.
const std::string & getName() const
Connection name from <llm name="...">; code looks connections up by this name.
LLMResult interact(const char *input, std::string &reply)
One blocking request/reply exchange (mode A).
LLMResult configure(const XMLNode &llmNode)
Configure from a parsed <llm> element.
const std::string & getSelectedModel() const
Currently selected model (the <models default="..."> value until selectModel() is called).
const std::vector< LLMHeader > & getHeaders() const
void setOwner(void *owner, LLMOwnerEndCallback callback)
Set, or clear with NULLs, the owner-end callback.
LLMResult selectModel(const char *modelName)
Select a model by name from the parsed list.
LLMResult configureFromString(const char *xml)
Convenience overload: parse the <llm> element from an XML string, then configure().
const std::string & getEndpoint() const
const LLMConstraints & getConstraints() const
LLMResult connect()
Validate configuration and resolved secret, and mark the connection live.
LLMVendorType getVendorType() const
LLMResult interactStream(const char *input, LLMStreamCallback callback, void *userData, std::string *fullReply=NULL)
Streaming request (mode B): delivers decoded tokens as they arrive.
LLMStreamTransport getStreamTransport() const
Streaming transport resolved at configure() time.
std::vector< std::string > listModels() const
Model names from the parsed <models> list.
const std::string & getSchemaVersion() const
LLMResult reset()
Drop the live connection.
bool hasResolvedSecret() const
true if apikeyref resolved to a secret.
const std::string & getResponseTemplate() const
const std::string & getRequestTemplate() const
bool isConfigured() const
true once configure() has succeeded.
bool isGlobal() const
Value of the global attribute.
bool isConnected() const
true between a successful connect() and reset().
const std::string & getAPIKeyRef() const
The credential reference text, e.g.
LLMStats stats() const
Snapshot of this connection's statistics.
Central owner of all channels, listeners and connections in a process.
LLMStreamTransport
Streaming wire format used by mode B.
LLMVendorType
Vendor family recognised from <llmvendor type="...">.
const char * LLMResultText(LLMResult result)
Human-readable name for an LLMResult, for logs and error reporting.
const char * LLMStreamTransportText(LLMStreamTransport transport)
Human-readable name for an LLMStreamTransport.
const char * LLMVendorTypeText(LLMVendorType type)
Human-readable name for an LLMVendorType.
bool(* LLMStreamCallback)(const char *token, uint32 size, void *userData)
Sink for incremental streaming output (mode B).
void(* LLMOwnerEndCallback)(void *owner, LLMConnection *connection, const LLMStats &finalStats)
Owner-notification hook, fired when a connection ends.
LLMResult
Typed result codes returned by every LLMConnection operation.
@ LLM_ERR_CONFIG_NO_VENDOR
@ LLM_ERR_CONFIG_NO_ENDPOINT
@ LLM_ERR_SECRET_UNRESOLVED
@ LLM_ERR_CONFIG_BAD_TRANSPORT
@ LLM_ERR_CONFIG_UNKNOWN_VENDOR
@ LLM_ERR_CONFIG_INLINE_SECRET
@ LLM_ERR_NOT_IMPLEMENTED
@ LLM_ERR_HTTP_UNREACHABLE
@ LLM_ERR_STREAM_CANCELLED
Per-connection constraints declared on the <llm> element.
int32 maxTokensPerRequest
Connection statistics: uptime, bytes, requests, tokens and cost.
Small recursive XML DOM parser (XMLNode) used by CMSDK for all PsySpec XML parsing.