mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-23 00:46:42 +08:00
### What problem does this PR solve?
This reverts commit 1a608ac411.
### Type of change
- [x] Other (please describe):
This commit is contained in:
@@ -30,6 +30,7 @@ KB_APP_URL = f"/{VERSION}/kb"
|
||||
DATASETS_URL = f"/api/{VERSION}/datasets"
|
||||
DOCUMENT_APP_URL = f"/{VERSION}/document"
|
||||
CHUNK_API_URL = f"/{VERSION}/chunk"
|
||||
DIALOG_APP_URL = f"/{VERSION}/dialog"
|
||||
# SESSION_WITH_CHAT_ASSISTANT_API_URL = "/api/v1/chats/{chat_id}/sessions"
|
||||
# SESSION_WITH_AGENT_API_URL = "/api/v1/agents/{agent_id}/sessions"
|
||||
MEMORY_API_URL = f"/api/{VERSION}/memories"
|
||||
@@ -468,6 +469,103 @@ def batch_add_chunks(auth, doc_id, num):
|
||||
return chunk_ids
|
||||
|
||||
|
||||
# DIALOG APP
|
||||
def create_dialog(auth, payload=None, *, headers=HEADERS, data=None):
|
||||
if payload is None:
|
||||
payload = {}
|
||||
url = f"{HOST_ADDRESS}{DIALOG_APP_URL}/set"
|
||||
req_id = str(uuid.uuid4())
|
||||
req_headers = dict(headers)
|
||||
req_headers["X-Request-ID"] = req_id
|
||||
start = time.monotonic()
|
||||
res = requests.post(url=url, headers=req_headers, auth=auth, json=payload, data=data)
|
||||
elapsed_ms = (time.monotonic() - start) * 1000
|
||||
resp_json = None
|
||||
json_error = None
|
||||
try:
|
||||
resp_json = res.json()
|
||||
except ValueError as exc:
|
||||
json_error = exc
|
||||
_log_http_debug("POST", url, req_id, payload, res.status_code, res.text, resp_json, elapsed_ms)
|
||||
if _http_debug_enabled():
|
||||
if not res.ok or (resp_json is not None and resp_json.get("code") != 0):
|
||||
payload_summary = _redact_payload(payload)
|
||||
raise AssertionError(
|
||||
"HTTP helper failure: "
|
||||
f"req_id={req_id} url={url} status={res.status_code} "
|
||||
f"payload={payload_summary} response={res.text}"
|
||||
)
|
||||
if json_error:
|
||||
raise json_error
|
||||
return resp_json
|
||||
|
||||
|
||||
def update_dialog(auth, payload=None, *, headers=HEADERS, data=None):
|
||||
res = requests.post(url=f"{HOST_ADDRESS}{DIALOG_APP_URL}/set", headers=headers, auth=auth, json=payload, data=data)
|
||||
return res.json()
|
||||
|
||||
|
||||
def get_dialog(auth, params=None, *, headers=HEADERS):
|
||||
res = requests.get(url=f"{HOST_ADDRESS}{DIALOG_APP_URL}/get", headers=headers, auth=auth, params=params)
|
||||
return res.json()
|
||||
|
||||
|
||||
def list_dialogs(auth, *, headers=HEADERS):
|
||||
res = requests.get(url=f"{HOST_ADDRESS}{DIALOG_APP_URL}/list", headers=headers, auth=auth)
|
||||
return res.json()
|
||||
|
||||
|
||||
def delete_dialog(auth, payload=None, *, headers=HEADERS, data=None):
|
||||
res = requests.post(url=f"{HOST_ADDRESS}{DIALOG_APP_URL}/rm", headers=headers, auth=auth, json=payload, data=data)
|
||||
return res.json()
|
||||
|
||||
|
||||
def batch_create_dialogs(auth, num, kb_ids=None):
|
||||
if kb_ids is None:
|
||||
kb_ids = []
|
||||
|
||||
dialog_ids = []
|
||||
for i in range(num):
|
||||
if kb_ids:
|
||||
prompt_config = {
|
||||
"system": "You are a helpful assistant. Use the following knowledge to answer questions: {knowledge}",
|
||||
"parameters": [{"key": "knowledge", "optional": False}],
|
||||
}
|
||||
else:
|
||||
prompt_config = {
|
||||
"system": "You are a helpful assistant.",
|
||||
"parameters": [],
|
||||
}
|
||||
payload = {
|
||||
"name": f"dialog_{i}",
|
||||
"description": f"Test dialog {i}",
|
||||
"kb_ids": kb_ids,
|
||||
"prompt_config": prompt_config,
|
||||
"top_n": 6,
|
||||
"top_k": 1024,
|
||||
"similarity_threshold": 0.1,
|
||||
"vector_similarity_weight": 0.3,
|
||||
"llm_setting": {"model": "gpt-3.5-turbo", "temperature": 0.7},
|
||||
}
|
||||
res = create_dialog(auth, payload)
|
||||
if res is None or res.get("code") != 0:
|
||||
uses_knowledge = "{knowledge}" in payload["prompt_config"]["system"]
|
||||
raise AssertionError(
|
||||
"batch_create_dialogs failed: "
|
||||
f"res={res} kb_ids_len={len(kb_ids)} uses_knowledge={uses_knowledge}"
|
||||
)
|
||||
if res["code"] == 0:
|
||||
dialog_ids.append(res["data"]["id"])
|
||||
return dialog_ids
|
||||
|
||||
|
||||
def delete_dialogs(auth):
|
||||
res = list_dialogs(auth)
|
||||
if res["code"] == 0 and res["data"]:
|
||||
dialog_ids = [dialog["id"] for dialog in res["data"]]
|
||||
if dialog_ids:
|
||||
delete_dialog(auth, {"dialog_ids": dialog_ids})
|
||||
|
||||
# MEMORY APP
|
||||
def create_memory(auth, payload=None):
|
||||
url = f"{HOST_ADDRESS}{MEMORY_API_URL}"
|
||||
|
||||
Reference in New Issue
Block a user