修改POST和Get请求代码
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from datetime import datetime
|
||||
|
||||
import uuid
|
||||
from app.api.routers.request.baseConfig import BaseConfig
|
||||
from app.api.routers.request.dbOrm import DBManager
|
||||
|
||||
@@ -19,22 +19,17 @@ class conversations:
|
||||
return datas
|
||||
|
||||
def get(self,user_id:str,id:str = ''):
|
||||
records = dbManage.query(self._tableName,user_id = user_id,id = id)
|
||||
records = dbManage.query(self._tableName,user_id = user_id,id=id)
|
||||
if len(records) >0:
|
||||
return records[0]
|
||||
return None
|
||||
|
||||
def add(self,user_id:str,name:str,id:str = ''):
|
||||
import uuid
|
||||
if id == '':
|
||||
id= str(uuid.uuid4())
|
||||
template = BaseConfig.ConversationCfg
|
||||
|
||||
template['id'] = id
|
||||
template['user_id'] = user_id
|
||||
template['name'] = name
|
||||
template['created_at'] = 1724399038
|
||||
|
||||
dbManage.addRecord(self._tableName,template)
|
||||
|
||||
def delete(self,id:str):
|
||||
@@ -70,7 +65,7 @@ class userMng:
|
||||
@classmethod
|
||||
def findNoExistCreate(cls,user_id:str):
|
||||
userInfo = cls.userObj.get(user_id)
|
||||
if userInfo is None:
|
||||
if len(userInfo) == 0:
|
||||
cls.userObj.add(user_id)
|
||||
|
||||
def remove(cls,user_id:str):
|
||||
@@ -116,14 +111,23 @@ class message:
|
||||
self._tableName = 'messages'
|
||||
dbManage.createTable(self._tableName)
|
||||
|
||||
def gets(self,user_id:str):
|
||||
return dbManage.query(self._tableName,user_id = user_id)
|
||||
def gets(self,user_id:str,conversation_id:str):
|
||||
records = dbManage.query(self._tableName,user_id = user_id,conversation_id = conversation_id)
|
||||
datas = []
|
||||
for record in records:
|
||||
datas.append(record)
|
||||
return datas
|
||||
|
||||
def add(self,user_id:str):
|
||||
dbManage.addRecord(self._tableName,{})
|
||||
def add(self,user_id:str,conversation_id:str,query:str,answer:str):
|
||||
template = BaseConfig.MessageCfg
|
||||
template['id'] = str(uuid.uuid4())
|
||||
template['user_id'] = user_id
|
||||
template['conversation_id'] = conversation_id
|
||||
template['query'] = query
|
||||
template['answer'] = answer
|
||||
dbManage.addRecord(self._tableName,template)
|
||||
|
||||
def delete(self,user_id:str):
|
||||
dbManage.delete(self._tableName,user_id = user_id)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -49,4 +49,14 @@ class BaseConfig:
|
||||
"status": "normal",
|
||||
"introduction": ParamterCfg['opening_statement'],
|
||||
"created_at":''
|
||||
}
|
||||
|
||||
|
||||
MessageCfg = {
|
||||
"id": "",
|
||||
'user_id':'',
|
||||
"conversation_id": "",
|
||||
"inputs": {},
|
||||
"query": "",
|
||||
"answer": ""
|
||||
}
|
||||
@@ -41,7 +41,7 @@ class MessagesOrm(Base):
|
||||
conversation_id = Column(String)
|
||||
inputs = Column(JSON)
|
||||
query = Column(String)
|
||||
answer = Column(JSON)
|
||||
answer = Column(String)
|
||||
|
||||
#数据结构
|
||||
class ConversationModel(BaseModel):
|
||||
@@ -90,7 +90,7 @@ class MessagesModel(BaseModel):
|
||||
conversation_id :str
|
||||
inputs : Dict[str, Any]
|
||||
query : str
|
||||
answer : Dict[str, Any]
|
||||
answer : str
|
||||
|
||||
class Config:
|
||||
#orm_mode = True
|
||||
|
||||
@@ -11,4 +11,3 @@ class ChatRequestData(BaseModel):
|
||||
response_mode: str
|
||||
files: Any
|
||||
conversation_id: str = None
|
||||
|
||||
Reference in New Issue
Block a user