-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72a4cbf
commit bcc4cd1
Showing
2 changed files
with
43 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,53 @@ | ||
import unittest | ||
from agi.llms.model_factory import ModelFactory | ||
from agi.llms.base import build_multi_modal_message,ImageType,AudioType | ||
from langchain_core.messages import AIMessage, HumanMessage | ||
|
||
|
||
class TestModelFactory(unittest.TestCase): | ||
|
||
def test_get_model(self): | ||
ollama_model = ModelFactory.get_model("ollama") | ||
resp = ollama_model.invoke("介绍下美国") | ||
print(type(resp)) | ||
self.assertIsNotNone(resp.content) | ||
self.assertEqual(len(ModelFactory._instances),1) | ||
ModelFactory.destroy("ollama") | ||
self.assertEqual(len(ModelFactory._instances),0) | ||
|
||
instance = ModelFactory.get_model("text2image") | ||
input = HumanMessage(content="a chinese leader") | ||
resp = instance.invoke(input) | ||
self.assertIsNotNone(resp.content) | ||
self.assertEqual(len(ModelFactory._instances),1) | ||
ModelFactory.destroy("text2image") | ||
self.assertEqual(len(ModelFactory._instances),0) | ||
|
||
instance = ModelFactory.get_model("image2image") | ||
input = build_multi_modal_message("as a cat woman","tests/cat.jpg",ImageType.FILE_PATH) | ||
resp = instance.invoke(input) | ||
self.assertIsNotNone(resp.content) | ||
self.assertEqual(len(ModelFactory._instances),1) | ||
ModelFactory.destroy("image2image") | ||
self.assertEqual(len(ModelFactory._instances),0) | ||
|
||
instance = ModelFactory.get_model("speech2text") | ||
input = self.input = build_multi_modal_message("","tests/1730604079.wav",AudioType.FILE_PATH) | ||
resp = instance.invoke(input) | ||
self.assertIsNotNone(resp.content) | ||
print(resp.content) | ||
self.assertEqual(len(ModelFactory._instances),1) | ||
ModelFactory.destroy("speech2text") | ||
self.assertEqual(len(ModelFactory._instances),0) | ||
|
||
instance = ModelFactory.get_model("text2speech") | ||
input = HumanMessage(content="岁的思考的加快速度为空军党委科技") | ||
resp = instance.invoke(input) | ||
self.assertIsNotNone(resp.content) | ||
print(resp.content) | ||
self.assertEqual(len(ModelFactory._instances),1) | ||
ModelFactory.destroy("text2speech") | ||
self.assertEqual(len(ModelFactory._instances),0) | ||
|
||
# def test_release_model(self): | ||
# self.assertIsNotNone(output) | ||
# self.assertIsNotNone(output.image) | ||
# self.assertIsNotNone(output.image.pil_image) | ||
# self.assertIsNotNone(output.content) | ||
# print(output.content) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |