Model instructions, setting the AI role, describing how the model should generally behave and respond
For example: “You are a pediatrician with 10 years of experience”
user
User input that passes end-user messages to the model
For example: “What should I do if a young child has a persistent low-grade fever?“
assistant
Historical responses generated by the model, providing the model with examples of how it should respond to the current request
For example: “It is recommended to take the temperature first…”
If you want the model to respond according to hierarchical instructions, you can use message roles to improve the quality of the output. However, the message role does not always have a deterministic performance, so it is recommended to try multiple usages, compare the effects of different methods, and find the solution that works best for you.
from openai import OpenAIclient = OpenAI(base_url="https://BASE_URL/v1",api_key="", # Replace with your API Key on this site )response = client.chat.completions.create(model="deepseek-r1",messages=[ {"role": "user","content": "say 1" } ] )print(response.choices[0].message.content)
from openai import OpenAIclient = OpenAI(base_url="https://BASE_URL/v1",api_key="", # Replace with your API Key on this site )stream = client.chat.completions.create(model="deepseek-r1",messages=[ {"role": "user","content": "Write a poem about spring" } ],stream=True )for chunk in stream:if chunk.choices[0].delta.content:print(chunk.choices[0].delta.content, end="", flush=True)
from openai import OpenAIclient = OpenAI(base_url="https://BASE_URL/v1",api_key="", # Replace with your API Key on this site )tools = [ {"type": "function","function": {"name": "get_weather","description": "Get weather information for a specified city","parameters": {"type": "object","properties": {"city": {"type": "string","description": "city name" } },"required": ["city"] } } } ]response = client.chat.completions.create(model="deepseek-r1",messages=[ {"role": "user","content": "How is the weather in Beijing today?" } ],tools=tools )print(response.choices[0].message)
import anthropicclient = anthropic.Anthropic(base_url="https://BASE_URL/anthropic",api_key="" # Replace with your API Key on this site )message = client.messages.create(model="deepseek-r1",max_tokens=1024,messages=[ {"role": "user","content": "Please explain in simple language what machine learning is" } ] )print(message.content[0].text)
import anthropicclient = anthropic.Anthropic(base_url="https://BASE_URL/anthropic",api_key="" # Replace with your API Key on this site )with client.messages.stream(model="deepseek-r1",max_tokens=1024,messages=[ {"role": "user","content": "Write a poem about spring" } ]) as stream:for text in stream.text_stream:print(text, end="", flush=True)
import anthropicclient = anthropic.Anthropic(base_url="https://BASE_URL/anthropic",api_key="" # Replace with your API Key on this site )tools = [ {"name": "get_weather","description": "Get weather information for a specified city","input_schema": {"type": "object","properties": {"city": {"type": "string","description": "city name" } },"required": ["city"] } } ]message = client.messages.create(model="deepseek-r1",max_tokens=1024,tools=tools,messages=[ {"role": "user","content": "How is the weather in Beijing today?" } ] )print(message.content)