forked from zilliztech/GPTCache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlite_milvus_mock.py
54 lines (43 loc) · 1.64 KB
/
sqlite_milvus_mock.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
from gptcache.adapter import openai
from gptcache.core import cache, Config
from gptcache.cache.factory import get_ss_data_manager
from gptcache.ranker.simple import SearchDistanceEvaluation
import numpy as np
d = 8
def mock_embeddings(data, **kwargs):
return np.random.random((d, )).astype('float32')
def run():
sqlite_file = "sqlite.db"
has_data = os.path.isfile(sqlite_file)
# milvus
data_manager = get_ss_data_manager("sqlite", "milvus", dimension=d, max_size=8, clean_size=2)
# zilliz cloud
# data_manager = get_ss_data_manager("sqlite", "milvus", dimension=d, max_size=8, clean_size=2,
# host="xxx.zillizcloud.com",
# port=19530,
# user="xxx", password="xxx", is_https=True,
# )
cache.init(embedding_func=mock_embeddings,
data_manager=data_manager,
similarity_evaluation=SearchDistanceEvaluation(),
config=Config(
similarity_threshold=0,
),
)
mock_messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "foo"}
]
if not has_data:
for i in range(10):
question = f"foo{i}"
answer = f"receiver the foo {i}"
cache.data_manager.save(question, answer, cache.embedding_func(question))
answer = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=mock_messages,
)
print(answer)
if __name__ == '__main__':
run()