@@ -167,13 +167,34 @@ gpt_4o_mini = dspy.LM('openai/gpt-4o-mini', temperature=0.9, max_tokens=3000, st
167167By default LMs in DSPy are cached. If you repeat the same call, you will get the same outputs. But you can turn off caching by setting ` cache=False ` .
168168
169169If you want to keep caching enabled but force a new request (for example, to obtain diverse outputs),
170- pass a unique ` rollout_id ` in your call. Different values ensure a different cache entry while
171- still caching future calls with the same inputs and ` rollout_id ` .
170+ pass a unique ` rollout_id ` in your call. DSPy hashes both the inputs and the ` rollout_id ` when
171+ looking up a cache entry, so different values force a new LM request while
172+ still caching future calls with the same inputs and ` rollout_id ` . The ID is also recorded in
173+ ` lm.history ` , which makes it easy to track or compare different rollouts during experiments.
172174
173175``` python linenums="1"
174176lm(" Say this is a test!" , rollout_id = 1 )
175177```
176178
179+ You can pass these LM kwargs directly to DSPy modules as well. Supplying them at
180+ initialization sets the defaults for every call:
181+
182+ ``` python linenums="1"
183+ predict = dspy.Predict(" question -> answer" , rollout_id = 1 )
184+ ```
185+
186+ To override them for a single invocation, provide a `` config `` dictionary when
187+ calling the module:
188+
189+ ``` python linenums="1"
190+ predict = dspy.Predict(" question -> answer" )
191+ predict(question = " What is 1 + 52?" , config = {" rollout_id" : 5 })
192+ ```
193+
194+ In both cases, `` rollout_id `` is forwarded to the underlying LM, affects
195+ its caching behavior, and is stored alongside each response so you can
196+ replay or analyze specific rollouts later.
197+
177198
178199## Inspecting output and usage metadata.
179200
0 commit comments