-
Notifications
You must be signed in to change notification settings - Fork 532
/
Copy pathapi.py
31 lines (23 loc) · 825 Bytes
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from gptcache import cache, Config, Cache
from gptcache.adapter.api import put, get, init_similar_cache
from gptcache.processor.post import nop
from gptcache.processor.pre import get_prompt
def run_basic():
cache.init(pre_embedding_func=get_prompt)
put("hello", "foo")
print(get("hello"))
# output: foo
def run_similar_match():
inner_cache = Cache()
init_similar_cache(
cache_obj=inner_cache, post_func=nop, config=Config(similarity_threshold=0)
)
put("hello1", "foo1", cache_obj=inner_cache)
put("hello2", "foo2", cache_obj=inner_cache)
put("hello3", "foo3", cache_obj=inner_cache)
messages = get("hello", cache_obj=inner_cache, top_k=3)
print(messages)
# output: ['foo1', 'foo2', 'foo3']
if __name__ == "__main__":
run_basic()
run_similar_match()