mirror of
https://github.com/deepseek-ai/DeepSeek-R1.git
synced 2025-04-19 10:09:02 -04:00
Merge 4372071fc5
into ed4409d2a9
This commit is contained in:
commit
f37eb6b412
38
README.md
38
README.md
@ -207,14 +207,46 @@ python3 -m sglang.launch_server --model deepseek-ai/DeepSeek-R1-Distill-Qwen-32B
|
||||
3. For mathematical problems, it is advisable to include a directive in your prompt such as: "Please reason step by step, and put your final answer within \boxed{}."
|
||||
4. When evaluating model performance, it is recommended to conduct multiple tests and average the results.
|
||||
|
||||
## 7. License
|
||||
## 7. Message Handling Capability
|
||||
|
||||
DeepSeek-R1 now supports successive user or assistant messages without causing an `invalid_request_error`. The message handling logic has been modified to allow successive messages of the same role. Here are some examples of how to format messages with successive user or assistant messages:
|
||||
|
||||
### Example 1: Interleaved Messages
|
||||
|
||||
```json
|
||||
[
|
||||
{"role": "user", "content": "Hello!"},
|
||||
{"role": "assistant", "content": "Hi! How can I help?"},
|
||||
{"role": "user", "content": "Tell me about DeepSeek R1."}
|
||||
]
|
||||
```
|
||||
|
||||
### Example 2: Successive User Messages
|
||||
|
||||
```json
|
||||
[
|
||||
{"role": "user", "content": "Hello!"},
|
||||
{"role": "user", "content": "Tell me about DeepSeek R1."}
|
||||
]
|
||||
```
|
||||
|
||||
### Example 3: Successive Assistant Messages
|
||||
|
||||
```json
|
||||
[
|
||||
{"role": "assistant", "content": "Hello!"},
|
||||
{"role": "assistant", "content": "How can I assist you today?"}
|
||||
]
|
||||
```
|
||||
|
||||
## 8. License
|
||||
This code repository and the model weights are licensed under the [MIT License](https://github.com/deepseek-ai/DeepSeek-R1/blob/main/LICENSE).
|
||||
DeepSeek-R1 series support commercial use, allow for any modifications and derivative works, including, but not limited to, distillation for training other LLMs. Please note that:
|
||||
- DeepSeek-R1-Distill-Qwen-1.5B, DeepSeek-R1-Distill-Qwen-7B, DeepSeek-R1-Distill-Qwen-14B and DeepSeek-R1-Distill-Qwen-32B are derived from [Qwen-2.5 series](https://github.com/QwenLM/Qwen2.5), which are originally licensed under [Apache 2.0 License](https://huggingface.co/Qwen/Qwen2.5-1.5B/blob/main/LICENSE), and now finetuned with 800k samples curated with DeepSeek-R1.
|
||||
- DeepSeek-R1-Distill-Llama-8B is derived from Llama3.1-8B-Base and is originally licensed under [llama3.1 license](https://huggingface.co/meta-llama/Llama-3.1-8B/blob/main/LICENSE).
|
||||
- DeepSeek-R1-Distill-Llama-70B is derived from Llama3.3-70B-Instruct and is originally licensed under [llama3.3 license](https://huggingface.co/meta-llama/Llama-3.3-70B-Instruct/blob/main/LICENSE).
|
||||
|
||||
## 8. Citation
|
||||
## 9. Citation
|
||||
```
|
||||
@misc{deepseekai2025deepseekr1incentivizingreasoningcapability,
|
||||
title={DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning},
|
||||
@ -228,5 +260,5 @@ DeepSeek-R1 series support commercial use, allow for any modifications and deriv
|
||||
|
||||
```
|
||||
|
||||
## 9. Contact
|
||||
## 10. Contact
|
||||
If you have any questions, please raise an issue or contact us at [service@deepseek.com](service@deepseek.com).
|
||||
|
46
deepseek_reasoner.py
Normal file
46
deepseek_reasoner.py
Normal file
@ -0,0 +1,46 @@
|
||||
import json
|
||||
|
||||
class DeepSeekReasoner:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def process_messages(self, messages):
|
||||
"""
|
||||
Process the input messages to ensure they follow the required format.
|
||||
"""
|
||||
if not messages:
|
||||
raise ValueError("Messages cannot be empty")
|
||||
|
||||
# Merge successive messages of the same role
|
||||
merged_messages = []
|
||||
for message in messages:
|
||||
if merged_messages and merged_messages[-1]['role'] == message['role']:
|
||||
merged_messages[-1]['content'] += " " + message['content']
|
||||
else:
|
||||
merged_messages.append(message)
|
||||
|
||||
return merged_messages
|
||||
|
||||
def handle_request(self, request):
|
||||
"""
|
||||
Handle the incoming request and process the messages.
|
||||
"""
|
||||
try:
|
||||
messages = request.get('messages', [])
|
||||
processed_messages = self.process_messages(messages)
|
||||
return {"status": "success", "processed_messages": processed_messages}
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
||||
# Example usage
|
||||
if __name__ == "__main__":
|
||||
reasoner = DeepSeekReasoner()
|
||||
request = {
|
||||
"messages": [
|
||||
{"role": "user", "content": "Hello!"},
|
||||
{"role": "user", "content": "Tell me about DeepSeek R1."},
|
||||
{"role": "assistant", "content": "DeepSeek R1 is a reasoning model."}
|
||||
]
|
||||
}
|
||||
response = reasoner.handle_request(request)
|
||||
print(json.dumps(response, indent=2))
|
46
test_deepseek_reasoner.py
Normal file
46
test_deepseek_reasoner.py
Normal file
@ -0,0 +1,46 @@
|
||||
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()
|
Loading…
Reference in New Issue
Block a user