Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Update README.md

Thomas Dybdahl Ahled461bb744c3d
diff --git a/README.md b/README.md
index 6ea9d3c80..bc0cc2ed6 100644
--- a/README.md
+++ b/README.md
@@ -276,9 +276,32 @@ compiled_rag = teleprompter.compile(RAG(), trainset=my_rag_trainset)
If we now use `compiled_rag`, it will invoke our LM with rich prompts with few-shot demonstrations of chain-of-thought retrieval-augmented question answering on our data.
+## 5) Pydantic Types
+Sometimes you need more than just string inputs/outputs.
+Assume, for example, you need to find
-## 5) FAQ: Is DSPy right for me?
+```python
+from pydantic import BaseModel, Field
+
+class TravelInformation(BaseModel):
+ origin: str = Field(pattern=r"^[A-Z]{3}$")
+ destination: str = Field(pattern=r"^[A-Z]{3}$")
+ date: datetime.date
+ confidence: float = Field(gt=0, lt=1)
+
+class TravelSignature(Signature):
+ """ Extract all travel information in the given email """
+ email: str = InputField()
+ flight_information: list[TravelInformation] = OutputField()
+
+predictor = dspy.TypedPredictor(TravelSignature)
+predictor(email='...')
+```
+
+Which will output a list of `TravelInformation` objects.
+
+## 6) FAQ: Is DSPy right for me?
The **DSPy** philosophy and abstraction differ significantly from other libraries and frameworks, so it's usually straightforward to decide when **DSPy** is (or isn't) the right framework for your usecase.