Skip to content

Commit aaa2329

Browse files
authored
feat(tests): add dump all redis query (#246)
1 parent c932c37 commit aaa2329

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Diff for: tests/tool_dump_redis_query.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from redis import Redis
2+
import os
3+
from loguru import logger
4+
import json
5+
6+
def redis_host():
7+
host = os.getenv('REDIS_HOST')
8+
if host is None or len(host) < 1:
9+
raise Exception('REDIS_HOST not config')
10+
return host
11+
12+
13+
def redis_port():
14+
port = os.getenv('REDIS_PORT')
15+
if port is None:
16+
logger.debug('REDIS_PORT not set, try 6379')
17+
port = 6379
18+
return port
19+
20+
21+
def redis_passwd():
22+
passwd = os.getenv('REDIS_PASSWORD')
23+
if passwd is None or len(passwd) < 1:
24+
raise Exception('REDIS_PASSWORD not config')
25+
return passwd
26+
27+
28+
def feature_store_base_dir():
29+
return 'feature_stores'
30+
31+
32+
db = Redis(host=redis_host(), port=redis_port(), password=redis_passwd(), charset='utf-8', decode_responses=True)
33+
keys = db.keys('HuixiangDou:query:*')
34+
35+
with open('query.jsonl', 'a') as f:
36+
for key in keys:
37+
value = db.hgetall(key)
38+
f.write(json.dumps(value, indent=2, ensure_ascii=False))
39+
f.write('\n')

Diff for: web/proxy/main.py

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ def chat_with_featue_store(cache: CacheRetriever,
147147
worker = WebWorker(work_dir=workdir, config_path=configpath)
148148

149149
history = format_history(payload.history)
150+
query_log = "{} {}\n".format(fs_id, payload.content)
151+
with open('query.log', 'a') as f:
152+
f.write(query_log)
150153
error, response, references = worker.generate(query=payload.content,
151154
history=history,
152155
retriever=retriever,

0 commit comments

Comments
 (0)