Skip to content

Commit

Permalink
Turn resource to plural form (infiniflow#3061)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

Turn resource to plural form

### Type of change
- [x] Refactoring

Co-authored-by: liuhua <10215101452@stu.ecun.edu.cn>
  • Loading branch information
Feiue and liuhua authored Oct 28, 2024
1 parent 29b8bae commit 34cac09
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion api/apps/sdk/dify_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from api.utils.api_utils import validate_request, build_error_result, apikey_required


@manager.route('/dify/retrievals', methods=['POST'])
@manager.route('/dify/retrieval', methods=['POST'])
@apikey_required
@validate_request("knowledge_id", "query")
def retrieval(tenant_id):
Expand Down
2 changes: 1 addition & 1 deletion api/apps/sdk/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def update_chunk(tenant_id,dataset_id,document_id,chunk_id):



@manager.route('/retrievals', methods=['POST'])
@manager.route('/retrieval', methods=['POST'])
@token_required
def retrieval_test(tenant_id):
req = request.json
Expand Down
6 changes: 3 additions & 3 deletions api/http_api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1169,14 +1169,14 @@ Failure:

## Retrieve chunks

**GET** `/api/v1/retrievals`
**GET** `/api/v1/retrieval`

Retrieves chunks from specified datasets.

### Request

- Method: POST
- URL: `/api/v1/retrievals`
- URL: `/api/v1/retrieval`
- Headers:
- `'content-Type: application/json'`
- `'Authorization: Bearer {YOUR_API_KEY}'`
Expand All @@ -1197,7 +1197,7 @@ Retrieves chunks from specified datasets.

```bash
curl --request POST \
--url http://{address}/api/v1/retrievals \
--url http://{address}/api/v1/retrieval \
--header 'Content-Type: application/json' \
--header 'Authorization: {YOUR_API_KEY}' \
--data '
Expand Down
8 changes: 4 additions & 4 deletions sdk/python/ragflow/modules/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ def __init__(self, rag, res_dict):
super().__init__(rag, res_dict)

def update(self, update_message: dict):
res = self.put(f'/chat/{self.id}',
res = self.put(f'/chats/{self.id}',
update_message)
res = res.json()
if res.get("code") != 0:
raise Exception(res["message"])


def create_session(self, name: str = "New session") -> Session:
res = self.post(f"/chat/{self.id}/session", {"name": name})
res = self.post(f"/chats/{self.id}/sessions", {"name": name})
res = res.json()
if res.get("code") == 0:
return Session(self.rag, res['data'])
raise Exception(res["message"])

def list_sessions(self,page: int = 1, page_size: int = 1024, orderby: str = "create_time", desc: bool = True,
id: str = None, name: str = None) -> List[Session]:
res = self.get(f'/chat/{self.id}/session',{"page": page, "page_size": page_size, "orderby": orderby, "desc": desc, "id": id, "name": name} )
res = self.get(f'/chats/{self.id}/sessions',{"page": page, "page_size": page_size, "orderby": orderby, "desc": desc, "id": id, "name": name} )
res = res.json()
if res.get("code") == 0:
result_list = []
Expand All @@ -69,7 +69,7 @@ def list_sessions(self,page: int = 1, page_size: int = 1024, orderby: str = "cre
raise Exception(res["message"])

def delete_sessions(self,ids):
res = self.rm(f"/chat/{self.id}/session", {"ids": ids})
res = self.rm(f"/chats/{self.id}/sessions", {"ids": ids})
res = res.json()
if res.get("code") != 0:
raise Exception(res.get("message"))
2 changes: 1 addition & 1 deletion sdk/python/ragflow/modules/chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, rag, res_dict):


def update(self,update_message:dict):
res = self.put(f"/dataset/{self.dataset_id}/document/{self.document_id}/chunk/{self.id}",update_message)
res = self.put(f"/datasets/{self.dataset_id}/documents/{self.document_id}/chunks/{self.id}",update_message)
res = res.json()
if res.get("code") != 0 :
raise Exception(res["message"])
Expand Down
12 changes: 6 additions & 6 deletions sdk/python/ragflow/modules/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ def __init__(self, rag, res_dict):
super().__init__(rag, res_dict)

def update(self, update_message: dict):
res = self.put(f'/dataset/{self.id}',
res = self.put(f'/datasets/{self.id}',
update_message)
res = res.json()
if res.get("code") != 0:
raise Exception(res["message"])

def upload_documents(self,document_list: List[dict]):
url = f"/dataset/{self.id}/document"
url = f"/datasets/{self.id}/documents"
files = [("file",(ele["displayed_name"],ele["blob"])) for ele in document_list]
res = self.post(path=url,json=None,files=files)
res = res.json()
Expand All @@ -51,7 +51,7 @@ def upload_documents(self,document_list: List[dict]):
raise Exception(res.get("message"))

def list_documents(self, id: str = None, keywords: str = None, offset: int =1, limit: int = 1024, orderby: str = "create_time", desc: bool = True):
res = self.get(f"/dataset/{self.id}/info",params={"id": id,"keywords": keywords,"offset": offset,"limit": limit,"orderby": orderby,"desc": desc})
res = self.get(f"/datasets/{self.id}/documents",params={"id": id,"keywords": keywords,"offset": offset,"limit": limit,"orderby": orderby,"desc": desc})
res = res.json()
documents = []
if res.get("code") == 0:
Expand All @@ -61,19 +61,19 @@ def list_documents(self, id: str = None, keywords: str = None, offset: int =1, l
raise Exception(res["message"])

def delete_documents(self,ids: List[str] = None):
res = self.rm(f"/dataset/{self.id}/document",{"ids":ids})
res = self.rm(f"/datasets/{self.id}/documents",{"ids":ids})
res = res.json()
if res.get("code") != 0:
raise Exception(res["message"])

def async_parse_documents(self,document_ids):
res = self.post(f"/dataset/{self.id}/chunk",{"document_ids":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 async_cancel_parse_documents(self,document_ids):
res = self.rm(f"/dataset/{self.id}/chunk",{"document_ids":document_ids})
res = self.rm(f"/datasets/{self.id}/chunks",{"document_ids":document_ids})
res = res.json()
if res.get("code") != 0:
raise Exception(res.get("message"))
10 changes: 5 additions & 5 deletions sdk/python/ragflow/modules/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ def __init__(self, rag, res_dict):


def update(self, update_message: dict):
res = self.put(f'/dataset/{self.dataset_id}/info/{self.id}',
res = self.put(f'/datasets/{self.dataset_id}/documents/{self.id}',
update_message)
res = res.json()
if res.get("code") != 0:
raise Exception(res["message"])

def download(self):
res = self.get(f"/dataset/{self.dataset_id}/document/{self.id}")
res = self.get(f"/datasets/{self.dataset_id}/documents/{self.id}")
try:
res = res.json()
raise Exception(res.get("message"))
Expand All @@ -52,7 +52,7 @@ def download(self):

def list_chunks(self,offset=0, limit=30, keywords="", id:str=None):
data={"document_id": self.id,"keywords": keywords,"offset":offset,"limit":limit,"id":id}
res = self.get(f'/dataset/{self.dataset_id}/document/{self.id}/chunk', data)
res = self.get(f'/datasets/{self.dataset_id}/documents/{self.id}/chunks', data)
res = res.json()
if res.get("code") == 0:
chunks=[]
Expand All @@ -64,14 +64,14 @@ def list_chunks(self,offset=0, limit=30, keywords="", id:str=None):


def add_chunk(self, content: str,important_keywords:List[str]=[]):
res = self.post(f'/dataset/{self.dataset_id}/document/{self.id}/chunk', {"content":content,"important_keywords":important_keywords})
res = self.post(f'/datasets/{self.dataset_id}/documents/{self.id}/chunks', {"content":content,"important_keywords":important_keywords})
res = res.json()
if res.get("code") == 0:
return Chunk(self.rag,res["data"].get("chunk"))
raise Exception(res.get("message"))

def delete_chunks(self,ids:List[str] = None):
res = self.rm(f"dataset/{self.dataset_id}/document/{self.id}/chunk",{"ids":ids})
res = self.rm(f"datasets/{self.dataset_id}/documents/{self.id}/chunks",{"ids":ids})
res = res.json()
if res.get("code")!=0:
raise Exception(res.get("message"))
4 changes: 2 additions & 2 deletions sdk/python/ragflow/modules/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def ask(self, question: str, stream: bool = False):
for message in self.messages:
if "reference" in message:
message.pop("reference")
res = self.post(f"/chat/{self.chat_id}/completion",
res = self.post(f"/chats/{self.chat_id}/completions",
{"question": question, "stream": True,"session_id":self.id}, stream=stream)
for line in res.iter_lines():
line = line.decode("utf-8")
Expand Down Expand Up @@ -53,7 +53,7 @@ def ask(self, question: str, stream: bool = False):
yield message

def update(self,update_message):
res = self.put(f"/chat/{self.chat_id}/session/{self.id}",
res = self.put(f"/chats/{self.chat_id}/sessions/{self.id}",
update_message)
res = res.json()
if res.get("code") != 0:
Expand Down
12 changes: 6 additions & 6 deletions sdk/python/ragflow/ragflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def create_dataset(self, name: str, avatar: str = "", description: str = "", lan
parser_config: DataSet.ParserConfig = None) -> DataSet:
if parser_config:
parser_config = parser_config.to_json()
res = self.post("/dataset",
res = self.post("/datasets",
{"name": name, "avatar": avatar, "description": description, "language": language,
"permission": permission, "chunk_method": chunk_method,
"parser_config": parser_config
Expand All @@ -65,7 +65,7 @@ def create_dataset(self, name: str, avatar: str = "", description: str = "", lan
raise Exception(res["message"])

def delete_datasets(self, ids: List[str]):
res = self.delete("/dataset",{"ids": ids})
res = self.delete("/datasets",{"ids": ids})
res=res.json()
if res.get("code") != 0:
raise Exception(res["message"])
Expand All @@ -79,7 +79,7 @@ def get_dataset(self,name: str):
def list_datasets(self, page: int = 1, page_size: int = 1024, orderby: str = "create_time", desc: bool = True,
id: str = None, name: str = None) -> \
List[DataSet]:
res = self.get("/dataset",
res = self.get("/datasets",
{"page": page, "page_size": page_size, "orderby": orderby, "desc": desc, "id": id, "name": name})
res = res.json()
result_list = []
Expand Down Expand Up @@ -129,22 +129,22 @@ def create_chat(self, name: str, avatar: str = "", dataset_ids: List[str] = [],
"dataset_ids": dataset_list,
"llm": llm.to_json(),
"prompt": prompt.to_json()}
res = self.post("/chat", temp_dict)
res = self.post("/chats", temp_dict)
res = res.json()
if res.get("code") == 0:
return Chat(self, res["data"])
raise Exception(res["message"])

def delete_chats(self,ids: List[str] = None,names: List[str] = None ) -> bool:
res = self.delete('/chat',
res = self.delete('/chats',
{"ids":ids, "names":names})
res = res.json()
if res.get("code") != 0:
raise Exception(res["message"])

def list_chats(self, page: int = 1, page_size: int = 1024, orderby: str = "create_time", desc: bool = True,
id: str = None, name: str = None) -> List[Chat]:
res = self.get("/chat",{"page": page, "page_size": page_size, "orderby": orderby, "desc": desc, "id": id, "name": name})
res = self.get("/chats",{"page": page, "page_size": page_size, "orderby": orderby, "desc": desc, "id": id, "name": name})
res = res.json()
result_list = []
if res.get("code") == 0:
Expand Down

0 comments on commit 34cac09

Please sign in to comment.