|
Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
|
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. | |
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.
| 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.
| state | Driver state from init(). |
| req | Request parameters (model, messages, temperature, tools...). |
| res | [out] Populated response (content, token counts, tool calls). |
| 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.
| state | Driver state from init(). |
| model | Model name for embeddings. |
| input | Array of input strings to embed. |
| count | Number of input strings. |
| res | [out] Populated embeddings response. |
| void(* csilk_ai_driver_t::free) (void *state) |
Clean up all driver-specific state.
| state | Driver state to free (from 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).
| api_key | API key (may be NULL for providers that don't need one). |
| base_url | Optional custom endpoint URL (NULL for provider default). |
| const char* csilk_ai_driver_t::name |
Driver identifier (e.g., "openai", "ollama"). Must match the name passed to csilk_ai_new.