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.

t_chat.py 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. from ragflow_sdk import RAGFlow
  17. from common import HOST_ADDRESS
  18. def test_create_chat_with_name(get_api_key_fixture):
  19. API_KEY = get_api_key_fixture
  20. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  21. kb = rag.create_dataset(name="test_create_chat")
  22. display_name = "ragflow.txt"
  23. with open("test_data/ragflow.txt", "rb") as file:
  24. blob = file.read()
  25. document = {"display_name": display_name, "blob": blob}
  26. documents = []
  27. documents.append(document)
  28. docs = kb.upload_documents(documents)
  29. for doc in docs:
  30. doc.add_chunk("This is a test to add chunk")
  31. rag.create_chat("test_create_chat", dataset_ids=[kb.id])
  32. def test_update_chat_with_name(get_api_key_fixture):
  33. API_KEY = get_api_key_fixture
  34. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  35. kb = rag.create_dataset(name="test_update_chat")
  36. display_name = "ragflow.txt"
  37. with open("test_data/ragflow.txt", "rb") as file:
  38. blob = file.read()
  39. document = {"display_name": display_name, "blob": blob}
  40. documents = []
  41. documents.append(document)
  42. docs = kb.upload_documents(documents)
  43. for doc in docs:
  44. doc.add_chunk("This is a test to add chunk")
  45. chat = rag.create_chat("test_update_chat", dataset_ids=[kb.id])
  46. chat.update({"name": "new_chat"})
  47. def test_delete_chats_with_success(get_api_key_fixture):
  48. API_KEY = get_api_key_fixture
  49. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  50. kb = rag.create_dataset(name="test_delete_chat")
  51. display_name = "ragflow.txt"
  52. with open("test_data/ragflow.txt", "rb") as file:
  53. blob = file.read()
  54. document = {"display_name": display_name, "blob": blob}
  55. documents = []
  56. documents.append(document)
  57. docs = kb.upload_documents(documents)
  58. for doc in docs:
  59. doc.add_chunk("This is a test to add chunk")
  60. chat = rag.create_chat("test_delete_chat", dataset_ids=[kb.id])
  61. rag.delete_chats(ids=[chat.id])
  62. def test_list_chats_with_success(get_api_key_fixture):
  63. API_KEY = get_api_key_fixture
  64. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  65. kb = rag.create_dataset(name="test_list_chats")
  66. display_name = "ragflow.txt"
  67. with open("test_data/ragflow.txt", "rb") as file:
  68. blob = file.read()
  69. document = {"display_name": display_name, "blob": blob}
  70. documents = []
  71. documents.append(document)
  72. docs = kb.upload_documents(documents)
  73. for doc in docs:
  74. doc.add_chunk("This is a test to add chunk")
  75. rag.create_chat("test_list_1", dataset_ids=[kb.id])
  76. rag.create_chat("test_list_2", dataset_ids=[kb.id])
  77. rag.list_chats()