Skip to content

Commit d3ec629

Browse files
jackgerritssonichi
andauthored
Consolidate separate caching docs (microsoft#2054)
* Consolidate separate caching docs * add pointer for moved --------- Co-authored-by: Chi Wang <[email protected]>
1 parent 96dad2a commit d3ec629

File tree

2 files changed

+21
-68
lines changed

2 files changed

+21
-68
lines changed

website/docs/Use-Cases/enhanced_inference.md

+1-68
Original file line numberDiff line numberDiff line change
@@ -167,74 +167,7 @@ Note: if using a custom model client (see [here](/blog/2024/01/26/Custom-Models)
167167

168168
## Caching
169169

170-
API call results are cached locally and reused when the same request is issued.
171-
This is useful when repeating or continuing experiments for reproducibility and cost saving.
172-
173-
Starting version 0.2.8, a configurable context manager allows you to easily configure
174-
the cache, using either DiskCache or Redis.
175-
All `OpenAIWrapper` created inside the context manager can use the same cache
176-
through the constructor.
177-
178-
```python
179-
from autogen import Cache
180-
181-
with Cache.redis(redis_url="redis://localhost:6379/0") as cache:
182-
client = OpenAIWrapper(..., cache=cache)
183-
client.create(...)
184-
185-
with Cache.disk() as cache:
186-
client = OpenAIWrapper(..., cache=cache)
187-
client.create(...)
188-
```
189-
190-
You can also set a cache directly in the `create()` method.
191-
192-
```python
193-
client = OpenAIWrapper(...)
194-
with Cache.disk() as cache:
195-
client.create(..., cache=cache)
196-
```
197-
198-
You can vary the `cache_seed` parameter to get different LLM output while
199-
still using cache.
200-
201-
```python
202-
# Setting the cache_seed to 1 will use a different cache from the default one
203-
# and you will see different output.
204-
with Cache.disk(cache_seed=1) as cache:
205-
client.create(..., cache=cache)
206-
```
207-
208-
By default DiskCache uses `.cache` for storage. To change the cache directory,
209-
set `cache_path_root`:
210-
211-
```python
212-
with Cache.disk(cache_path_root="/tmp/autogen_cache") as cache:
213-
client.create(..., cache=cache)
214-
```
215-
216-
### Turnning off cache
217-
218-
For backward compatibility, DiskCache is always enabled by default
219-
with `cache_seed` set to 41. To fully disable it, set `cache_seed` to None.
220-
221-
```python
222-
# Turn off cache in constructor,
223-
client = OpenAIWrapper(..., cache_seed=None)
224-
# or directly in create().
225-
client.create(..., cache_seed=None)
226-
```
227-
228-
### Difference between `cache_seed` and openai's `seed` parameter
229-
230-
openai v1.1 introduces a new param `seed`.
231-
The differences between autogen's `cache_seed` and openai's `seed`:
232-
- autogen uses local disk cache to guarantee the exactly same output is produced
233-
for the same input and when cache is hit, no openai api call will be made.
234-
- openai's `seed` is a best-effort deterministic sampling with no guarantee
235-
of determinism. When using openai's `seed` with `cache_seed` set to None,
236-
even for the same input, an openai api call will be made and there is
237-
no guarantee for getting exactly the same output.
170+
Moved to [here](/docs/topics/llm-caching).
238171

239172
## Error handling
240173

website/docs/topics/llm-caching.md

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# LLM Caching
22

3+
AutoGen supports caching API requests so that they can be reused when the same request is issued. This is useful when repeating or continuing experiments for reproducibility and cost saving.
4+
35
Since version [`0.2.8`](https://github.com/microsoft/autogen/releases/tag/v0.2.8), a configurable context manager allows you to easily
46
configure LLM cache, using either [`DiskCache`](/docs/reference/cache/disk_cache#diskcache) or [`RedisCache`](/docs/reference/cache/redis_cache#rediscache). All agents inside the
57
context manager will use the same cache.
@@ -16,6 +18,16 @@ with Cache.disk() as cache:
1618
user.initiate_chat(assistant, message=coding_task, cache=cache)
1719
```
1820

21+
The cache can also be passed directly to the model client's create call.
22+
23+
```python
24+
client = OpenAIWrapper(...)
25+
with Cache.disk() as cache:
26+
client.create(..., cache=cache)
27+
```
28+
29+
## Controlling the seed
30+
1931
You can vary the `cache_seed` parameter to get different LLM output while
2032
still using cache.
2133

@@ -26,6 +38,8 @@ with Cache.disk(cache_seed=1) as cache:
2638
user.initiate_chat(assistant, message=coding_task, cache=cache)
2739
```
2840

41+
## Cache path
42+
2943
By default [`DiskCache`](/docs/reference/cache/disk_cache#diskcache) uses `.cache` for storage. To change the cache directory,
3044
set `cache_path_root`:
3145

@@ -34,6 +48,8 @@ with Cache.disk(cache_path_root="/tmp/autogen_cache") as cache:
3448
user.initiate_chat(assistant, message=coding_task, cache=cache)
3549
```
3650

51+
## Disabling cache
52+
3753
For backward compatibility, [`DiskCache`](/docs/reference/cache/disk_cache#diskcache) is on by default with `cache_seed` set to 41.
3854
To disable caching completely, set `cache_seed` to `None` in the `llm_config` of the agent.
3955

@@ -47,3 +63,7 @@ assistant = AssistantAgent(
4763
},
4864
)
4965
```
66+
67+
## Difference between `cache_seed` and OpenAI's `seed` parameter
68+
69+
OpenAI v1.1 introduced a new parameter `seed`. The difference between AutoGen's `cache_seed` and OpenAI's `seed` is AutoGen uses an explicit request cache to guarantee the exactly same output is produced for the same input and when cache is hit, no OpenAI API call will be made. OpenAI's `seed` is a best-effort deterministic sampling with no guarantee of determinism. When using OpenAI's `seed` with `cache_seed` set to `None`, even for the same input, an OpenAI API call will be made and there is no guarantee for getting exactly the same output.

0 commit comments

Comments
 (0)