Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

common.py 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import requests
  17. from configs import HOST_ADDRESS
  18. HEADERS = {"Content-Type": "application/json"}
  19. KB_APP_URL = "/v1/kb"
  20. # FILE_API_URL = "/api/v1/datasets/{dataset_id}/documents"
  21. # FILE_CHUNK_API_URL = "/api/v1/datasets/{dataset_id}/chunks"
  22. # CHUNK_API_URL = "/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks"
  23. # CHAT_ASSISTANT_API_URL = "/api/v1/chats"
  24. # SESSION_WITH_CHAT_ASSISTANT_API_URL = "/api/v1/chats/{chat_id}/sessions"
  25. # SESSION_WITH_AGENT_API_URL = "/api/v1/agents/{agent_id}/sessions"
  26. # DATASET MANAGEMENT
  27. def create_kb(auth, payload=None, *, headers=HEADERS, data=None):
  28. res = requests.post(url=f"{HOST_ADDRESS}{KB_APP_URL}/create", headers=headers, auth=auth, json=payload, data=data)
  29. return res.json()
  30. def list_kbs(auth, params=None, payload=None, *, headers=HEADERS, data=None):
  31. if payload is None:
  32. payload = {}
  33. res = requests.post(url=f"{HOST_ADDRESS}{KB_APP_URL}/list", headers=headers, auth=auth, params=params, json=payload, data=data)
  34. return res.json()
  35. def update_kb(auth, payload=None, *, headers=HEADERS, data=None):
  36. res = requests.post(url=f"{HOST_ADDRESS}{KB_APP_URL}/update", headers=headers, auth=auth, json=payload, data=data)
  37. return res.json()
  38. def rm_kb(auth, payload=None, *, headers=HEADERS, data=None):
  39. res = requests.post(url=f"{HOST_ADDRESS}{KB_APP_URL}/rm", headers=headers, auth=auth, json=payload, data=data)
  40. return res.json()
  41. def detail_kb(auth, params=None, *, headers=HEADERS):
  42. res = requests.get(url=f"{HOST_ADDRESS}{KB_APP_URL}/detail", headers=headers, auth=auth, params=params)
  43. return res.json()
  44. def list_tags_from_kbs(auth, params=None, *, headers=HEADERS):
  45. res = requests.get(url=f"{HOST_ADDRESS}{KB_APP_URL}/tags", headers=headers, auth=auth, params=params)
  46. return res.json()
  47. def list_tags(auth, dataset_id, params=None, *, headers=HEADERS):
  48. res = requests.get(url=f"{HOST_ADDRESS}{KB_APP_URL}/{dataset_id}/tags", headers=headers, auth=auth, params=params)
  49. return res.json()
  50. def rm_tags(auth, dataset_id, payload=None, *, headers=HEADERS, data=None):
  51. res = requests.post(url=f"{HOST_ADDRESS}{KB_APP_URL}/{dataset_id}/rm_tags", headers=headers, auth=auth, json=payload, data=data)
  52. return res.json()
  53. def rename_tags(auth, dataset_id, payload=None, *, headers=HEADERS, data=None):
  54. res = requests.post(url=f"{HOST_ADDRESS}{KB_APP_URL}/{dataset_id}/rename_tags", headers=headers, auth=auth, json=payload, data=data)
  55. return res.json()
  56. def knowledge_graph(auth, dataset_id, params=None, *, headers=HEADERS):
  57. res = requests.get(url=f"{HOST_ADDRESS}{KB_APP_URL}/{dataset_id}/knowledge_graph", headers=headers, auth=auth, params=params)
  58. return res.json()
  59. def delete_knowledge_graph(auth, dataset_id, payload=None, *, headers=HEADERS, data=None):
  60. res = requests.delete(url=f"{HOST_ADDRESS}{KB_APP_URL}/{dataset_id}/delete_knowledge_graph", headers=headers, auth=auth, json=payload, data=data)
  61. return res.json()
  62. def batch_create_datasets(auth, num):
  63. ids = []
  64. for i in range(num):
  65. res = create_kb(auth, {"name": f"kb_{i}"})
  66. ids.append(res["data"]["kb_id"])
  67. return ids