-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from Undertone0809/feat-v1.10.0
test: optimize tests
- Loading branch information
Showing
27 changed files
with
630 additions
and
286 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from promptulate.llms import ChatOpenAI | ||
from promptulate.schema import AssistantMessage, MessageSet, SystemMessage, UserMessage | ||
|
||
|
||
def main(): | ||
messages = MessageSet( | ||
messages=[ | ||
SystemMessage(content="You are a helpful assitant"), | ||
UserMessage(content="Hello?"), | ||
] | ||
) | ||
|
||
llm = ChatOpenAI() | ||
answer: AssistantMessage = llm.predict(messages) | ||
print(answer.content) | ||
|
||
|
||
main() |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""This example will show how to use a specified key in OpenAI model.""" | ||
from promptulate.llms import ChatOpenAI | ||
|
||
|
||
def main(): | ||
llm = ChatOpenAI() | ||
llm.set_private_api_key("your key here") | ||
print(llm("hello")) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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,46 +1,46 @@ | ||
from unittest import TestCase | ||
# from unittest import TestCase | ||
|
||
from promptulate.frameworks.conversation import Conversation | ||
from promptulate.memory import FileChatMemory | ||
from promptulate.utils.logger import enable_log, get_logger | ||
# from promptulate.frameworks.conversation import Conversation | ||
# from promptulate.memory import FileChatMemory | ||
# from promptulate.utils.logger import enable_log, get_logger | ||
|
||
enable_log() | ||
logger = get_logger() | ||
# enable_log() | ||
# logger = get_logger() | ||
|
||
|
||
class TestConversation(TestCase): | ||
def test_predict(self): | ||
conversation = Conversation() | ||
result = conversation.run("什么是大语言模型") | ||
self.assertIsNotNone(result) | ||
self.assertTrue("大语言模型" in result) | ||
# class TestConversation(TestCase): | ||
# def test_predict(self): | ||
# conversation = Conversation() | ||
# result = conversation.run("什么是大语言模型") | ||
# self.assertIsNotNone(result) | ||
# self.assertTrue("大语言模型" in result) | ||
|
||
def test_predict_with_stop(self): | ||
conversation = Conversation() | ||
prompt = """ | ||
Please strictly output the following content. | ||
``` | ||
[start] This is a test [end] | ||
``` | ||
""" | ||
result = conversation.run(prompt, stop=["test"]) | ||
self.assertTrue("test [end]" not in result) | ||
self.assertIsNotNone(result) | ||
# def test_predict_with_stop(self): | ||
# conversation = Conversation() | ||
# prompt = """ | ||
# Please strictly output the following content. | ||
# ``` | ||
# [start] This is a test [end] | ||
# ``` | ||
# """ | ||
# result = conversation.run(prompt, stop=["test"]) | ||
# self.assertTrue("test [end]" not in result) | ||
# self.assertIsNotNone(result) | ||
|
||
def test_memory_with_buffer(self): | ||
conversation = Conversation() | ||
prompt = """给我想5个公司的名字""" | ||
conversation.run(prompt) | ||
conversation_id = conversation.conversation_id | ||
new_conversation = Conversation(conversation_id=conversation_id) | ||
new_conversation.predict("再给我五个") | ||
# def test_memory_with_buffer(self): | ||
# conversation = Conversation() | ||
# prompt = """give me 5 company names""" | ||
# conversation.run(prompt) | ||
# conversation_id = conversation.conversation_id | ||
# new_conversation = Conversation(conversation_id=conversation_id) | ||
# new_conversation.predict("give me 5 more") | ||
|
||
def test_memory_with_file(self): | ||
conversation = Conversation(memory=FileChatMemory()) | ||
prompt = """给我想5个公司的名字""" | ||
conversation.run(prompt) | ||
conversation_id = conversation.conversation_id | ||
new_conversation = Conversation( | ||
conversation_id=conversation_id, memory=FileChatMemory() | ||
) | ||
new_conversation.predict("再给我五个") | ||
# def test_memory_with_file(self): | ||
# conversation = Conversation(memory=FileChatMemory()) | ||
# prompt = """give me 5 company names""" | ||
# conversation.run(prompt) | ||
# conversation_id = conversation.conversation_id | ||
# new_conversation = Conversation( | ||
# conversation_id=conversation_id, memory=FileChatMemory() | ||
# ) | ||
# new_conversation.predict("give me 5 more") |
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
Oops, something went wrong.