mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-12 22:55:45 +08:00
Refactor: reformat all code for lefthook using ruff and gofmt (#16585)
This commit is contained in:
@@ -36,7 +36,6 @@ class Session(Base):
|
||||
self.__session_type = "agent"
|
||||
super().__init__(rag, res_dict)
|
||||
|
||||
|
||||
def ask(
|
||||
self,
|
||||
question="",
|
||||
@@ -89,8 +88,7 @@ class Session(Base):
|
||||
|
||||
if inputs is not None or release is not None or return_trace is not None:
|
||||
logger.debug(
|
||||
"Session.ask explicit-params session_type=%s session_id=%s "
|
||||
"input_keys=%s release=%s return_trace=%s",
|
||||
"Session.ask explicit-params session_type=%s session_id=%s input_keys=%s release=%s return_trace=%s",
|
||||
self.__session_type,
|
||||
getattr(self, "id", None),
|
||||
list(inputs.keys()) if isinstance(inputs, dict) else None,
|
||||
@@ -111,7 +109,7 @@ class Session(Base):
|
||||
continue # Skip empty lines
|
||||
line = line.strip()
|
||||
if line.startswith("data:"):
|
||||
content = line[len("data:"):].strip()
|
||||
content = line[len("data:") :].strip()
|
||||
if content == "[DONE]":
|
||||
break # End of stream
|
||||
else:
|
||||
@@ -122,14 +120,11 @@ class Session(Base):
|
||||
except json.JSONDecodeError:
|
||||
continue # Skip lines that are not valid JSON
|
||||
|
||||
event = json_data.get("event",None)
|
||||
event = json_data.get("event", None)
|
||||
if event and event != "message":
|
||||
continue
|
||||
|
||||
if (
|
||||
(self.__session_type == "agent" and event == "message_end")
|
||||
or (self.__session_type == "chat" and json_data.get("data") is True)
|
||||
):
|
||||
if (self.__session_type == "agent" and event == "message_end") or (self.__session_type == "chat" and json_data.get("data") is True):
|
||||
return
|
||||
if self.__session_type == "agent":
|
||||
yield self._structure_answer(json_data)
|
||||
@@ -141,7 +136,6 @@ class Session(Base):
|
||||
except ValueError:
|
||||
raise Exception(f"Invalid response {res}")
|
||||
yield self._structure_answer(json_data["data"])
|
||||
|
||||
|
||||
def _structure_answer(self, json_data):
|
||||
answer = ""
|
||||
@@ -150,10 +144,7 @@ class Session(Base):
|
||||
elif self.__session_type == "chat":
|
||||
answer = json_data["answer"]
|
||||
reference = json_data.get("reference", {})
|
||||
temp_dict = {
|
||||
"content": answer,
|
||||
"role": "assistant"
|
||||
}
|
||||
temp_dict = {"content": answer, "role": "assistant"}
|
||||
if reference and "chunks" in reference:
|
||||
chunks = reference["chunks"]
|
||||
temp_dict["reference"] = chunks
|
||||
@@ -163,8 +154,7 @@ class Session(Base):
|
||||
def _ask_chat(self, question: str, stream: bool, **kwargs):
|
||||
json_data = {"question": question, "stream": stream, "session_id": self.id}
|
||||
json_data.update(kwargs)
|
||||
res = self.post(f"/chats/{self.chat_id}/completions",
|
||||
json_data, stream=stream)
|
||||
res = self.post(f"/chats/{self.chat_id}/completions", json_data, stream=stream)
|
||||
return res
|
||||
|
||||
def _ask_agent(self, question: str, stream: bool, **kwargs):
|
||||
@@ -180,8 +170,7 @@ class Session(Base):
|
||||
return res
|
||||
|
||||
def update(self, update_message):
|
||||
res = self.patch(f"/chats/{self.chat_id}/sessions/{self.id}",
|
||||
update_message)
|
||||
res = self.patch(f"/chats/{self.chat_id}/sessions/{self.id}", update_message)
|
||||
res = res.json()
|
||||
if res.get("code") != 0:
|
||||
raise Exception(res.get("message"))
|
||||
|
||||
Reference in New Issue
Block a user