Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FirmAI-Research/vibe-dspy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vibe-dspy

Transform your ideas and prompts into DSPy signatures using DSPy Signature!

This is an experimental approach for DSPy framework.

Features

  • Natural Language to DSPy Signature: Convert ideas like "Translate English to German" or "Count people on the image" into a full dspy.Signature.
  • Dynamic Class Factory: Generate and use dspy.Signature classes at runtime.
  • Interactive Refinement: Iteratively improve generated signatures by providing feedback in a loop.
  • CLI Interface: command-line interface built with Typer and Rich.

Installation

  1. Clone the repository:
    git clone https://github.com/Archelunch/vibe-dspy
    cd vibe-dspy
  2. Install the required dependencies:
    pip install -r requirements.txt

Configuration

Before using the generator, you need to configure your API key for the language model.

Set it as an environment variable:

export GEMINI_API_KEY="your-api-key-here"

Usage Examples

The following examples are taken from the Examples.ipynb notebook.

1. Simple Code Generation

You can generate the Python source code for a signature directly from a prompt.

import dspy
from src.signature_generator import SignatureGenerator

# Configure your LM (e.g., Gemini)
# dspy.settings.configure(lm=...) 

generator = SignatureGenerator()
result = generator(prompt="Generate jokes by prompt")

# Print the generated Python code
print(generator.generate_code(result))

Output:

import dspy

class JokeGenerator(dspy.Signature):
    """Generates a joke based on a given prompt or topic."""

    topic: str = dspy.InputField(desc="The topic or theme for the joke.")
    joke: str = dspy.OutputField(desc="The generated joke.")

2. Dynamic Class Factory

We can also create a dspy.Signature class dynamically at runtime.

# Use the result from the previous step
JokeGeneratorSignature = SignatureGenerator.create_signature_class(result)

# You now have a real, usable class
print(JokeGeneratorSignature)
print(JokeGeneratorSignature.__doc__)

Output:

JokeGenerator(topic -> joke
    instructions='Generates a joke based on a given prompt or topic.'
    topic = Field(annotation=str required=True ... )
    joke = Field(annotation=str required=True ... )
)
Generates a joke based on a given prompt or topic.

3. Using the Dynamic Class

This generated class can be used immediately.

joker = dspy.Predict(JokeGeneratorSignature)

# Get a prediction
response = joker(topic="clowns")
print(response.joke)

4. Interactive Refinement

You can also refine a generated signature by providing feedback in a loop until you're satisfied with the result.

def user_feedback_validator(args, pred):
    """A simple validation function that asks for user feedback."""
    print(SignatureGenerator.generate_code(pred))
    is_ok = input("Is the signature correct? (Y/n): ")
    if is_ok.lower() == "n":
        feedback = input("What should be changed? ")
        return dspy.Prediction(score=0.0, feedback=feedback)
    return 1.0

# Set up the Refine module to try up to 3 times
refiner = dspy.Refine(
    module=generator, 
    N=3, 
    reward_fn=user_feedback_validator, 
    threshold=1.0
)

# Run the refinement process
final_result = refiner(prompt="Count birds in the image")

print("\\n--- Final Approved Signature ---")
print(SignatureGenerator.generate_code(final_result))

CLI Usage

This tool also includes a full command-line interface.

Generate a single signature:

python -m src.main generate "Count birds in an image" --output-file bird_counter.py

Interactive mode:

python -m src.main interactive

Refine a signature with feedback:

python -m src.main refine "Analyze customer reviews" --attempts 5

Project Structure

.
├── src/
│   ├── signature_generator.py  # Core logic and dynamic class factory
│   ├── cli.py                  # CLI interface
│   ├── utils.py                # Utility functions
│   └── main.py                 # Entry point for the CLI
├── Examples.ipynb              # Jupyter notebook with usage examples
├── requirements.txt
└── README.md

Backlog & Future Plans

I'm not sure about future of this project. It was small and fun idea to do. But let me know if you are interested in this project and want to see more.

  • Tests?
  • Web-interface?
  • MCP-server ???
  • VS Code extension???
  • Complex data schema with set of pydantic classes
  • Optimisation experiments with MIPRO or GEPA

License

This project is licensed under the BSD 3-Clause License. See the LICENSE file for details.

Contact

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 76.9%
  • Jupyter Notebook 23.1%