Skip to content

Commit 3ba1e6f

Browse files
committed
Merge branch 'main' of https://github.com/powerli2002/CodeFuse-ModelCache into fix-mysql-delete
2 parents 7afe7b1 + 539ddb4 commit 3ba1e6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+3085
-144
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,11 @@ dmypy.json
135135
/embedding_npy
136136
/flask_server
137137
*.bin
138+
**/maya_embedding_service
139+
140+
*.ini
141+
142+
**/multicache_serving.py
138143
**/modelcache_serving.py
139-
*.ini
144+
145+
**/model/

README.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,26 @@ The project's startup scripts are divided into flask4modelcache.py and flask4mod
4040
- Python version: 3.8 and above
4141
- Package Installation
4242
```shell
43-
pip install requirements.txt
43+
pip install -r requirements.txt
4444
```
4545
### Service Startup
4646
#### Demo Service Startup
4747
1. Download the embedding model bin file from the following address: [https://huggingface.co/shibing624/text2vec-base-chinese/tree/main](https://huggingface.co/shibing624/text2vec-base-chinese/tree/main). Place the downloaded bin file in the model/text2vec-base-chinese folder.
4848
2. Start the backend service using the flask4modelcache_dome.py script.
49+
```shell
50+
cd CodeFuse-ModelCache
51+
```
52+
```shell
53+
python flask4modelcache_demo.py
54+
```
4955

5056
#### Normal Service Startup
5157
Before starting the service, the following environment configurations should be performed:
52-
1. Install the relational database MySQL and import the SQL file to create the data tables. The SQL file can be found at: reference_doc/create_table.sql
58+
1. Install the relational database MySQL and import the SQL file to create the data tables. The SQL file can be found at: ```reference_doc/create_table.sql```
5359
2. Install the vector database Milvus.
5460
3. Add the database access information to the configuration files:
55-
1. modelcache/config/milvus_config.ini
56-
2. modelcache/config/mysql_config.ini
61+
1. ```modelcache/config/milvus_config.ini ```
62+
2. ```modelcache/config/mysql_config.ini```
5763
4. Download the embedding model bin file from the following address: [https://huggingface.co/shibing624/text2vec-base-chinese/tree/main](https://huggingface.co/shibing624/text2vec-base-chinese/tree/main). Place the downloaded bin file in the model/text2vec-base-chinese folder.
5864
5. Start the backend service using the flask4modelcache.py script.
5965
## Service-Access
@@ -245,11 +251,23 @@ In ModelCache, we adopted the main idea of GPTCache, includes core modules: ada
245251
- Asynchronous log write-back capability for data analysis and statistics.
246252
- Added model field and data statistics field for feature expansion.
247253

248-
Future Features Under Development:
254+
## Todo List
255+
### Adapter
256+
- [ ] Register adapter for Milvus:Based on the "model" parameter in the scope, initialize the corresponding Collection and perform the load operation.
257+
### Embedding model&inference
258+
- [ ] Inference Optimization: Optimizing the speed of embedding inference, compatible with inference engines such as FasterTransformer, TurboTransformers, and ByteTransformer.
259+
- [ ] Compatibility with Hugging Face models and ModelScope models, offering more methods for model loading.
260+
### Scalar Storage
261+
- [ ] Support MongoDB
262+
- [ ] Support ElasticSearch
263+
### Vector Storage
264+
- [ ] Adapts Faiss storage in multimodal scenarios.
265+
### Rank能力
266+
- [ ] Add ranking model to refine the order of data after embedding recall.
267+
### Service
268+
- [ ] Supports FastAPI.
269+
- [ ] Add visual interface to offer a more direct user experience.
249270

250-
- [ ] Data isolation based on hyperparameters.
251-
- [ ] System prompt partitioning storage capability to enhance accuracy and efficiency of similarity matching.
252-
- [ ] More versatile embedding models and similarity evaluation algorithms.
253271
## Acknowledgements
254272
This project has referenced the following open-source projects. We would like to express our gratitude to the projects and their developers for their contributions and research.<br />[GPTCache](https://github.com/zilliztech/GPTCache)
255273

README_CN.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,29 @@ Codefuse-ModelCache 是一个开源的大模型语义缓存系统,通过缓存
3737
- flask4modelcache_demo.py 为快速测试服务,内嵌了sqlite和faiss,用户无需关心数据库相关事宜。
3838
- flask4modelcache.py 为正常服务,需用户具备mysql和milvus等数据库服务。
3939
### 环境依赖
40-
4140
- python版本: 3.8及以上
4241
- 依赖包安装:
4342
```shell
44-
pip install requirements.txt
43+
pip install -r requirements.txt
4544
```
4645
### 服务启动
4746
#### Demo服务启动
4847
- 离线模型bin文件下载, 参考地址:[https://huggingface.co/shibing624/text2vec-base-chinese/tree/main](https://huggingface.co/shibing624/text2vec-base-chinese/tree/main),并将下载的bin文件,放到 model/text2vec-base-chinese 文件夹中。
49-
- 执行flask4modelcache_demo.py脚本即可启动。
48+
- 执行flask4modelcache_demo.py启动服务。
49+
```shell
50+
cd CodeFuse-ModelCache
51+
```
52+
```shell
53+
python flask4modelcache_demo.py
54+
```
5055

5156
#### 正常服务启动
5257
在启动服务前,应该进行如下环境配置:
53-
1. 安装关系数据库 mysql, 导入sql创建数据表,sql文件: reference_doc/create_table.sql
58+
1. 安装关系数据库 mysql, 导入sql创建数据表,sql文件:```reference_doc/create_table.sql```
5459
2. 安装向量数据库milvus
5560
3. 在配置文件中添加数据库访问信息,配置文件为:
56-
1. modelcache/config/milvus_config.ini
57-
2. modelcache/config/mysql_config.ini
61+
1. ```modelcache/config/milvus_config.ini```
62+
2. ```modelcache/config/mysql_config.ini```
5863
4. 离线模型bin文件下载, 参考地址:[https://huggingface.co/shibing624/text2vec-base-chinese/tree/main](https://huggingface.co/shibing624/text2vec-base-chinese/tree/main),并将下载的bin文件,放到 model/text2vec-base-chinese 文件夹中
5964
5. 通过flask4modelcache.py脚本启动后端服务。
6065
## 服务访问
@@ -245,11 +250,23 @@ https://mp.weixin.qq.com/s/ExIRu2o7yvXa6nNLZcCfhQ
245250
- 异步日志回写能力,用于数据分析和统计
246251
- 增加model字段和数据统计字段,用于功能拓展。
247252

248-
未来会持续建设的功能:
253+
## Todo List
254+
### Adapter
255+
- [ ] register adapter for Milvus:根据scope中的model参数,初始化对应Collection 并且执行load操作。
256+
### Embedding model&inference
257+
- [ ] inference优化:优化embedding推理速度,适配fastertransformer, TurboTransformers, ByteTransformer等推理引擎。
258+
- [ ] 兼容huggingface模型和modelscope模型,提供更多模型加载方式。
259+
### Scalar Storage
260+
- [ ] Support MongoDB。
261+
- [ ] Support ElasticSearch。
262+
### Vector Storage
263+
- [ ] 在多模态场景中适配faiss存储。
264+
### Ranking
265+
- [ ] 增加Rank模型,对embedding召回后的数据,进行精排。
266+
### Service
267+
- [ ] 支持fastapi。
268+
- [ ] 增加前端界面,用于测试。
249269

250-
- [ ] 基于超参数的数据隔离
251-
- [ ] system promt分区存储能力,以提高相似度匹配的准确度和效率
252-
- [ ] 更通用的embedding模型和相似度评估算法
253270
## 致谢
254271
本项目参考了以下开源项目,在此对相关项目和研究开发人员表示感谢。<br />[GPTCache](https://github.com/zilliztech/GPTCache)
255272

examples/flask/llms_cache/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-

examples/flask/data_insert.py renamed to examples/flask/llms_cache/data_insert.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def run():
1313
headers = {"Content-Type": "application/json"}
1414
res = requests.post(url, headers=headers, json=json.dumps(data))
1515
res_text = res.text
16-
print('res_text: {}'.format(res_text))
1716

1817

1918
if __name__ == '__main__':

examples/flask/data_query.py renamed to examples/flask/llms_cache/data_query.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def run():
1313
headers = {"Content-Type": "application/json"}
1414
res = requests.post(url, headers=headers, json=json.dumps(data))
1515
res_text = res.text
16-
print('res_text: {}'.format(res_text))
1716

1817

1918
if __name__ == '__main__':

examples/flask/data_query_long.py renamed to examples/flask/llms_cache/data_query_long.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def run():
1818
headers = {"Content-Type": "application/json"}
1919
res = requests.post(url, headers=headers, json=json.dumps(data))
2020
res_text = res.text
21-
print('res_text: {}'.format(res_text))
2221

2322

2423
if __name__ == '__main__':

examples/flask/register.py renamed to examples/flask/llms_cache/register.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def run():
1414
headers = {"Content-Type": "application/json"}
1515
res = requests.post(url, headers=headers, json=json.dumps(data))
1616
res_text = res.text
17-
print('res_text: {}'.format(res_text))
1817

1918

2019
if __name__ == '__main__':
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
import time
3+
import json
4+
import uuid
5+
import requests
6+
7+
8+
def run():
9+
url = 'http://127.0.0.1:5000/multicache'
10+
11+
request_type = 'insert'
12+
scope = {"model": "multimodal_test"}
13+
# UUID = "820b0052-d9d8-11ee-95f1-52775e3e6fd1" + "==>" + str(time.time())
14+
UUID = str(uuid.uuid1()) + "==>" + str(time.time())
15+
img_data = "https://img0.baidu.com/it/u=1436460262,4166266890&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=282"
16+
query = {'text': ['父母带着孩子来这个地方可能会有什么顾虑'],
17+
'imageRaw': '',
18+
'imageUrl': img_data,
19+
'imageId': 'ccc'}
20+
answer = "应该注意小孩不要跑到铁轨上"
21+
chat_info = [{"query": query, "answer": answer}]
22+
data_dict = {'request_type': request_type, 'scope': scope, 'chat_info': chat_info, 'UUID': UUID}
23+
24+
headers = {"Content-Type": "application/json"}
25+
res = requests.post(url, headers=headers, json=json.dumps(data_dict))
26+
res_text = res.text
27+
print('res_text: {}'.format(res_text))
28+
29+
30+
if __name__ == '__main__':
31+
run()

0 commit comments

Comments
 (0)