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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 common import HOST_ADDRESS
  17. from ragflow_sdk import RAGFlow
  18. from ragflow_sdk.modules.chat import Chat
  19. def test_create_chat_with_name(get_api_key_fixture):
  20. API_KEY = get_api_key_fixture
  21. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  22. kb = rag.create_dataset(name="test_create_chat")
  23. display_name = "ragflow.txt"
  24. with open("test_data/ragflow.txt", "rb") as file:
  25. blob = file.read()
  26. document = {"display_name": display_name, "blob": blob}
  27. documents = []
  28. documents.append(document)
  29. docs = kb.upload_documents(documents)
  30. for doc in docs:
  31. doc.add_chunk("This is a test to add chunk")
  32. llm = Chat.LLM(
  33. rag,
  34. {
  35. "model_name": "glm-4-flash@ZHIPU-AI",
  36. "temperature": 0.1,
  37. "top_p": 0.3,
  38. "presence_penalty": 0.4,
  39. "frequency_penalty": 0.7,
  40. "max_tokens": 512,
  41. },
  42. )
  43. rag.create_chat("test_create_chat", dataset_ids=[kb.id], llm=llm)
  44. def test_update_chat_with_name(get_api_key_fixture):
  45. API_KEY = get_api_key_fixture
  46. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  47. kb = rag.create_dataset(name="test_update_chat")
  48. display_name = "ragflow.txt"
  49. with open("test_data/ragflow.txt", "rb") as file:
  50. blob = file.read()
  51. document = {"display_name": display_name, "blob": blob}
  52. documents = []
  53. documents.append(document)
  54. docs = kb.upload_documents(documents)
  55. for doc in docs:
  56. doc.add_chunk("This is a test to add chunk")
  57. llm = Chat.LLM(
  58. rag,
  59. {
  60. "model_name": "glm-4-flash@ZHIPU-AI",
  61. "temperature": 0.1,
  62. "top_p": 0.3,
  63. "presence_penalty": 0.4,
  64. "frequency_penalty": 0.7,
  65. "max_tokens": 512,
  66. },
  67. )
  68. chat = rag.create_chat("test_update_chat", dataset_ids=[kb.id], llm=llm)
  69. chat.update({"name": "new_chat"})
  70. def test_delete_chats_with_success(get_api_key_fixture):
  71. API_KEY = get_api_key_fixture
  72. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  73. kb = rag.create_dataset(name="test_delete_chat")
  74. display_name = "ragflow.txt"
  75. with open("test_data/ragflow.txt", "rb") as file:
  76. blob = file.read()
  77. document = {"display_name": display_name, "blob": blob}
  78. documents = []
  79. documents.append(document)
  80. docs = kb.upload_documents(documents)
  81. for doc in docs:
  82. doc.add_chunk("This is a test to add chunk")
  83. llm = Chat.LLM(
  84. rag,
  85. {
  86. "model_name": "glm-4-flash@ZHIPU-AI",
  87. "temperature": 0.1,
  88. "top_p": 0.3,
  89. "presence_penalty": 0.4,
  90. "frequency_penalty": 0.7,
  91. "max_tokens": 512,
  92. },
  93. )
  94. chat = rag.create_chat("test_delete_chat", dataset_ids=[kb.id], llm=llm)
  95. rag.delete_chats(ids=[chat.id])
  96. def test_list_chats_with_success(get_api_key_fixture):
  97. API_KEY = get_api_key_fixture
  98. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  99. kb = rag.create_dataset(name="test_list_chats")
  100. display_name = "ragflow.txt"
  101. with open("test_data/ragflow.txt", "rb") as file:
  102. blob = file.read()
  103. document = {"display_name": display_name, "blob": blob}
  104. documents = []
  105. documents.append(document)
  106. docs = kb.upload_documents(documents)
  107. for doc in docs:
  108. doc.add_chunk("This is a test to add chunk")
  109. llm = Chat.LLM(
  110. rag,
  111. {
  112. "model_name": "glm-4-flash@ZHIPU-AI",
  113. "temperature": 0.1,
  114. "top_p": 0.3,
  115. "presence_penalty": 0.4,
  116. "frequency_penalty": 0.7,
  117. "max_tokens": 512,
  118. },
  119. )
  120. rag.create_chat("test_list_1", dataset_ids=[kb.id], llm=llm)
  121. rag.create_chat("test_list_2", dataset_ids=[kb.id], llm=llm)
  122. rag.list_chats()