您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

t_assistant.py 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from ragflow import RAGFlow, Assistant
  2. from common import API_KEY, HOST_ADDRESS
  3. from test_sdkbase import TestSdk
  4. class TestAssistant(TestSdk):
  5. def test_create_assistant_with_success(self):
  6. """
  7. Test creating an assistant with success
  8. """
  9. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  10. kb = rag.get_dataset(name="God")
  11. assistant = rag.create_assistant("God",knowledgebases=[kb])
  12. if isinstance(assistant, Assistant):
  13. assert assistant.name == "God", "Name does not match."
  14. else:
  15. assert False, f"Failed to create assistant, error: {assistant}"
  16. def test_update_assistant_with_success(self):
  17. """
  18. Test updating an assistant with success.
  19. """
  20. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  21. kb = rag.get_dataset(name="God")
  22. assistant = rag.create_assistant("ABC",knowledgebases=[kb])
  23. if isinstance(assistant, Assistant):
  24. assert assistant.name == "ABC", "Name does not match."
  25. assistant.name = 'DEF'
  26. res = assistant.save()
  27. assert res is True, f"Failed to update assistant, error: {res}"
  28. else:
  29. assert False, f"Failed to create assistant, error: {assistant}"
  30. def test_delete_assistant_with_success(self):
  31. """
  32. Test deleting an assistant with success
  33. """
  34. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  35. kb = rag.get_dataset(name="God")
  36. assistant = rag.create_assistant("MA",knowledgebases=[kb])
  37. if isinstance(assistant, Assistant):
  38. assert assistant.name == "MA", "Name does not match."
  39. res = assistant.delete()
  40. assert res is True, f"Failed to delete assistant, error: {res}"
  41. else:
  42. assert False, f"Failed to create assistant, error: {assistant}"
  43. def test_list_assistants_with_success(self):
  44. """
  45. Test listing assistants with success
  46. """
  47. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  48. list_assistants = rag.list_assistants()
  49. assert len(list_assistants) > 0, "Do not exist any assistant"
  50. for assistant in list_assistants:
  51. assert isinstance(assistant, Assistant), "Existence type is not assistant."
  52. def test_get_detail_assistant_with_success(self):
  53. """
  54. Test getting an assistant's detail with success
  55. """
  56. rag = RAGFlow(API_KEY, HOST_ADDRESS)
  57. assistant = rag.get_assistant(name="God")
  58. assert isinstance(assistant, Assistant), f"Failed to get assistant, error: {assistant}."
  59. assert assistant.name == "God", "Name does not match"