Skip to content

Commit 34c2167

Browse files
committed
Swap to client examples for all examples
1 parent 6b01d0a commit 34c2167

File tree

1 file changed

+9
-211
lines changed

1 file changed

+9
-211
lines changed

content/develop/ai/langcache/api-examples.md

Lines changed: 9 additions & 211 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ curl -s -X POST "https://$HOST/v1/caches/$CACHE_ID/entries/search" \
3535
-d "{ 'prompt': 'What is semantic caching' }"
3636
{{< /clients-example >}}
3737

38-
- The example expects several variables to be set in the shell:
38+
This example expects several variables to be set in the shell:
3939

4040
- **$HOST** - the LangCache API base URL
4141
- **$CACHE_ID** - the Cache ID of your cache
@@ -74,75 +74,19 @@ POST https://[host]/v1/caches/{cacheId}/entries/search
7474

7575
Use [`POST /v1/caches/{cacheId}/entries`]({{< relref "/develop/ai/langcache/api-reference#tag/Cache-Entries/operation/set" >}}) to store a new response in the cache.
7676

77-
{{< multitabs id="store-basic"
78-
tab1="REST API"
79-
tab2="Python"
80-
tab3="Javascript" >}}
81-
82-
```sh
77+
{{< clients-example set="langcache_sdk" step="store_basic" dft_tab_name="REST API" footer="hide" >}}
8378
POST https://[host]/v1/caches/{cacheId}/entries
8479
{
8580
"prompt": "User prompt text",
8681
"response": "LLM response text"
8782
}
88-
```
89-
90-
-tab-sep-
91-
92-
```python
93-
from langcache import LangCache
94-
import os
95-
96-
97-
with LangCache(
98-
server_url="https://[host]",
99-
cache_id="{cacheId}",
100-
service_key=os.getenv("LANGCACHE_SERVICE_KEY", ""),
101-
) as lang_cache:
102-
103-
res = lang_cache.set(
104-
prompt="User prompt text",
105-
response="LLM response text",
106-
)
107-
108-
print(res)
109-
```
110-
111-
-tab-sep-
112-
113-
```js
114-
import { LangCache } from "@redis-ai/langcache";
115-
116-
const langCache = new LangCache({
117-
serverURL: "https://<host>",
118-
cacheId: "<cacheId>",
119-
serviceKey: "<LANGCACHE_SERVICE_KEY>",
120-
});
121-
122-
async function run() {
123-
const result = await langCache.set({
124-
prompt: "User prompt text",
125-
response: "LLM response text",
126-
});
127-
128-
console.log(result);
129-
}
130-
131-
run();
132-
```
133-
134-
{{< /multitabs >}}
83+
{{< /clients-example >}}
13584

13685
Place this call in your client app after you get a response from the LLM. This will store the response in the cache for future use.
13786

13887
You can also store the responses with custom attributes by adding an `attributes` object to the request.
13988

140-
{{< multitabs id="store-attributes"
141-
tab1="REST API"
142-
tab2="Python"
143-
tab3="Javascript" >}}
144-
145-
```sh
89+
{{< clients-example set="langcache_sdk" step="store_attributes" dft_tab_name="REST API" footer="hide" >}}
14690
POST https://[host]/v1/caches/{cacheId}/entries
14791
{
14892
"prompt": "User prompt text",
@@ -151,110 +95,15 @@ POST https://[host]/v1/caches/{cacheId}/entries
15195
"customAttributeName": "customAttributeValue"
15296
}
15397
}
154-
```
155-
-tab-sep-
156-
157-
```python
158-
from langcache import LangCache
159-
import os
160-
161-
162-
with LangCache(
163-
server_url="https://[host]",
164-
cache_id="{cacheId}",
165-
service_key=os.getenv("LANGCACHE_SERVICE_KEY", ""),
166-
) as lang_cache:
167-
168-
res = lang_cache.set(
169-
prompt="User prompt text",
170-
response="LLM response text",
171-
attributes={"customAttributeName": "customAttributeValue"},
172-
)
173-
174-
print(res)
175-
```
176-
177-
-tab-sep-
178-
179-
```js
180-
import { LangCache } from "@redis-ai/langcache";
181-
182-
const langCache = new LangCache({
183-
serverURL: "https://<host>",
184-
cacheId: "<cacheId>",
185-
serviceKey: "<LANGCACHE_SERVICE_KEY>",
186-
});
187-
188-
async function run() {
189-
const result = await langCache.set({
190-
prompt: "User prompt text",
191-
response: "LLM response text",
192-
attributes: {
193-
"customAttributeName": "customAttributeValue",
194-
},
195-
});
196-
197-
console.log(result);
198-
}
199-
200-
run();
201-
```
202-
203-
{{< /multitabs >}}
98+
{{< /clients-example >}}
20499

205100
### Delete cached responses
206101

207102
Use [`DELETE /v1/caches/{cacheId}/entries/{entryId}`]({{< relref "/develop/ai/langcache/api-reference#tag/Cache-Entries/operation/delete" >}}) to delete a cached response from the cache.
208103

209-
{{< multitabs id="delete-entry"
210-
tab1="REST API"
211-
tab2="Python"
212-
tab3="Javascript" >}}
213-
214-
```sh
104+
{{< clients-example set="langcache_sdk" step="delete_entry" dft_tab_name="REST API" footer="hide" >}}
215105
DELETE https://[host]/v1/caches/{cacheId}/entries/{entryId}
216-
```
217-
-tab-sep-
218-
219-
```python
220-
from langcache import LangCache
221-
import os
222-
223-
224-
with LangCache(
225-
server_url="https://[host]",
226-
cache_id="{cacheId}",
227-
service_key=os.getenv("LANGCACHE_SERVICE_KEY", ""),
228-
) as lang_cache:
229-
230-
res = lang_cache.delete_by_id(entry_id="{entryId}")
231-
232-
print(res)
233-
```
234-
235-
-tab-sep-
236-
237-
```js
238-
import { LangCache } from "@redis-ai/langcache";
239-
240-
const langCache = new LangCache({
241-
serverURL: "https://<host>",
242-
cacheId: "<cacheId>",
243-
serviceKey: "<LANGCACHE_SERVICE_KEY>",
244-
});
245-
246-
async function run() {
247-
const result = await langCache.deleteById({
248-
entryId: "<entryId>",
249-
});
250-
251-
console.log(result);
252-
}
253-
254-
run();
255-
```
256-
257-
{{< /multitabs >}}
106+
{{< /clients-example >}}
258107

259108
You can also use [`DELETE /v1/caches/{cacheId}/entries`]({{< relref "/develop/ai/langcache/api-reference#tag/Cache-Entries/operation/deleteQuery" >}}) to delete multiple cached responses based on the `attributes` you specify. If you specify multiple `attributes`, LangCache will delete entries that contain all given attributes.
260109

@@ -264,63 +113,12 @@ If you do not specify any `attributes`, all responses in the cache will be delet
264113

265114
<br/>
266115

267-
{{< multitabs id="delete-attributes"
268-
tab1="REST API"
269-
tab2="Python"
270-
tab3="Javascript" >}}
271-
272-
```sh
116+
{{< clients-example set="langcache_sdk" step="delete_query" dft_tab_name="REST API" footer="hide" >}}
273117
DELETE https://[host]/v1/caches/{cacheId}/entries
274118
{
275119
"attributes": {
276120
"customAttributeName": "customAttributeValue"
277121
}
278122
}
279-
```
280-
281-
-tab-sep-
282-
283-
```python
284-
from langcache import LangCache
285-
import os
286-
287-
288-
with LangCache(
289-
server_url="https://[host]",
290-
cache_id="{cacheId}",
291-
service_key=os.getenv("LANGCACHE_SERVICE_KEY", ""),
292-
) as lang_cache:
293-
294-
res = lang_cache.delete_query(
295-
attributes={"customAttributeName": "customAttributeValue"},
296-
)
297-
298-
print(res)
299-
```
300-
301-
-tab-sep-
302-
303-
```js
304-
import { LangCache } from "@redis-ai/langcache";
305-
306-
const langCache = new LangCache({
307-
serverURL: "https://<host>",
308-
cacheId: "<cacheId>",
309-
serviceKey: "<LANGCACHE_SERVICE_KEY>",
310-
});
311-
312-
async function run() {
313-
const result = await langCache.deleteQuery({
314-
attributes: {
315-
"customAttributeName": "customAttributeValue",
316-
},
317-
});
318-
319-
console.log(result);
320-
}
321-
322-
run();
323-
```
324-
325-
{{< /multitabs >}}
123+
{{< /clients-example >}}
326124

0 commit comments

Comments
 (0)