You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/learn/programming/signatures.md
+15-19Lines changed: 15 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,13 @@ Your signatures can also have multiple input/output fields with types:
32
32
33
33
**Tip:** For fields, any valid variable names work! Field names should be semantically meaningful, but start simple and don't prematurely optimize keywords! Leave that kind of hacking to the DSPy compiler. For example, for summarization, it's probably fine to say `"document -> summary"`, `"text -> gist"`, or `"long_context -> tldr"`.
34
34
35
+
You can also add instructions to your inline signature, which can use variables at runtime. Use the `instructions` keyword argument to add instructions to your signature.
36
+
37
+
```python
38
+
toxicity = dspy.Predict(
39
+
'comment -> toxic: bool',
40
+
instructions="Mark as 'toxic' if the comment includes insults, harassment, or sarcastic derogatory remarks.")
41
+
```
35
42
36
43
### Example A: Sentiment Classification
37
44
@@ -162,10 +169,10 @@ Prediction(
162
169
DSPy signatures support various annotation types:
163
170
164
171
1.**Basic types** like `str`, `int`, `bool`
165
-
2.**Typing module types** like `List[str]`, `Dict[str, int]`, `Optional[float]`
172
+
2.**Typing module types** like `List[str]`, `Dict[str, int]`, `Optional[float]`. `Union[str, int]`
166
173
3.**Custom types** defined in your code
167
174
4.**Dot notation** for nested types with proper configuration
168
-
5.**Special data types** like `dspy.Image`
175
+
5.**Special data types** like `dspy.Image, dspy.History`
169
176
170
177
### Working with Custom Types
171
178
@@ -175,26 +182,15 @@ class QueryResult(pydantic.BaseModel):
0 commit comments