⚠️ EDUCATIONAL USE ONLY - This software is licensed for educational and learning purposes only. Not for production, commercial, or application deployment. See [LICENSE](LICENSE) and NOTICE.md for complete details.
This file provides additional documentation for the Prompt Workbench Core library.
Overview
Prompt Workbench Core is a C static library designed for testing and evaluating prompts against OpenAI-compatible APIs. It provides:
- API Client: Make requests to OpenAI-compatible endpoints
- Database Layer: SQLite-based storage for test suites and user prompts
- Cross-Platform: Works on Linux, macOS, and Windows
- Static Linking: All dependencies bundled into a single static library
Architecture
Components
- API Client (
api-client.h
/api-client.c
)
- HTTP client using libcurl
- JSON parsing with cJSON
- Automatic extraction of chat completion responses
- Database (
db.h
/db.c
)
- SQLite-based persistence
- Full CRUD operations for test suites and user prompts
- Foreign key constraints with CASCADE deletes
- Library Interface (
library.h
/library.c
)
- Main library entry point
- Version information
Data Model
Test Suites
A test suite represents a collection of prompts to test with specific configuration:
- id: Unique identifier
- title: Human-readable name
- description: Optional description
- system_prompt: System message for the AI
- model: Model identifier (e.g., "gpt-4")
User Prompts
User prompts are questions or inputs to test:
- id: Unique identifier
- prompt: The actual prompt text
- test_suite_id: Foreign key to parent test suite
Usage Examples
Creating a Test Suite
int main() {
"Code Review Assistant",
"Tests for code review prompts",
"You are an expert code reviewer",
"gpt-4"
);
return 0;
}
void db_close(void)
Close the database connection and release any resources.
int db_create_user_prompt(const char *prompt, int test_suite_id)
Create a new user prompt associated with a test suite.
int db_init(const char *db_path)
Initialize the database.
int db_create_test_suite(const char *title, const char *description, const char *system_prompt, const char *model)
Create a new test suite.
Making API Calls
int main() {
"https://api.openai.com/v1/chat/completions",
getenv("OPENAI_API_KEY"),
"gpt-4",
"You are a helpful assistant",
"What is the capital of France?"
);
if (response) {
printf("Answer: %s\n", response);
}
return 0;
}
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.
Reading Test Data
int main() {
int count;
for (int i = 0; i < count; i++) {
printf("Suite: %s\n", suites[i]->title);
int prompt_count;
suites[i]->id, &prompt_count
);
for (int j = 0; j < prompt_count; j++) {
printf(" - %s\n", prompts[j]->prompt);
}
}
return 0;
}
UserPrompt ** db_get_user_prompts_by_suite(int test_suite_id, int *count)
Retrieve all user prompts for a specific test suite.
void db_free_user_prompts(UserPrompt **prompts, int count)
Free an array of UserPrompt structures.
TestSuite ** db_get_all_test_suites(int *count)
Retrieve all test suites.
void db_free_test_suites(TestSuite **suites, int count)
Free an array of TestSuite structures.
Memory Management
All functions that return allocated memory require the caller to free it:
Error Handling
Functions return specific values to indicate errors:
- Functions returning
int
: Return -1
on error, or a positive ID/0
on success
- Functions returning pointers: Return
NULL
on error
- Always check return values before using the result
Thread Safety
- Database operations are not thread-safe. Use external synchronization.
- API client operations can be called from multiple threads (libcurl is thread-safe when used correctly).
Platform Notes
Linux
- Requires pthread and math libraries (linked automatically)
- Build with GCC or Clang
macOS
- Build with Clang
- May require Xcode Command Line Tools
Windows
- Build with MSVC or MinGW
- Link against
Ws2_32.lib
and Crypt32.lib
for curl support
Building from Source
See the main README.md for build instructions.
Contributing
When contributing, ensure:
- All unit tests pass
- New functionality includes tests
- Code follows the existing style
- Documentation is updated
License
See LICENSE file for license information.