Prompt Workbench Core 1.0.0
A C library for prompt testing and evaluation with OpenAI-compatible APIs (Educational Use Only)
Loading...
Searching...
No Matches
Functions
api-client.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * api_ask (const char *api_endpoint, const char *api_key, const char *model, const char *system_prompt, const char *user_prompt)
 
void api_ask_free (char *response)
 Free a response string returned by API functions.
 

Function Documentation

◆ api_ask()

char * api_ask ( const char *  api_endpoint,
const char *  api_key,
const char *  model,
const char *  system_prompt,
const char *  user_prompt 
)

api_ask

Sends a request to a given API endpoint with a system and user prompt, using the specified model, and returns the model's response as a dynamically allocated string.

Parameters: api_endpoint - URL of the API endpoint api_key - API key for authorization model - Model identifier to use for the request system_prompt - System-level instructions to guide the model user_prompt - User's prompt to the model

Returns: A pointer to a dynamically allocated string containing the model's response. The caller is responsible for freeing the returned string using api_ask_free(). Returns NULL on failure (e.g., network error, invalid JSON, or missing parameters).

Notes:

  • Uses libcurl to perform the HTTP POST request.
  • Accumulates the response dynamically using a MemoryChunk struct.
  • Parses the JSON response with cJSON to extract choices[0].message.content.

Definition at line 41 of file api-client.c.

References MemoryChunk::memory, MemoryChunk::size, and write_callback().

+ Here is the call graph for this function:

◆ api_ask_free()

void api_ask_free ( char *  response)

Free a response string returned by API functions.

Parameters
responseThe response string to free

Definition at line 167 of file api-client.c.