mirror of
https://github.com/deepseek-ai/DeepSeek-R1.git
synced 2025-02-23 06:09:00 -05:00
Fixes #21 Add support for successive user or assistant messages in `deepseek-reasoner`. * **deepseek_reasoner.py**: - Modify the message handling logic to allow successive messages of the same role. - Add a check to merge successive messages of the same role into a single message. - Update the `process_messages` function to handle the new message format. * **README.md**: - Add a section explaining the new message handling capability. - Provide examples of how to format messages with successive user or assistant messages. * **test_deepseek_reasoner.py**: - Add tests to ensure the model correctly processes successive user or assistant messages. - Include test cases for both interleaved and successive messages. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/deepseek-ai/DeepSeek-R1/issues/21?shareId=XXXX-XXXX-XXXX-XXXX).
47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
import unittest
|
|
from deepseek_reasoner import DeepSeekReasoner
|
|
|
|
class TestDeepSeekReasoner(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
self.reasoner = DeepSeekReasoner()
|
|
|
|
def test_interleaved_messages(self):
|
|
request = {
|
|
"messages": [
|
|
{"role": "user", "content": "Hello!"},
|
|
{"role": "assistant", "content": "Hi! How can I help?"},
|
|
{"role": "user", "content": "Tell me about DeepSeek R1."}
|
|
]
|
|
}
|
|
response = self.reasoner.handle_request(request)
|
|
self.assertEqual(response["status"], "success")
|
|
self.assertEqual(len(response["processed_messages"]), 3)
|
|
|
|
def test_successive_user_messages(self):
|
|
request = {
|
|
"messages": [
|
|
{"role": "user", "content": "Hello!"},
|
|
{"role": "user", "content": "Tell me about DeepSeek R1."}
|
|
]
|
|
}
|
|
response = self.reasoner.handle_request(request)
|
|
self.assertEqual(response["status"], "success")
|
|
self.assertEqual(len(response["processed_messages"]), 1)
|
|
self.assertEqual(response["processed_messages"][0]["content"], "Hello! Tell me about DeepSeek R1.")
|
|
|
|
def test_successive_assistant_messages(self):
|
|
request = {
|
|
"messages": [
|
|
{"role": "assistant", "content": "Hello!"},
|
|
{"role": "assistant", "content": "How can I assist you today?"}
|
|
]
|
|
}
|
|
response = self.reasoner.handle_request(request)
|
|
self.assertEqual(response["status"], "success")
|
|
self.assertEqual(len(response["processed_messages"]), 1)
|
|
self.assertEqual(response["processed_messages"][0]["content"], "Hello! How can I assist you today?")
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|