mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-10 21:55:42 +08:00
Refactor: reformat all code for lefthook using ruff and gofmt (#16585)
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#
|
||||
|
||||
from beartype.claw import beartype_this_package
|
||||
|
||||
beartype_this_package()
|
||||
|
||||
import importlib.metadata
|
||||
@@ -30,13 +31,4 @@ from .modules.memory import Memory
|
||||
|
||||
__version__ = importlib.metadata.version("ragflow_sdk")
|
||||
|
||||
__all__ = [
|
||||
"RAGFlow",
|
||||
"DataSet",
|
||||
"Chat",
|
||||
"Session",
|
||||
"Document",
|
||||
"Chunk",
|
||||
"Agent",
|
||||
"Memory"
|
||||
]
|
||||
__all__ = ["RAGFlow", "DataSet", "Chat", "Session", "Document", "Chunk", "Agent", "Memory"]
|
||||
|
||||
@@ -12,4 +12,4 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#
|
||||
|
||||
@@ -20,7 +20,7 @@ from .session import Session
|
||||
|
||||
class Agent(Base):
|
||||
def __init__(self, rag, res_dict):
|
||||
self.id = None
|
||||
self.id = None
|
||||
self.avatar = None
|
||||
self.canvas_type = None
|
||||
self.description = None
|
||||
@@ -30,42 +30,17 @@ class Agent(Base):
|
||||
class Dsl(Base):
|
||||
def __init__(self, rag, res_dict):
|
||||
self.answer = []
|
||||
self.components = {
|
||||
"begin": {
|
||||
"downstream": ["Answer:China"],
|
||||
"obj": {
|
||||
"component_name": "Begin",
|
||||
"params": {}
|
||||
},
|
||||
"upstream": []
|
||||
}
|
||||
}
|
||||
self.components = {"begin": {"downstream": ["Answer:China"], "obj": {"component_name": "Begin", "params": {}}, "upstream": []}}
|
||||
self.graph = {
|
||||
"edges": [],
|
||||
"nodes": [
|
||||
{
|
||||
"data": {
|
||||
"label": "Begin",
|
||||
"name": "begin"
|
||||
},
|
||||
"id": "begin",
|
||||
"position": {
|
||||
"x": 50,
|
||||
"y": 200
|
||||
},
|
||||
"sourcePosition": "left",
|
||||
"targetPosition": "right",
|
||||
"type": "beginNode"
|
||||
}
|
||||
]
|
||||
"nodes": [{"data": {"label": "Begin", "name": "begin"}, "id": "begin", "position": {"x": 50, "y": 200}, "sourcePosition": "left", "targetPosition": "right", "type": "beginNode"}],
|
||||
}
|
||||
self.history = []
|
||||
self.messages = []
|
||||
self.path = []
|
||||
self.history = []
|
||||
self.messages = []
|
||||
self.path = []
|
||||
self.reference = []
|
||||
super().__init__(rag, res_dict)
|
||||
|
||||
|
||||
def create_session(self, **kwargs) -> Session:
|
||||
res = self.post(f"/agents/{self.id}/sessions", json=kwargs)
|
||||
res = res.json()
|
||||
@@ -73,11 +48,8 @@ class Agent(Base):
|
||||
return Session(self.rag, res.get("data"))
|
||||
raise Exception(res.get("message"))
|
||||
|
||||
|
||||
def list_sessions(self, page: int = 1, page_size: int = 30, orderby: str = "create_time", desc: bool = True,
|
||||
id: str = None) -> list[Session]:
|
||||
res = self.get(f"/agents/{self.id}/sessions",
|
||||
{"page": page, "page_size": page_size, "orderby": orderby, "desc": desc, "id": id})
|
||||
def list_sessions(self, page: int = 1, page_size: int = 30, orderby: str = "create_time", desc: bool = True, id: str = None) -> list[Session]:
|
||||
res = self.get(f"/agents/{self.id}/sessions", {"page": page, "page_size": page_size, "orderby": orderby, "desc": desc, "id": id})
|
||||
res = res.json()
|
||||
if res.get("code") == 0:
|
||||
result_list = []
|
||||
@@ -86,7 +58,7 @@ class Agent(Base):
|
||||
result_list.append(temp_agent)
|
||||
return result_list
|
||||
raise Exception(res.get("message"))
|
||||
|
||||
|
||||
def delete_sessions(self, ids: list[str] | None = None, delete_all: bool = False):
|
||||
payload = {"ids": ids}
|
||||
if delete_all:
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
from .base import Base
|
||||
|
||||
|
||||
class ChunkUpdateError(Exception):
|
||||
def __init__(self, code=None, message=None, details=None):
|
||||
self.code = code
|
||||
@@ -23,6 +24,7 @@ class ChunkUpdateError(Exception):
|
||||
self.details = details
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
class Chunk(Base):
|
||||
def __init__(self, rag, res_dict):
|
||||
self.id = ""
|
||||
@@ -48,17 +50,12 @@ class Chunk(Base):
|
||||
res_dict.pop(k)
|
||||
super().__init__(rag, res_dict)
|
||||
|
||||
#for backward compatibility
|
||||
# for backward compatibility
|
||||
if not self.document_name:
|
||||
self.document_name = self.document_keyword
|
||||
|
||||
|
||||
def update(self, update_message: dict):
|
||||
res = self.patch(f"/datasets/{self.dataset_id}/documents/{self.document_id}/chunks/{self.id}", update_message)
|
||||
res = res.json()
|
||||
if res.get("code") != 0:
|
||||
raise ChunkUpdateError(
|
||||
code=res.get("code"),
|
||||
message=res.get("message"),
|
||||
details=res.get("details")
|
||||
)
|
||||
raise ChunkUpdateError(code=res.get("code"), message=res.get("message"), details=res.get("details"))
|
||||
|
||||
@@ -113,18 +113,21 @@ class DataSet(Base):
|
||||
|
||||
def _get_documents_status(self, document_ids):
|
||||
import time
|
||||
|
||||
terminal_states = {"DONE", "FAIL", "CANCEL"}
|
||||
interval_sec = 1
|
||||
pending = set(document_ids)
|
||||
finished = []
|
||||
while pending:
|
||||
for doc_id in list(pending):
|
||||
|
||||
def fetch_doc(doc_id: str) -> Document | None:
|
||||
try:
|
||||
docs = self.list_documents(id=doc_id)
|
||||
return docs[0] if docs else None
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
doc = fetch_doc(doc_id)
|
||||
if doc is None:
|
||||
continue
|
||||
@@ -137,13 +140,12 @@ class DataSet(Base):
|
||||
if pending:
|
||||
time.sleep(interval_sec)
|
||||
return finished
|
||||
|
||||
|
||||
def async_parse_documents(self, document_ids):
|
||||
res = self.post(f"/datasets/{self.id}/chunks", {"document_ids": document_ids})
|
||||
res = res.json()
|
||||
if res.get("code") != 0:
|
||||
raise Exception(res.get("message"))
|
||||
|
||||
|
||||
def parse_documents(self, document_ids):
|
||||
try:
|
||||
@@ -151,9 +153,8 @@ class DataSet(Base):
|
||||
self._get_documents_status(document_ids)
|
||||
except KeyboardInterrupt:
|
||||
self.async_cancel_parse_documents(document_ids)
|
||||
|
||||
return self._get_documents_status(document_ids)
|
||||
|
||||
return self._get_documents_status(document_ids)
|
||||
|
||||
def async_cancel_parse_documents(self, document_ids):
|
||||
res = self.rm(f"/datasets/{self.id}/chunks", {"document_ids": document_ids})
|
||||
|
||||
@@ -18,7 +18,6 @@ from .base import Base
|
||||
|
||||
|
||||
class Memory(Base):
|
||||
|
||||
def __init__(self, rag, res_dict):
|
||||
self.id = ""
|
||||
self.name = ""
|
||||
@@ -33,7 +32,7 @@ class Memory(Base):
|
||||
self.description = ""
|
||||
self.memory_size = 5 * 1024 * 1024
|
||||
self.forgetting_policy = "FIFO"
|
||||
self.temperature = 0.5,
|
||||
self.temperature = (0.5,)
|
||||
self.system_prompt = ""
|
||||
self.user_prompt = ""
|
||||
for k in list(res_dict.keys()):
|
||||
@@ -57,13 +56,8 @@ class Memory(Base):
|
||||
self._update_from_dict(self.rag, res.get("data", {}))
|
||||
return self
|
||||
|
||||
def list_memory_messages(self, agent_id: str | list[str]=None, keywords: str=None, page: int=1, page_size: int=50):
|
||||
params = {
|
||||
"agent_id": agent_id,
|
||||
"keywords": keywords,
|
||||
"page": page,
|
||||
"page_size": page_size
|
||||
}
|
||||
def list_memory_messages(self, agent_id: str | list[str] = None, keywords: str = None, page: int = 1, page_size: int = 50):
|
||||
params = {"agent_id": agent_id, "keywords": keywords, "page": page, "page_size": page_size}
|
||||
res = self.get(f"/memories/{self.id}", params)
|
||||
res = res.json()
|
||||
if res.get("code") != 0:
|
||||
@@ -78,9 +72,7 @@ class Memory(Base):
|
||||
return True
|
||||
|
||||
def update_message_status(self, message_id: int, status: bool):
|
||||
update_message = {
|
||||
"status": status
|
||||
}
|
||||
update_message = {"status": status}
|
||||
res = self.put(f"/messages/{self.id}:{message_id}", update_message)
|
||||
res = res.json()
|
||||
if res.get("code") != 0:
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -196,7 +196,7 @@ class RAGFlow:
|
||||
top_k=1024,
|
||||
rerank_id: str | None = None,
|
||||
keyword: bool = False,
|
||||
cross_languages: list[str]|None = None,
|
||||
cross_languages: list[str] | None = None,
|
||||
metadata_condition: dict | None = None,
|
||||
use_kg: bool = False,
|
||||
toc_enhance: bool = False,
|
||||
@@ -217,7 +217,7 @@ class RAGFlow:
|
||||
"cross_languages": cross_languages,
|
||||
"metadata_condition": metadata_condition,
|
||||
"use_kg": use_kg,
|
||||
"toc_enhance": toc_enhance
|
||||
"toc_enhance": toc_enhance,
|
||||
}
|
||||
# Send a POST request to the backend service (using requests library as an example, actual implementation may vary)
|
||||
res = self.post("/retrieval", json=data_json)
|
||||
@@ -331,7 +331,7 @@ class RAGFlow:
|
||||
"memory_type": memory_type,
|
||||
"storage_type": storage_type,
|
||||
"keywords": keywords,
|
||||
}
|
||||
},
|
||||
)
|
||||
res = res.json()
|
||||
if res.get("code") != 0:
|
||||
@@ -339,12 +339,7 @@ class RAGFlow:
|
||||
result_list = []
|
||||
for data in res["data"]["memory_list"]:
|
||||
result_list.append(Memory(self, data))
|
||||
return {
|
||||
"code": res.get("code", 0),
|
||||
"message": res.get("message"),
|
||||
"memory_list": result_list,
|
||||
"total_count": res["data"]["total_count"]
|
||||
}
|
||||
return {"code": res.get("code", 0), "message": res.get("message"), "memory_list": result_list, "total_count": res["data"]["total_count"]}
|
||||
|
||||
def delete_memory(self, memory_id: str):
|
||||
res = self.delete(f"/memories/{memory_id}", {})
|
||||
@@ -354,21 +349,24 @@ class RAGFlow:
|
||||
|
||||
def add_message(self, memory_id: list[str], agent_id: str, session_id: str, user_input: str, agent_response: str, user_id: str = "") -> str:
|
||||
"""Append messages to memories; ``user_id`` is forwarded only for API-key auth (external subject)."""
|
||||
payload = {
|
||||
"memory_id": memory_id,
|
||||
"agent_id": agent_id,
|
||||
"session_id": session_id,
|
||||
"user_input": user_input,
|
||||
"agent_response": agent_response,
|
||||
"user_id": user_id
|
||||
}
|
||||
payload = {"memory_id": memory_id, "agent_id": agent_id, "session_id": session_id, "user_input": user_input, "agent_response": agent_response, "user_id": user_id}
|
||||
res = self.post("/messages", payload)
|
||||
res = res.json()
|
||||
if res.get("code") != 0:
|
||||
raise Exception(res["message"])
|
||||
return res["message"]
|
||||
|
||||
def search_message(self, query: str, memory_id: list[str], agent_id: str=None, session_id: str=None, user_id: str=None, similarity_threshold: float=0.2, keywords_similarity_weight: float=0.7, top_n: int=10) -> list[dict]:
|
||||
def search_message(
|
||||
self,
|
||||
query: str,
|
||||
memory_id: list[str],
|
||||
agent_id: str = None,
|
||||
session_id: str = None,
|
||||
user_id: str = None,
|
||||
similarity_threshold: float = 0.2,
|
||||
keywords_similarity_weight: float = 0.7,
|
||||
top_n: int = 10,
|
||||
) -> list[dict]:
|
||||
params = {
|
||||
"query": query,
|
||||
"memory_id": memory_id,
|
||||
@@ -377,7 +375,7 @@ class RAGFlow:
|
||||
"user_id": user_id,
|
||||
"similarity_threshold": similarity_threshold,
|
||||
"keywords_similarity_weight": keywords_similarity_weight,
|
||||
"top_n": top_n
|
||||
"top_n": top_n,
|
||||
}
|
||||
res = self.get("/messages/search", params)
|
||||
res = res.json()
|
||||
@@ -385,13 +383,8 @@ class RAGFlow:
|
||||
raise Exception(res["message"])
|
||||
return res["data"]
|
||||
|
||||
def get_recent_messages(self, memory_id: list[str], agent_id: str=None, session_id: str=None, limit: int=10) -> list[dict]:
|
||||
params = {
|
||||
"memory_id": memory_id,
|
||||
"agent_id": agent_id,
|
||||
"session_id": session_id,
|
||||
"limit": limit
|
||||
}
|
||||
def get_recent_messages(self, memory_id: list[str], agent_id: str = None, session_id: str = None, limit: int = 10) -> list[dict]:
|
||||
params = {"memory_id": memory_id, "agent_id": agent_id, "session_id": session_id, "limit": limit}
|
||||
res = self.get("/messages", params)
|
||||
res = res.json()
|
||||
if res.get("code") != 0:
|
||||
|
||||
@@ -2,7 +2,7 @@ from .ragflow_sdk import RAGFlow
|
||||
|
||||
rag_object = RAGFlow(api_key="ragflow-FDfRECsXDRagsKPxb_EfZdDPcmngavSgYEzbU_Blgq4", base_url="http://localhost:9222")
|
||||
assistant = rag_object.get_agent("b0bc46e43dfc11f1b4ff84ba59bc54d9")
|
||||
session = assistant.create_session()
|
||||
session = assistant.create_session()
|
||||
|
||||
print("\n==================== Miss R =====================\n")
|
||||
print("Hello. What can I do for you?")
|
||||
@@ -10,8 +10,8 @@ print("Hello. What can I do for you?")
|
||||
while True:
|
||||
question = input("\n==================== User =====================\n> ")
|
||||
print("\n==================== Miss R =====================\n")
|
||||
|
||||
|
||||
cont = ""
|
||||
for ans in session.ask(question, stream=True):
|
||||
print(ans.content[len(cont):], end='', flush=True)
|
||||
print(ans.content[len(cont) :], end="", flush=True)
|
||||
cont = ans.content
|
||||
|
||||
@@ -113,12 +113,7 @@ def add_model_instance(auth):
|
||||
pytest.exit(f"Critical error in add model provider: {add_provider_res.get('message')}")
|
||||
|
||||
add_instance_api = HOST_ADDRESS + "/api/v1/providers/ZHIPU-AI/instances"
|
||||
add_instance_response = requests.post(url=add_instance_api, headers=authorization, json={
|
||||
"instance_name": "CI",
|
||||
"api_key": ZHIPU_AI_API_KEY,
|
||||
"region": "default",
|
||||
"base_url": ""
|
||||
})
|
||||
add_instance_response = requests.post(url=add_instance_api, headers=authorization, json={"instance_name": "CI", "api_key": ZHIPU_AI_API_KEY, "region": "default", "base_url": ""})
|
||||
add_instance_res = add_instance_response.json()
|
||||
if add_instance_res.get("code") != 0:
|
||||
pytest.exit(f"Critical error in add model instance: {add_instance_res.get('message')}")
|
||||
@@ -139,41 +134,19 @@ def set_tenant_info(get_auth):
|
||||
url = HOST_ADDRESS + "/api/v1/models/default"
|
||||
authorization = {"Authorization": get_auth}
|
||||
# set chat model
|
||||
set_default_llm_response = requests.patch(
|
||||
url=url,
|
||||
headers=authorization,
|
||||
json={
|
||||
"model_provider": "ZHIPU-AI",
|
||||
"model_instance": "CI",
|
||||
"model_type": "chat",
|
||||
"model_name": "glm-4-flash"
|
||||
})
|
||||
set_default_llm_response = requests.patch(url=url, headers=authorization, json={"model_provider": "ZHIPU-AI", "model_instance": "CI", "model_type": "chat", "model_name": "glm-4-flash"})
|
||||
llm_res = set_default_llm_response.json()
|
||||
if llm_res.get("code") != 0:
|
||||
raise Exception(llm_res.get("message"))
|
||||
# set embedding model
|
||||
set_default_embedding_response = requests.patch(
|
||||
url=url,
|
||||
headers=authorization,
|
||||
json={
|
||||
"model_provider": "Builtin",
|
||||
"model_instance": "Local",
|
||||
"model_type": "embedding",
|
||||
"model_name": "BAAI/bge-small-en-v1.5"
|
||||
})
|
||||
url=url, headers=authorization, json={"model_provider": "Builtin", "model_instance": "Local", "model_type": "embedding", "model_name": "BAAI/bge-small-en-v1.5"}
|
||||
)
|
||||
embd_res = set_default_embedding_response.json()
|
||||
if embd_res.get("code") != 0:
|
||||
raise Exception(embd_res.get("message"))
|
||||
# set image to text model
|
||||
set_default_img2txt_response = requests.patch(
|
||||
url=url,
|
||||
headers=authorization,
|
||||
json={
|
||||
"model_provider": "ZHIPU-AI",
|
||||
"model_instance": "CI",
|
||||
"model_type": "vision",
|
||||
"model_name": "glm-4v"
|
||||
})
|
||||
set_default_img2txt_response = requests.patch(url=url, headers=authorization, json={"model_provider": "ZHIPU-AI", "model_instance": "CI", "model_type": "vision", "model_name": "glm-4v"})
|
||||
img2txt_res = set_default_img2txt_response.json()
|
||||
if img2txt_res.get("code") != 0:
|
||||
raise Exception(img2txt_res.get("message"))
|
||||
|
||||
@@ -73,20 +73,20 @@ def list_document(auth, dataset_id):
|
||||
def get_docs_info(auth, dataset_id, doc_ids=None, doc_id=None):
|
||||
"""
|
||||
Get document information by IDs.
|
||||
|
||||
|
||||
Args:
|
||||
auth: Authorization header
|
||||
dataset_id: Dataset ID
|
||||
doc_ids: List of document IDs (use for multiple) - exclusive with doc_id
|
||||
doc_id: Single document ID (use for one) - exclusive with doc_ids
|
||||
|
||||
|
||||
Raises:
|
||||
ValueError: If both doc_id and doc_ids are provided
|
||||
"""
|
||||
# Validate that id and ids are not used together
|
||||
if doc_id and doc_ids:
|
||||
raise ValueError("Cannot use both 'id' and 'ids' parameters at the same time.")
|
||||
|
||||
|
||||
authorization = {"Authorization": auth}
|
||||
params = {}
|
||||
if doc_ids:
|
||||
@@ -96,7 +96,7 @@ def get_docs_info(auth, dataset_id, doc_ids=None, doc_id=None):
|
||||
elif doc_id:
|
||||
# Single ID
|
||||
params["id"] = doc_id
|
||||
|
||||
|
||||
# Use /api/v1 prefix for dataset API
|
||||
url = f"{HOST_ADDRESS}/api/v1/datasets/{dataset_id}/documents"
|
||||
res = requests.get(url=url, headers=authorization, params=params)
|
||||
@@ -113,4 +113,3 @@ def parse_docs(auth, doc_ids):
|
||||
|
||||
def parse_file(auth, document_id):
|
||||
pass
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
|
||||
def test_get_email(get_email):
|
||||
print("\nEmail account:",flush=True)
|
||||
print(f"{get_email}\n",flush=True)
|
||||
print("\nEmail account:", flush=True)
|
||||
print(f"{get_email}\n", flush=True)
|
||||
|
||||
@@ -40,15 +40,15 @@ def test_parse_txt_document(get_auth):
|
||||
break
|
||||
page_number += 1
|
||||
|
||||
filename = 'ragflow_test.txt'
|
||||
filename = "ragflow_test.txt"
|
||||
res = upload_file(get_auth, dataset_id, f"../test_sdk_api/test_data/{filename}")
|
||||
assert res.get("code") == 0, f"{res.get('message')}"
|
||||
|
||||
res = list_document(get_auth, dataset_id)
|
||||
|
||||
doc_id_list = []
|
||||
for doc in res['data']['docs']:
|
||||
doc_id_list.append(doc['id'])
|
||||
for doc in res["data"]["docs"]:
|
||||
doc_id_list.append(doc["id"])
|
||||
|
||||
res = get_docs_info(get_auth, dataset_id, doc_ids=doc_id_list)
|
||||
print(doc_id_list)
|
||||
@@ -59,13 +59,13 @@ def test_parse_txt_document(get_auth):
|
||||
while True:
|
||||
res = get_docs_info(get_auth, dataset_id, doc_ids=doc_id_list)
|
||||
finished_count = 0
|
||||
for doc_info in res['data']:
|
||||
if doc_info['progress'] == 1:
|
||||
for doc_info in res["data"]:
|
||||
if doc_info["progress"] == 1:
|
||||
finished_count += 1
|
||||
if finished_count == doc_count:
|
||||
break
|
||||
sleep(1)
|
||||
print('time cost {:.1f}s'.format(timer() - start_ts))
|
||||
print("time cost {:.1f}s".format(timer() - start_ts))
|
||||
|
||||
# delete dataset
|
||||
if dataset_list:
|
||||
|
||||
@@ -89,7 +89,7 @@ def test_duplicated_name_dataset(get_auth):
|
||||
if isinstance(data, dict):
|
||||
data = data.get("kbs", [])
|
||||
dataset_list = []
|
||||
pattern = r'^test_create_dataset.*'
|
||||
pattern = r"^test_create_dataset.*"
|
||||
for item in data:
|
||||
dataset_name = item.get("name")
|
||||
dataset_id = item.get("id")
|
||||
@@ -106,10 +106,10 @@ def test_duplicated_name_dataset(get_auth):
|
||||
def test_invalid_name_dataset(get_auth):
|
||||
# create dataset
|
||||
res = create_dataset(get_auth, {"name": 0})
|
||||
assert res['code'] != 0
|
||||
assert res["code"] != 0
|
||||
|
||||
res = create_dataset(get_auth, {"name": ""})
|
||||
assert res['code'] != 0
|
||||
assert res["code"] != 0
|
||||
|
||||
long_string = ""
|
||||
|
||||
@@ -117,7 +117,7 @@ def test_invalid_name_dataset(get_auth):
|
||||
long_string += random.choice(string.ascii_letters + string.digits)
|
||||
|
||||
res = create_dataset(get_auth, {"name": long_string})
|
||||
assert res['code'] != 0
|
||||
assert res["code"] != 0
|
||||
print(res)
|
||||
|
||||
|
||||
@@ -144,13 +144,17 @@ def test_update_different_params_dataset_success(get_auth):
|
||||
print(f"found {len(dataset_list)} datasets")
|
||||
dataset_id = dataset_list[0]
|
||||
|
||||
res = update_dataset(get_auth, dataset_id, {
|
||||
"name": "test_update_dataset",
|
||||
"description": "test",
|
||||
"permission": "me",
|
||||
"chunk_method": "presentation",
|
||||
"language": "spanish",
|
||||
})
|
||||
res = update_dataset(
|
||||
get_auth,
|
||||
dataset_id,
|
||||
{
|
||||
"name": "test_update_dataset",
|
||||
"description": "test",
|
||||
"permission": "me",
|
||||
"chunk_method": "presentation",
|
||||
"language": "spanish",
|
||||
},
|
||||
)
|
||||
assert res.get("code") == 0, f"{res.get('message')}"
|
||||
|
||||
# delete dataset
|
||||
|
||||
Reference in New Issue
Block a user