This repository contains an example implementation of Kwansi, a wrapper for DSPy that makes its optimizers easier to use. You can find Kwansi here: https://github.com/baloise/kwansi, which also includes a documentation about its core functions.
This example demonstrates how to use Kwansi to optimize a tweet creation task. It covers:
- Setting up the environment
- Preparing training data
- Creating a task
- Defining metrics
- Running the optimizer
- Testing the optimized model
-
Clone this repository:
git clone https://github.com/lordamp/kwansi-example.git cd kwansi-example
-
Install the required packages:
pip install -r requirements.txt
-
Set up your OpenAI API key in a
.env
file:OPENAI_API_KEY=your-api-key-here
-
Run the main script:
python example_implementation.py
-
For a step-by-step walkthrough, see the
example_implementation.ipynb
Jupyter notebook.
example_implementation.py
: The example implementation of Kwansi. Run this to execute the whole example.example_implementation.ipynb
: The step-by-step walkthrough of the example implementation as a Jupyter notebook.components/
: Custom task and evaluator definitionstask.py
: The task instructions we're trying to optimizeassessors.py
: The assessor evaluators used to evaluate the task (LLM-based evaluators)metrics.py
: The metrics used to evaluate the task (binary metrics)custom_combiner.py
: A custom combiner function for the evaluators
data/
: Example data for the taskexample_data.json
: The prepared data used for training the optimizer
outputs/
: Directory for storing the compiled instructions (empty at the start)
For more detailed information about Kwansi, please visit the Kwansi documentation. If you want to learn more about the underlying DSPy framework, please visit the DSPy documentation.