Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

t_assistant.py 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.create_dataset(name="test_create_assistant")
  11. assistant = rag.create_assistant("test_create", knowledgebases=[kb])
  12. if isinstance(assistant, Assistant):
  13. assert assistant.name == "test_create", "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.create_dataset(name="test_update_assistant")
  22. assistant = rag.create_assistant("test_update", knowledgebases=[kb])
  23. if isinstance(assistant, Assistant):
  24. assert assistant.name == "test_update", "Name does not match."
  25. assistant.name = 'new_assistant'
  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.create_dataset(name="test_delete_assistant")
  36. assistant = rag.create_assistant("test_delete", knowledgebases=[kb])
  37. if isinstance(assistant, Assistant):
  38. assert assistant.name == "test_delete", "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. kb = rag.create_dataset(name="test_get_assistant")
  58. rag.create_assistant("test_get_assistant", knowledgebases=[kb])
  59. assistant = rag.get_assistant(name="test_get_assistant")
  60. assert isinstance(assistant, Assistant), f"Failed to get assistant, error: {assistant}."
  61. assert assistant.name == "test_get_assistant", "Name does not match"