Views
No views yet


Note: Underline means the best performance among open-sourced models, Bold indicates the best performance among all models.
1top_p = 0.95
2top_k = 50
3min_p = 0.0
4temperature = 0.81
2
3from openai import OpenAI
4import json
5
6
7def get_current_temperature(location: str, unit: str = "celsius"):
8 """Get current temperature at a location.
9
10 Args:
11 location: The location to get the temperature for, in the format "City, State, Country".
12 unit: The unit to return the temperature in. Defaults to "celsius". (choices: ["celsius", "fahrenheit"])
13
14 Returns:
15 the temperature, the location, and the unit in a dict
16 """
17 return {
18 "temperature": 26.1,
19 "location": location,
20 "unit": unit,
21 }
22
23
24def get_temperature_date(location: str, date: str, unit: str = "celsius"):
25 """Get temperature at a location and date.
26
27 Args:
28 location: The location to get the temperature for, in the format "City, State, Country".
29 date: The date to get the temperature for, in the format "Year-Month-Day".
30 unit: The unit to return the temperature in. Defaults to "celsius". (choices: ["celsius", "fahrenheit"])
31
32 Returns:
33 the temperature, the location, the date and the unit in a dict
34 """
35 return {
36 "temperature": 25.9,
37 "location": location,
38 "date": date,
39 "unit": unit,
40 }
41
42def get_function_by_name(name):
43 if name == "get_current_temperature":
44 return get_current_temperature
45 if name == "get_temperature_date":
46 return get_temperature_date
47
48tools = [{
49 'type': 'function',
50 'function': {
51 'name': 'get_current_temperature',
52 'description': 'Get current temperature at a location.',
53 'parameters': {
54 'type': 'object',
55 'properties': {
56 'location': {
57 'type': 'string',
58 'description': 'The location to get the temperature for, in the format \'City, State, Country\'.'
59 },
60 'unit': {
61 'type': 'string',
62 'enum': [
63 'celsius',
64 'fahrenheit'
65 ],
66 'description': 'The unit to return the temperature in. Defaults to \'celsius\'.'
67 }
68 },
69 'required': [
70 'location'
71 ]
72 }
73 }
74}, {
75 'type': 'function',
76 'function': {
77 'name': 'get_temperature_date',
78 'description': 'Get temperature at a location and date.',
79 'parameters': {
80 'type': 'object',
81 'properties': {
82 'location': {
83 'type': 'string',
84 'description': 'The location to get the temperature for, in the format \'City, State, Country\'.'
85 },
86 'date': {
87 'type': 'string',
88 'description': 'The date to get the temperature for, in the format \'Year-Month-Day\'.'
89 },
90 'unit': {
91 'type': 'string',
92 'enum': [
93 'celsius',
94 'fahrenheit'
95 ],
96 'description': 'The unit to return the temperature in. Defaults to \'celsius\'.'
97 }
98 },
99 'required': [
100 'location',
101 'date'
102 ]
103 }
104 }
105}]
106
107
108
109messages = [
110 {'role': 'user', 'content': 'Today is 2024-11-14, What\'s the temperature in San Francisco now? How about tomorrow?'}
111]
112
113openai_api_key = "EMPTY"
114openai_api_base = "http://0.0.0.0:23333/v1"
115client = OpenAI(
116 api_key=openai_api_key,
117 base_url=openai_api_base,
118)
119model_name = client.models.list().data[0].id
120response = client.chat.completions.create(
121 model=model_name,
122 messages=messages,
123 max_tokens=32768,
124 temperature=0.8,
125 top_p=0.95,
126 extra_body=dict(spaces_between_special_tokens=False),
127 tools=tools)
128print(response.choices[0].message)
129messages.append(response.choices[0].message)
130
131for tool_call in response.choices[0].message.tool_calls:
132 tool_call_args = json.loads(tool_call.function.arguments)
133 tool_call_result = get_function_by_name(tool_call.function.name)(**tool_call_args)
134 tool_call_result = json.dumps(tool_call_result, ensure_ascii=False)
135 messages.append({
136 'role': 'tool',
137 'name': tool_call.function.name,
138 'content': tool_call_result,
139 'tool_call_id': tool_call.id
140 })
141
142response = client.chat.completions.create(
143 model=model_name,
144 messages=messages,
145 temperature=0.8,
146 top_p=0.95,
147 extra_body=dict(spaces_between_special_tokens=False),
148 tools=tools)
149print(response.choices[0].message)enable_thinking=False in tokenizer.apply_chat_template1text = tokenizer.apply_chat_template(
2 messages,
3 tokenize=False,
4 add_generation_prompt=True,
5 enable_thinking=False # think mode indicator
6)enable_thinking parameter in your requests.1from openai import OpenAI
2import json
3
4messages = [
5{
6 'role': 'user',
7 'content': 'who are you'
8}, {
9 'role': 'assistant',
10 'content': 'I am an AI'
11}, {
12 'role': 'user',
13 'content': 'AGI is?'
14}]
15
16openai_api_key = "EMPTY"
17openai_api_base = "http://0.0.0.0:23333/v1"
18client = OpenAI(
19 api_key=openai_api_key,
20 base_url=openai_api_base,
21)
22model_name = client.models.list().data[0].id
23
24response = client.chat.completions.create(
25 model=model_name,
26 messages=messages,
27 temperature=0.8,
28 top_p=0.95,
29 max_tokens=2048,
30 extra_body={
31 "chat_template_kwargs": {"enable_thinking": False}
32 }
33)
34print(json.dumps(response.model_dump(), indent=2, ensure_ascii=False))Note: We do not recommend disabling thinking mode for agentic tasks.
from openai import OpenAI
from lmdeploy.vl.utils import encode_time_series_base64
openai_api_key = "EMPTY"
openai_api_base = "http://0.0.0.0:8000/v1"
client = OpenAI(
api_key=openai_api_key,
base_url=openai_api_base,
)
model_name = client.models.list().data[0].id
def send_base64(file_path: str, sampling_rate: int = 100):
"""base64-encoded time-series data."""
# encode_time_series_base64 accepts local file paths and http urls,
# encoding time-series data (.npy, .csv, .wav, .mp3, .flac, etc.) into base64 strings.
base64_ts = encode_time_series_base64(file_path)
messages = [
{
"role": "user",
"content": [
{
"type": "time_series_url",
"time_series_url": {
"url": f"data:time_series/npy;base64,{base64_ts}",
"sampling_rate": sampling_rate
},
},
{
"type": "text",
"text": "Please determine whether an Earthquake event has occurred in the provided time-series data. If so, please specify the starting time point indices of the P-wave and S-wave in the event."
},
],
}
]
return client.chat.completions.create(
model=model_name,
messages=messages,
temperature=0,
max_tokens=200,
extra_body={
"chat_template_kwargs": {"enable_thinking": False}
}
)
def send_http_url(url: str, sampling_rate: int = 100):
"""http(s) url pointing to the time-series data."""
messages = [
{
"role": "user",
"content": [
{
"type": "time_series_url",
"time_series_url": {
"url": url,
"sampling_rate": sampling_rate
},
},
{
"type": "text",
"text": "Please determine whether an Earthquake event has occurred in the provided time-series data. If so, please specify the starting time point indices of the P-wave and S-wave in the event."
},
],
}
]
return client.chat.completions.create(
model=model_name,
messages=messages,
temperature=0,
max_tokens=200,
extra_body={
"chat_template_kwargs": {"enable_thinking": False}
}
)
def send_file_url(file_path: str, sampling_rate: int = 100):
"""file url pointing to the time-series data."""
messages = [
{
"role": "user",
"content": [
{
"type": "time_series_url",
"time_series_url": {
"url": f"file://{file_path}",
"sampling_rate": sampling_rate
},
},
{
"type": "text",
"text": "Please determine whether an Earthquake event has occurred in the provided time-series data. If so, please specify the starting time point indices of the P-wave and S-wave in the event."
},
],
}
]
return client.chat.completions.create(
model=model_name,
messages=messages,
temperature=0,
max_tokens=200,
extra_body={
"chat_template_kwargs": {"enable_thinking": False}
}
)
response = send_base64("./0092638_seism.npy")
# response = send_http_url("https://huggingface.co/internlm/Intern-S1-Pro/raw/main/0092638_seism.npy")
# response = send_file_url("./0092638_seism.npy")
print(response.choices[0].message)
forecast_horizon is optional. Set it to an integer to produce a forecast of exactly that length, or set it to None to let the model infer the horizon from the text prompt.def forecast_base64(file_path: str, forecast_horizon: int | None = None):
base64_ts = encode_time_series_base64(file_path)
messages = [
{
"role": "user",
"content": [
{
"type": "text",
"text": (
"Please complete a electric load forecasting task. "
"This dataset is based on historical electricity load data every half hour within 24 hours of the region, "
"as well as data on minimum temperature, maximum temperature, humidity, air pressure, etc., "
"to predict future load consumption every half hour within 24 hours. Here is the weather information for city TAS: "
"Historical date weather: minimum temperature of 279.71K, maximum temperature of 285.83K, humidity of 85.0%, "
"air pressure of 1003.0hPa. Forecast date weather: minimum temperature 280.54K, maximum temperature 286.47K, "
"humidity 74.0%, air pressure 1007.0hPa. This data has no relevant effect information. "
"Please predict the next 48 time points given information above."
),
},
{
"type": "time_series_url",
"time_series_url": {
"url": f"data:time_series/npy;base64,{base64_ts}",
},
},
],
}
]
return client.chat.completions.create(
model=model_name,
messages=messages,
temperature=0,
max_tokens=16,
extra_body={
"chat_template_kwargs": {"enable_thinking": False},
"enable_forecasting": True,
"forecast_horizon": forecast_horizon,
},
)
response = forecast_base64("./load_20210803_0.npy", forecast_horizon=None)
forecast = response.choices[0].message.ts_forecast
print("Point forecast:", forecast.point_forecast)
print("Quantile forecast:", forecast.quantile_forecast)http://0.0.0.0:23333.http://0.0.0.0:23333/v1.1curl http://0.0.0.0:23333/v1/chat/completions \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer EMPTY" \
4 -d '{
5 "model": "internlm/Intern-S2-Preview-397B",
6 "messages": [
7 {"role": "user", "content": "Hello"}
8 ],
9 "temperature": 0.8,
10 "top_p": 0.95
11 }'1export OPENAI_API_KEY=EMPTY
2export OPENAI_BASE_URL=http://0.0.0.0:23333/v1
3export OPENAI_MODEL=internlm/Intern-S2-Preview-397B--tool-call-parser interns2-preview so tool calls are parsed correctly./v1/messages endpoint that Claude Code can talk to directly. Add the following to ~/.claude/settings.json:1{
2 "env": {
3 "ANTHROPIC_BASE_URL": "http://127.0.0.1:23333",
4 "ANTHROPIC_AUTH_TOKEN": "dummy",
5 "ANTHROPIC_MODEL": "internlm/Intern-S2-Preview-397B",
6 "ANTHROPIC_CUSTOM_MODEL_OPTION": "internlm/Intern-S2-Preview-397B"
7 }
8}sk-xxxxxxxx).https://chat.intern-ai.org.cn/api/v1 and the model name to intern-s2-preview-397b in the cli or config file.1curl https://chat.intern-ai.org.cn/api/v1/chat/completions \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer sk-xxxxxxxx" \
4 -d '{
5 "model": "intern-s2-preview-397b",
6 "messages": [
7 {"role": "user", "content": "Hello"}
8 ],
9 "temperature": 0.8,
10 "top_p": 0.95
11 }'ANTHROPIC_BASE_URL at the Intern Anthropic-compatible gateway:1{
2 "env": {
3 "ANTHROPIC_BASE_URL": "https://chat.intern-ai.org.cn",
4 "ANTHROPIC_AUTH_TOKEN": "your-api-token",
5 "ANTHROPIC_MODEL": "intern-s2-preview-397b",
6 "ANTHROPIC_SMALL_FAST_MODEL": "intern-s2-preview-397b"
7 }
8}claude --model intern-s2-preview-397b