Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 os
  17. import requests
  18. HOST_ADDRESS = os.getenv('HOST_ADDRESS', 'http://127.0.0.1:9380')
  19. DATASET_NAME_LIMIT = 128
  20. def create_dataset(auth, dataset_name):
  21. authorization = {"Authorization": auth}
  22. url = f"{HOST_ADDRESS}/v1/kb/create"
  23. json = {"name": dataset_name}
  24. res = requests.post(url=url, headers=authorization, json=json)
  25. return res.json()
  26. def list_dataset(auth, page_number):
  27. authorization = {"Authorization": auth}
  28. url = f"{HOST_ADDRESS}/v1/kb/list?page={page_number}"
  29. res = requests.get(url=url, headers=authorization)
  30. return res.json()
  31. def rm_dataset(auth, dataset_id):
  32. authorization = {"Authorization": auth}
  33. url = f"{HOST_ADDRESS}/v1/kb/rm"
  34. json = {"kb_id": dataset_id}
  35. res = requests.post(url=url, headers=authorization, json=json)
  36. return res.json()
  37. def update_dataset(auth, json_req):
  38. authorization = {"Authorization": auth}
  39. url = f"{HOST_ADDRESS}/v1/kb/update"
  40. res = requests.post(url=url, headers=authorization, json=json_req)
  41. return res.json()
  42. def upload_file(auth, dataset_id, path):
  43. authorization = {"Authorization": auth}
  44. url = f"{HOST_ADDRESS}/v1/document/upload"
  45. json_req = {
  46. "kb_id": dataset_id,
  47. }
  48. file = {
  49. 'file': open(f'{path}', 'rb')
  50. }
  51. res = requests.post(url=url, headers=authorization, files=file, data=json_req)
  52. return res.json()
  53. def list_document(auth, dataset_id):
  54. authorization = {"Authorization": auth}
  55. url = f"{HOST_ADDRESS}/v1/document/list?kb_id={dataset_id}"
  56. res = requests.get(url=url, headers=authorization)
  57. return res.json()
  58. def get_docs_info(auth, doc_ids):
  59. authorization = {"Authorization": auth}
  60. json_req = {
  61. "doc_ids": doc_ids
  62. }
  63. url = f"{HOST_ADDRESS}/v1/document/infos"
  64. res = requests.post(url=url, headers=authorization, json=json_req)
  65. return res.json()
  66. def parse_docs(auth, doc_ids):
  67. authorization = {"Authorization": auth}
  68. json_req = {
  69. "doc_ids": doc_ids,
  70. "run": 1
  71. }
  72. url = f"{HOST_ADDRESS}/v1/document/run"
  73. res = requests.post(url=url, headers=authorization, json=json_req)
  74. return res.json()
  75. def parse_file(auth, document_id):
  76. pass