Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
Loading...
Searching...
No Matches
csilk_ai_driver_t Struct Reference

Virtual function table implemented by each AI provider backend. More...

#include <ai.h>

Data Fields

const char * name
 
void *(* init )(const char *api_key, const char *base_url)
 Initialize driver-specific state (e.g., HTTP client, auth tokens).
 
int(* chat )(void *state, const csilk_ai_chat_request_t *req, csilk_ai_chat_response_t *res)
 Perform a synchronous chat completion call.
 
int(* embeddings )(void *state, const char *model, const char **input, size_t count, csilk_ai_embeddings_response_t *res)
 Perform a synchronous embeddings call.
 
void(* free )(void *state)
 Clean up all driver-specific state.
 

Detailed Description

Virtual function table implemented by each AI provider backend.

Each registered driver (OpenAI, Claude, Ollama, etc.) provides these four functions. The init function returns a driver-specific state handle that is passed to all subsequent calls.

Field Documentation

◆ chat

int(* csilk_ai_driver_t::chat) (void *state, const csilk_ai_chat_request_t *req, csilk_ai_chat_response_t *res)

Perform a synchronous chat completion call.

Parameters
stateDriver state from init().
reqRequest parameters (model, messages, temperature, tools...).
res[out] Populated response (content, token counts, tool calls).
Returns
0 on success, -1 on failure.

◆ embeddings

int(* csilk_ai_driver_t::embeddings) (void *state, const char *model, const char **input, size_t count, csilk_ai_embeddings_response_t *res)

Perform a synchronous embeddings call.

Parameters
stateDriver state from init().
modelModel name for embeddings.
inputArray of input strings to embed.
countNumber of input strings.
res[out] Populated embeddings response.
Returns
0 on success, -1 on failure.

◆ free

void(* csilk_ai_driver_t::free) (void *state)

Clean up all driver-specific state.

Parameters
stateDriver state to free (from init()).

◆ init

void *(* csilk_ai_driver_t::init) (const char *api_key, const char *base_url)

Initialize driver-specific state (e.g., HTTP client, auth tokens).

Parameters
api_keyAPI key (may be NULL for providers that don't need one).
base_urlOptional custom endpoint URL (NULL for provider default).
Returns
Opaque driver state handle, or NULL on failure.

◆ name

const char* csilk_ai_driver_t::name

Driver identifier (e.g., "openai", "ollama"). Must match the name passed to csilk_ai_new.


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