ruff check preview (#25653)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -18,9 +18,7 @@ FILE_PATH_BASE = os.path.dirname(__file__)
|
||||
class TestKnowledgeBaseClient(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.knowledge_base_client = KnowledgeBaseClient(API_KEY, base_url=API_BASE_URL)
|
||||
self.README_FILE_PATH = os.path.abspath(
|
||||
os.path.join(FILE_PATH_BASE, "../README.md")
|
||||
)
|
||||
self.README_FILE_PATH = os.path.abspath(os.path.join(FILE_PATH_BASE, "../README.md"))
|
||||
self.dataset_id = None
|
||||
self.document_id = None
|
||||
self.segment_id = None
|
||||
@@ -28,9 +26,7 @@ class TestKnowledgeBaseClient(unittest.TestCase):
|
||||
|
||||
def _get_dataset_kb_client(self):
|
||||
self.assertIsNotNone(self.dataset_id)
|
||||
return KnowledgeBaseClient(
|
||||
API_KEY, base_url=API_BASE_URL, dataset_id=self.dataset_id
|
||||
)
|
||||
return KnowledgeBaseClient(API_KEY, base_url=API_BASE_URL, dataset_id=self.dataset_id)
|
||||
|
||||
def test_001_create_dataset(self):
|
||||
response = self.knowledge_base_client.create_dataset(name="test_dataset")
|
||||
@@ -76,9 +72,7 @@ class TestKnowledgeBaseClient(unittest.TestCase):
|
||||
def _test_004_update_document_by_text(self):
|
||||
client = self._get_dataset_kb_client()
|
||||
self.assertIsNotNone(self.document_id)
|
||||
response = client.update_document_by_text(
|
||||
self.document_id, "test_document_updated", "test_text_updated"
|
||||
)
|
||||
response = client.update_document_by_text(self.document_id, "test_document_updated", "test_text_updated")
|
||||
data = response.json()
|
||||
self.assertIn("document", data)
|
||||
self.assertIn("batch", data)
|
||||
@@ -93,9 +87,7 @@ class TestKnowledgeBaseClient(unittest.TestCase):
|
||||
def _test_006_update_document_by_file(self):
|
||||
client = self._get_dataset_kb_client()
|
||||
self.assertIsNotNone(self.document_id)
|
||||
response = client.update_document_by_file(
|
||||
self.document_id, self.README_FILE_PATH
|
||||
)
|
||||
response = client.update_document_by_file(self.document_id, self.README_FILE_PATH)
|
||||
data = response.json()
|
||||
self.assertIn("document", data)
|
||||
self.assertIn("batch", data)
|
||||
@@ -125,9 +117,7 @@ class TestKnowledgeBaseClient(unittest.TestCase):
|
||||
|
||||
def _test_010_add_segments(self):
|
||||
client = self._get_dataset_kb_client()
|
||||
response = client.add_segments(
|
||||
self.document_id, [{"content": "test text segment 1"}]
|
||||
)
|
||||
response = client.add_segments(self.document_id, [{"content": "test text segment 1"}])
|
||||
data = response.json()
|
||||
self.assertIn("data", data)
|
||||
self.assertGreater(len(data["data"]), 0)
|
||||
@@ -174,18 +164,12 @@ class TestChatClient(unittest.TestCase):
|
||||
self.chat_client = ChatClient(API_KEY)
|
||||
|
||||
def test_create_chat_message(self):
|
||||
response = self.chat_client.create_chat_message(
|
||||
{}, "Hello, World!", "test_user"
|
||||
)
|
||||
response = self.chat_client.create_chat_message({}, "Hello, World!", "test_user")
|
||||
self.assertIn("answer", response.text)
|
||||
|
||||
def test_create_chat_message_with_vision_model_by_remote_url(self):
|
||||
files = [
|
||||
{"type": "image", "transfer_method": "remote_url", "url": "your_image_url"}
|
||||
]
|
||||
response = self.chat_client.create_chat_message(
|
||||
{}, "Describe the picture.", "test_user", files=files
|
||||
)
|
||||
files = [{"type": "image", "transfer_method": "remote_url", "url": "your_image_url"}]
|
||||
response = self.chat_client.create_chat_message({}, "Describe the picture.", "test_user", files=files)
|
||||
self.assertIn("answer", response.text)
|
||||
|
||||
def test_create_chat_message_with_vision_model_by_local_file(self):
|
||||
@@ -196,15 +180,11 @@ class TestChatClient(unittest.TestCase):
|
||||
"upload_file_id": "your_file_id",
|
||||
}
|
||||
]
|
||||
response = self.chat_client.create_chat_message(
|
||||
{}, "Describe the picture.", "test_user", files=files
|
||||
)
|
||||
response = self.chat_client.create_chat_message({}, "Describe the picture.", "test_user", files=files)
|
||||
self.assertIn("answer", response.text)
|
||||
|
||||
def test_get_conversation_messages(self):
|
||||
response = self.chat_client.get_conversation_messages(
|
||||
"test_user", "your_conversation_id"
|
||||
)
|
||||
response = self.chat_client.get_conversation_messages("test_user", "your_conversation_id")
|
||||
self.assertIn("answer", response.text)
|
||||
|
||||
def test_get_conversations(self):
|
||||
@@ -223,9 +203,7 @@ class TestCompletionClient(unittest.TestCase):
|
||||
self.assertIn("answer", response.text)
|
||||
|
||||
def test_create_completion_message_with_vision_model_by_remote_url(self):
|
||||
files = [
|
||||
{"type": "image", "transfer_method": "remote_url", "url": "your_image_url"}
|
||||
]
|
||||
files = [{"type": "image", "transfer_method": "remote_url", "url": "your_image_url"}]
|
||||
response = self.completion_client.create_completion_message(
|
||||
{"query": "Describe the picture."}, "blocking", "test_user", files
|
||||
)
|
||||
@@ -250,9 +228,7 @@ class TestDifyClient(unittest.TestCase):
|
||||
self.dify_client = DifyClient(API_KEY)
|
||||
|
||||
def test_message_feedback(self):
|
||||
response = self.dify_client.message_feedback(
|
||||
"your_message_id", "like", "test_user"
|
||||
)
|
||||
response = self.dify_client.message_feedback("your_message_id", "like", "test_user")
|
||||
self.assertIn("success", response.text)
|
||||
|
||||
def test_get_application_parameters(self):
|
||||
|
||||
Reference in New Issue
Block a user