You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

common.py 1.0KB

12345678910111213141516171819202122232425262728293031323334
  1. import os
  2. import requests
  3. HOST_ADDRESS = os.getenv('HOST_ADDRESS', 'http://127.0.0.1:9380')
  4. DATASET_NAME_LIMIT = 128
  5. def create_dataset(auth, dataset_name):
  6. authorization = {"Authorization": auth}
  7. url = f"{HOST_ADDRESS}/v1/kb/create"
  8. json = {"name": dataset_name}
  9. res = requests.post(url=url, headers=authorization, json=json)
  10. return res.json()
  11. def list_dataset(auth, page_number):
  12. authorization = {"Authorization": auth}
  13. url = f"{HOST_ADDRESS}/v1/kb/list?page={page_number}"
  14. res = requests.get(url=url, headers=authorization)
  15. return res.json()
  16. def rm_dataset(auth, dataset_id):
  17. authorization = {"Authorization": auth}
  18. url = f"{HOST_ADDRESS}/v1/kb/rm"
  19. json = {"kb_id": dataset_id}
  20. res = requests.post(url=url, headers=authorization, json=json)
  21. return res.json()
  22. def update_dataset(auth, json_req):
  23. authorization = {"Authorization": auth}
  24. url = f"{HOST_ADDRESS}/v1/kb/update"
  25. res = requests.post(url=url, headers=authorization, json=json_req)
  26. return res.json()