Prompt Workbench Core 1.0.0
A C library for prompt testing and evaluation with OpenAI-compatible APIs (Educational Use Only)
|
#include "api-client.h"
#include <curl/curl.h>
#include <cjson/cJSON.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Go to the source code of this file.
Data Structures | |
struct | MemoryChunk |
Functions | |
static size_t | write_callback (void *contents, size_t size, size_t nmemb, void *userp) |
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. | |
char * api_ask | ( | const char * | api_endpoint, |
const char * | api_key, | ||
const char * | model, | ||
const char * | system_prompt, | ||
const char * | user_prompt | ||
) |
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:
Definition at line 41 of file api-client.c.
References MemoryChunk::memory, MemoryChunk::size, and write_callback().
void api_ask_free | ( | char * | response | ) |
Free a response string returned by API functions.
response | The response string to free |
Definition at line 167 of file api-client.c.
|
static |
Definition at line 24 of file api-client.c.
References MemoryChunk::memory, and MemoryChunk::size.
Referenced by api_ask().