Add parameters for ask_chat and fix bugs in list_sessions (#4119)

### What problem does this PR solve?

Add parameters for ask_chat and fix bugs in list_sessions
#4105
### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
- [x] New Feature (non-breaking change which adds functionality)

Co-authored-by: liuhua <10215101452@stu.ecun.edu.cn>
This commit is contained in:
liuhua
2024-12-19 17:24:26 +08:00
committed by GitHub
parent 7474348394
commit b35e811fe7
2 changed files with 27 additions and 26 deletions

View File

@ -17,11 +17,11 @@ class Session(Base):
self.__session_type = "agent"
super().__init__(rag, res_dict)
def ask(self, question,stream=True):
def ask(self, question,stream=True,**kwargs):
if self.__session_type == "agent":
res=self._ask_agent(question,stream)
elif self.__session_type == "chat":
res=self._ask_chat(question,stream)
res=self._ask_chat(question,stream,**kwargs)
for line in res.iter_lines():
line = line.decode("utf-8")
if line.startswith("{"):
@ -45,9 +45,11 @@ class Session(Base):
yield message
def _ask_chat(self, question: str, stream: bool):
def _ask_chat(self, question: str, stream: bool,**kwargs):
json_data={"question": question, "stream": True,"session_id":self.id}
json_data.update(kwargs)
res = self.post(f"/chats/{self.chat_id}/completions",
{"question": question, "stream": True,"session_id":self.id}, stream=stream)
json_data, stream=stream)
return res
def _ask_agent(self,question:str,stream:bool):
res = self.post(f"/agents/{self.agent_id}/completions",