KevinHuSh
commited on
Commit
·
2edbd4b
1
Parent(s):
4c52eb9
fix bug of inserting cites (#76)
Browse files- api/apps/user_app.py +3 -3
- api/db/init_data.py +4 -4
- api/db/services/common_service.py +20 -5
- conf/service_conf.yaml +3 -3
- rag/nlp/search.py +1 -1
api/apps/user_app.py
CHANGED
@@ -208,9 +208,9 @@ def user_register(user_id, user):
|
|
208 |
for llm in LLMService.query(fid=LLM_FACTORY):
|
209 |
tenant_llm.append({"tenant_id": user_id, "llm_factory": LLM_FACTORY, "llm_name": llm.llm_name, "model_type":llm.model_type, "api_key": API_KEY})
|
210 |
|
211 |
-
if not UserService.
|
212 |
-
TenantService.
|
213 |
-
UserTenantService.
|
214 |
TenantLLMService.insert_many(tenant_llm)
|
215 |
return UserService.query(email=user["email"])
|
216 |
|
|
|
208 |
for llm in LLMService.query(fid=LLM_FACTORY):
|
209 |
tenant_llm.append({"tenant_id": user_id, "llm_factory": LLM_FACTORY, "llm_name": llm.llm_name, "model_type":llm.model_type, "api_key": API_KEY})
|
210 |
|
211 |
+
if not UserService.insert(**user):return
|
212 |
+
TenantService.insert(**tenant)
|
213 |
+
UserTenantService.insert(**usr_tenant)
|
214 |
TenantLLMService.insert_many(tenant_llm)
|
215 |
return UserService.query(email=user["email"])
|
216 |
|
api/db/init_data.py
CHANGED
@@ -58,16 +58,16 @@ def init_superuser():
|
|
58 |
if not UserService.save(**user_info):
|
59 |
print("【ERROR】can't init admin.")
|
60 |
return
|
61 |
-
TenantService.
|
62 |
-
UserTenantService.
|
63 |
TenantLLMService.insert_many(tenant_llm)
|
64 |
-
|
65 |
|
66 |
chat_mdl = LLMBundle(tenant["id"], LLMType.CHAT, tenant["llm_id"])
|
67 |
msg = chat_mdl.chat(system="", history=[{"role": "user", "content": "Hello!"}], gen_conf={})
|
68 |
if msg.find("ERROR: ") == 0:
|
69 |
print("【ERROR】: '{}' dosen't work. {}".format(tenant["llm_id"]), msg)
|
70 |
-
embd_mdl = LLMBundle(tenant["id"], LLMType.
|
71 |
v,c = embd_mdl.encode(["Hello!"])
|
72 |
if c == 0:
|
73 |
print("【ERROR】: '{}' dosen't work...".format(tenant["embd_id"]))
|
|
|
58 |
if not UserService.save(**user_info):
|
59 |
print("【ERROR】can't init admin.")
|
60 |
return
|
61 |
+
TenantService.insert(**tenant)
|
62 |
+
UserTenantService.insert(**usr_tenant)
|
63 |
TenantLLMService.insert_many(tenant_llm)
|
64 |
+
print("【INFO】Super user initialized. user name: admin, password: admin. Changing the password after logining is strongly recomanded.")
|
65 |
|
66 |
chat_mdl = LLMBundle(tenant["id"], LLMType.CHAT, tenant["llm_id"])
|
67 |
msg = chat_mdl.chat(system="", history=[{"role": "user", "content": "Hello!"}], gen_conf={})
|
68 |
if msg.find("ERROR: ") == 0:
|
69 |
print("【ERROR】: '{}' dosen't work. {}".format(tenant["llm_id"]), msg)
|
70 |
+
embd_mdl = LLMBundle(tenant["id"], LLMType.EMBEDDING, tenant["embd_id"])
|
71 |
v,c = embd_mdl.encode(["Hello!"])
|
72 |
if c == 0:
|
73 |
print("【ERROR】: '{}' dosen't work...".format(tenant["embd_id"]))
|
api/db/services/common_service.py
CHANGED
@@ -18,7 +18,7 @@ from datetime import datetime
|
|
18 |
import peewee
|
19 |
|
20 |
from api.db.db_models import DB
|
21 |
-
from api.utils import datetime_format
|
22 |
|
23 |
|
24 |
class CommonService:
|
@@ -66,27 +66,42 @@ class CommonService:
|
|
66 |
sample_obj = cls.model(**kwargs).save(force_insert=True)
|
67 |
return sample_obj
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
@classmethod
|
70 |
@DB.connection_context()
|
71 |
def insert_many(cls, data_list, batch_size=100):
|
72 |
with DB.atomic():
|
73 |
-
for d in data_list:
|
|
|
|
|
74 |
for i in range(0, len(data_list), batch_size):
|
75 |
cls.model.insert_many(data_list[i:i + batch_size]).execute()
|
76 |
|
77 |
@classmethod
|
78 |
@DB.connection_context()
|
79 |
def update_many_by_id(cls, data_list):
|
80 |
-
cur = datetime_format(datetime.now())
|
81 |
with DB.atomic():
|
82 |
for data in data_list:
|
83 |
-
data["update_time"] =
|
|
|
84 |
cls.model.update(data).where(cls.model.id == data["id"]).execute()
|
85 |
|
86 |
@classmethod
|
87 |
@DB.connection_context()
|
88 |
def update_by_id(cls, pid, data):
|
89 |
-
data["update_time"] =
|
|
|
90 |
num = cls.model.update(data).where(cls.model.id == pid).execute()
|
91 |
return num
|
92 |
|
|
|
18 |
import peewee
|
19 |
|
20 |
from api.db.db_models import DB
|
21 |
+
from api.utils import datetime_format, current_timestamp, get_uuid
|
22 |
|
23 |
|
24 |
class CommonService:
|
|
|
66 |
sample_obj = cls.model(**kwargs).save(force_insert=True)
|
67 |
return sample_obj
|
68 |
|
69 |
+
@classmethod
|
70 |
+
@DB.connection_context()
|
71 |
+
def insert(cls, **kwargs):
|
72 |
+
if "id" not in kwargs:
|
73 |
+
kwargs["id"] = get_uuid()
|
74 |
+
kwargs["create_time"] = current_timestamp()
|
75 |
+
kwargs["create_date"] = datetime_format(datetime.now())
|
76 |
+
kwargs["update_time"] = current_timestamp()
|
77 |
+
kwargs["update_date"] = datetime_format(datetime.now())
|
78 |
+
sample_obj = cls.model(**kwargs).save(force_insert=True)
|
79 |
+
return sample_obj
|
80 |
+
|
81 |
@classmethod
|
82 |
@DB.connection_context()
|
83 |
def insert_many(cls, data_list, batch_size=100):
|
84 |
with DB.atomic():
|
85 |
+
for d in data_list:
|
86 |
+
d["create_time"] = current_timestamp()
|
87 |
+
d["create_date"] = datetime_format(datetime.now())
|
88 |
for i in range(0, len(data_list), batch_size):
|
89 |
cls.model.insert_many(data_list[i:i + batch_size]).execute()
|
90 |
|
91 |
@classmethod
|
92 |
@DB.connection_context()
|
93 |
def update_many_by_id(cls, data_list):
|
|
|
94 |
with DB.atomic():
|
95 |
for data in data_list:
|
96 |
+
data["update_time"] = current_timestamp()
|
97 |
+
data["update_date"] = datetime_format(datetime.now())
|
98 |
cls.model.update(data).where(cls.model.id == data["id"]).execute()
|
99 |
|
100 |
@classmethod
|
101 |
@DB.connection_context()
|
102 |
def update_by_id(cls, pid, data):
|
103 |
+
data["update_time"] = current_timestamp()
|
104 |
+
data["update_date"] = datetime_format(datetime.now())
|
105 |
num = cls.model.update(data).where(cls.model.id == pid).execute()
|
106 |
return num
|
107 |
|
conf/service_conf.yaml
CHANGED
@@ -17,16 +17,16 @@ database:
|
|
17 |
name: 'rag_flow'
|
18 |
user: 'root'
|
19 |
passwd: 'infini_rag_flow'
|
20 |
-
host: '
|
21 |
port: 5455
|
22 |
max_connections: 100
|
23 |
stale_timeout: 30
|
24 |
minio:
|
25 |
user: 'rag_flow'
|
26 |
passwd: 'infini_rag_flow'
|
27 |
-
host: '
|
28 |
es:
|
29 |
-
hosts: 'http://
|
30 |
user_default_llm:
|
31 |
factory: '通义千问'
|
32 |
chat_model: 'qwen-plus'
|
|
|
17 |
name: 'rag_flow'
|
18 |
user: 'root'
|
19 |
passwd: 'infini_rag_flow'
|
20 |
+
host: '127.0.0.1'
|
21 |
port: 5455
|
22 |
max_connections: 100
|
23 |
stale_timeout: 30
|
24 |
minio:
|
25 |
user: 'rag_flow'
|
26 |
passwd: 'infini_rag_flow'
|
27 |
+
host: '127.0.0.1:9000'
|
28 |
es:
|
29 |
+
hosts: 'http://127.0.0.1:9200'
|
30 |
user_default_llm:
|
31 |
factory: '通义千问'
|
32 |
chat_model: 'qwen-plus'
|
rag/nlp/search.py
CHANGED
@@ -226,7 +226,7 @@ class Dealer:
|
|
226 |
continue
|
227 |
if i not in cites:
|
228 |
continue
|
229 |
-
|
230 |
res += "##%s$$" % "$".join(cites[i])
|
231 |
|
232 |
return res
|
|
|
226 |
continue
|
227 |
if i not in cites:
|
228 |
continue
|
229 |
+
for c in cites[i]: assert int(c) < len(chunk_v)
|
230 |
res += "##%s$$" % "$".join(cites[i])
|
231 |
|
232 |
return res
|