mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Refactor Chat API (#2804)
### What problem does this PR solve? Refactor Chat API ### Type of change - [x] Refactoring --------- Co-authored-by: liuhua <10215101452@stu.ecun.edu.cn>
This commit is contained in:
@ -1,68 +0,0 @@
|
||||
from ragflow import RAGFlow, Assistant
|
||||
|
||||
from common import API_KEY, HOST_ADDRESS
|
||||
from test_sdkbase import TestSdk
|
||||
|
||||
|
||||
class TestAssistant(TestSdk):
|
||||
def test_create_assistant_with_success(self):
|
||||
"""
|
||||
Test creating an assistant with success
|
||||
"""
|
||||
rag = RAGFlow(API_KEY, HOST_ADDRESS)
|
||||
kb = rag.create_dataset(name="test_create_assistant")
|
||||
assistant = rag.create_assistant("test_create", knowledgebases=[kb])
|
||||
if isinstance(assistant, Assistant):
|
||||
assert assistant.name == "test_create", "Name does not match."
|
||||
else:
|
||||
assert False, f"Failed to create assistant, error: {assistant}"
|
||||
|
||||
def test_update_assistant_with_success(self):
|
||||
"""
|
||||
Test updating an assistant with success.
|
||||
"""
|
||||
rag = RAGFlow(API_KEY, HOST_ADDRESS)
|
||||
kb = rag.create_dataset(name="test_update_assistant")
|
||||
assistant = rag.create_assistant("test_update", knowledgebases=[kb])
|
||||
if isinstance(assistant, Assistant):
|
||||
assert assistant.name == "test_update", "Name does not match."
|
||||
assistant.name = 'new_assistant'
|
||||
res = assistant.save()
|
||||
assert res is True, f"Failed to update assistant, error: {res}"
|
||||
else:
|
||||
assert False, f"Failed to create assistant, error: {assistant}"
|
||||
|
||||
def test_delete_assistant_with_success(self):
|
||||
"""
|
||||
Test deleting an assistant with success
|
||||
"""
|
||||
rag = RAGFlow(API_KEY, HOST_ADDRESS)
|
||||
kb = rag.create_dataset(name="test_delete_assistant")
|
||||
assistant = rag.create_assistant("test_delete", knowledgebases=[kb])
|
||||
if isinstance(assistant, Assistant):
|
||||
assert assistant.name == "test_delete", "Name does not match."
|
||||
res = assistant.delete()
|
||||
assert res is True, f"Failed to delete assistant, error: {res}"
|
||||
else:
|
||||
assert False, f"Failed to create assistant, error: {assistant}"
|
||||
|
||||
def test_list_assistants_with_success(self):
|
||||
"""
|
||||
Test listing assistants with success
|
||||
"""
|
||||
rag = RAGFlow(API_KEY, HOST_ADDRESS)
|
||||
list_assistants = rag.list_assistants()
|
||||
assert len(list_assistants) > 0, "Do not exist any assistant"
|
||||
for assistant in list_assistants:
|
||||
assert isinstance(assistant, Assistant), "Existence type is not assistant."
|
||||
|
||||
def test_get_detail_assistant_with_success(self):
|
||||
"""
|
||||
Test getting an assistant's detail with success
|
||||
"""
|
||||
rag = RAGFlow(API_KEY, HOST_ADDRESS)
|
||||
kb = rag.create_dataset(name="test_get_assistant")
|
||||
rag.create_assistant("test_get_assistant", knowledgebases=[kb])
|
||||
assistant = rag.get_assistant(name="test_get_assistant")
|
||||
assert isinstance(assistant, Assistant), f"Failed to get assistant, error: {assistant}."
|
||||
assert assistant.name == "test_get_assistant", "Name does not match"
|
||||
56
sdk/python/test/t_chat.py
Normal file
56
sdk/python/test/t_chat.py
Normal file
@ -0,0 +1,56 @@
|
||||
from ragflow import RAGFlow, Chat
|
||||
|
||||
from common import API_KEY, HOST_ADDRESS
|
||||
from test_sdkbase import TestSdk
|
||||
|
||||
|
||||
class TestChat(TestSdk):
|
||||
def test_create_chat_with_success(self):
|
||||
"""
|
||||
Test creating an chat with success
|
||||
"""
|
||||
rag = RAGFlow(API_KEY, HOST_ADDRESS)
|
||||
kb = rag.create_dataset(name="test_create_chat")
|
||||
chat = rag.create_chat("test_create", knowledgebases=[kb])
|
||||
if isinstance(chat, Chat):
|
||||
assert chat.name == "test_create", "Name does not match."
|
||||
else:
|
||||
assert False, f"Failed to create chat, error: {chat}"
|
||||
|
||||
def test_update_chat_with_success(self):
|
||||
"""
|
||||
Test updating an chat with success.
|
||||
"""
|
||||
rag = RAGFlow(API_KEY, HOST_ADDRESS)
|
||||
kb = rag.create_dataset(name="test_update_chat")
|
||||
chat = rag.create_chat("test_update", knowledgebases=[kb])
|
||||
if isinstance(chat, Chat):
|
||||
assert chat.name == "test_update", "Name does not match."
|
||||
res=chat.update({"name":"new_chat"})
|
||||
assert res is None, f"Failed to update chat, error: {res}"
|
||||
else:
|
||||
assert False, f"Failed to create chat, error: {chat}"
|
||||
|
||||
def test_delete_chats_with_success(self):
|
||||
"""
|
||||
Test deleting an chat with success
|
||||
"""
|
||||
rag = RAGFlow(API_KEY, HOST_ADDRESS)
|
||||
kb = rag.create_dataset(name="test_delete_chat")
|
||||
chat = rag.create_chat("test_delete", knowledgebases=[kb])
|
||||
if isinstance(chat, Chat):
|
||||
assert chat.name == "test_delete", "Name does not match."
|
||||
res = rag.delete_chats(ids=[chat.id])
|
||||
assert res is None, f"Failed to delete chat, error: {res}"
|
||||
else:
|
||||
assert False, f"Failed to create chat, error: {chat}"
|
||||
|
||||
def test_list_chats_with_success(self):
|
||||
"""
|
||||
Test listing chats with success
|
||||
"""
|
||||
rag = RAGFlow(API_KEY, HOST_ADDRESS)
|
||||
list_chats = rag.list_chats()
|
||||
assert len(list_chats) > 0, "Do not exist any chat"
|
||||
for chat in list_chats:
|
||||
assert isinstance(chat, Chat), "Existence type is not chat."
|
||||
@ -29,7 +29,7 @@ class TestDataset(TestSdk):
|
||||
else:
|
||||
assert False, f"Failed to create dataset, error: {ds}"
|
||||
|
||||
def test_delete_dataset_with_success(self):
|
||||
def test_delete_datasets_with_success(self):
|
||||
"""
|
||||
Test deleting a dataset with success
|
||||
"""
|
||||
@ -37,7 +37,7 @@ class TestDataset(TestSdk):
|
||||
ds = rag.create_dataset("MA")
|
||||
if isinstance(ds, DataSet):
|
||||
assert ds.name == "MA", "Name does not match."
|
||||
res = rag.delete_dataset(names=["MA"])
|
||||
res = rag.delete_datasets(ids=[ds.id])
|
||||
assert res is None, f"Failed to delete dataset, error: {res}"
|
||||
else:
|
||||
assert False, f"Failed to create dataset, error: {ds}"
|
||||
|
||||
Reference in New Issue
Block a user