DSPy
DSPy = Declarative Self-improving Python.
Components
1. language model — LLM that will answer our questions,
2. signature —a declaration of the program’s input and output (what task we want to solve),
- 1. inline
- 2. class
dspy.InputField()
List[Literal['', '', '']] = dspy.OutputField()
3. module — the prompting technique (how we want to solve the task).
- Building blocks
- different prompting strategies,
- 1. dspy.Predict
- 2. dspy.ChainOfThought
- 3. dspy.ReAct (to add tools = function calling
4. Optimiser
- 1. Automatic few-shot learning (e.g. BootstrapFewShot or BootstrapFewShotWithRandomSearch)
- 2. Automatic instructions optimisation (e.g. MIPROv2)
- 3. Automatic fine-tuning (e.g, BootstrapFinetune)
Other points
- dspy.inspect_history for logs
- Caching
# 1. updating config
dspy.configure_cache(enable_memory_cache=False, enable_disk_cache=False)
# 2. not using cache for specific module
math = dspy.Predict("question -> answer: float", cache = False)
- dspy.configure(adapter=dspy.JSONAdapter())
- DSPy is integrated with MLFlow (an observability tool)






0 comments:
Post a Comment