Fix some issues in API (#2982)
### What problem does this PR solve? Fix some issues in API ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --------- Co-authored-by: liuhua <10215101452@stu.ecun.edu.cn>
This commit is contained in:
@@ -49,17 +49,11 @@ class RAGFlow:
|
||||
return res
|
||||
|
||||
def create_dataset(self, name: str, avatar: str = "", description: str = "", language: str = "English",
|
||||
permission: str = "me",
|
||||
document_count: int = 0, chunk_count: int = 0, chunk_method: str = "naive",
|
||||
permission: str = "me",chunk_method: str = "naive",
|
||||
parser_config: DataSet.ParserConfig = None) -> DataSet:
|
||||
if parser_config is None:
|
||||
parser_config = DataSet.ParserConfig(self, {"chunk_token_count": 128, "layout_recognize": True,
|
||||
"delimiter": "\n!?。;!?", "task_page_size": 12})
|
||||
parser_config = parser_config.to_json()
|
||||
res = self.post("/dataset",
|
||||
{"name": name, "avatar": avatar, "description": description, "language": language,
|
||||
"permission": permission,
|
||||
"document_count": document_count, "chunk_count": chunk_count, "chunk_method": chunk_method,
|
||||
"permission": permission, "chunk_method": chunk_method,
|
||||
"parser_config": parser_config
|
||||
}
|
||||
)
|
||||
@@ -93,11 +87,11 @@ class RAGFlow:
|
||||
return result_list
|
||||
raise Exception(res["message"])
|
||||
|
||||
def create_chat(self, name: str, avatar: str = "", knowledgebases: List[DataSet] = [],
|
||||
def create_chat(self, name: str, avatar: str = "", datasets: List[DataSet] = [],
|
||||
llm: Chat.LLM = None, prompt: Chat.Prompt = None) -> Chat:
|
||||
datasets = []
|
||||
for dataset in knowledgebases:
|
||||
datasets.append(dataset.to_json())
|
||||
dataset_list = []
|
||||
for dataset in datasets:
|
||||
dataset_list.append(dataset.to_json())
|
||||
|
||||
if llm is None:
|
||||
llm = Chat.LLM(self, {"model_name": None,
|
||||
@@ -130,7 +124,7 @@ class RAGFlow:
|
||||
|
||||
temp_dict = {"name": name,
|
||||
"avatar": avatar,
|
||||
"knowledgebases": datasets,
|
||||
"datasets": dataset_list,
|
||||
"llm": llm.to_json(),
|
||||
"prompt": prompt.to_json()}
|
||||
res = self.post("/chat", temp_dict)
|
||||
@@ -158,25 +152,22 @@ class RAGFlow:
|
||||
raise Exception(res["message"])
|
||||
|
||||
|
||||
def retrieve(self, question="",datasets=None,documents=None, offset=1, limit=30, similarity_threshold=0.2,vector_similarity_weight=0.3,top_k=1024,rerank_id:str=None,keyword:bool=False,):
|
||||
data_params = {
|
||||
def retrieve(self, datasets,documents,question="", offset=1, limit=1024, similarity_threshold=0.2,vector_similarity_weight=0.3,top_k=1024,rerank_id:str=None,keyword:bool=False,):
|
||||
data_json ={
|
||||
"offset": offset,
|
||||
"limit": limit,
|
||||
"similarity_threshold": similarity_threshold,
|
||||
"vector_similarity_weight": vector_similarity_weight,
|
||||
"top_k": top_k,
|
||||
"knowledgebase_id": datasets,
|
||||
"rerank_id":rerank_id,
|
||||
"keyword":keyword
|
||||
}
|
||||
data_json ={
|
||||
"rerank_id": rerank_id,
|
||||
"keyword": keyword,
|
||||
"question": question,
|
||||
"datasets": datasets,
|
||||
"documents": documents
|
||||
}
|
||||
|
||||
# Send a POST request to the backend service (using requests library as an example, actual implementation may vary)
|
||||
res = self.get(f'/retrieval', data_params,data_json)
|
||||
res = self.post(f'/retrieval',json=data_json)
|
||||
res = res.json()
|
||||
if res.get("code") ==0:
|
||||
chunks=[]
|
||||
|
||||
Reference in New Issue
Block a user