forked from zilliztech/GPTCache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql_milvus_mock.py
45 lines (35 loc) · 1.3 KB
/
mysql_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
from gptcache.adapter import openai
from gptcache.core import cache, Config
from gptcache.cache.factory import get_ss_data_manager
from gptcache.similarity_evaluation.simple import SearchDistanceEvaluation
import numpy as np
d = 8
has_data = False
def mock_embeddings(data, **kwargs):
return np.random.random((d, )).astype('float32')
def run():
# `sql_url` defaults to 'mysql+pymysql://root:[email protected]:3306/mysql'
data_manager = get_ss_data_manager("mysql", "milvus", dimension=d, max_size=8, clean_size=2)
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()