mirror of https://github.com/InternLM/InternLM
parent
3ebe24d92c
commit
d163169143
|
@ -0,0 +1,109 @@
|
|||
# Chat Format
|
||||
|
||||
English | [简体中文](chat_format_zh-CN.md)
|
||||
|
||||
InternLM2-Chat adopts a new chat format to flexibly support a wider range of applications, such as tool invocation, while avoiding user input attacks. This new format is similar to the [ChatML](https://github.com/openai/openai-python/blob/release-v0.28.0/chatml.md) format, but with an added `environment` role to support general-purpose AI applications, in addition to `system`, `user`, and `assistant`.
|
||||
|
||||
## Basic Structure
|
||||
|
||||
The regular chat structure usually contains three roles: `system`, `user`, and `assistant`, formatted as follows for multi-turn dialogues:
|
||||
|
||||
```
|
||||
[UNUSED_TOKEN_146]system
|
||||
You are InternLM2-Chat, a harmless AI assistant[UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]user
|
||||
Hello[UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]assistant
|
||||
Hello, I am InternLM2-Chat, how can I assist you?[UNUSED_TOKEN_145]
|
||||
```
|
||||
|
||||
Here, `[UNUSED_TOKEN_146]` acts as the start token for each turn of dialogue, and `[UNUSED_TOKEN_145]` as the end token. Each turn of dialogue typically starts with `[UNUSED_TOKEN_146]role` and ends with the model's output `[UNUSED_TOKEN_145]`, where role represents `system`, `user`, `assistant`, and `environment`. Currently, the InternLM2-Chat model's vocabulary also maintains the following mappings:
|
||||
|
||||
- `[UNUSED_TOKEN_146]`: Start token for each role's dialogue
|
||||
- `[UNUSED_TOKEN_145]`: End token for each role's dialogue
|
||||
- `[UNUSED_TOKEN_144]`: Start token for invoking external plugins
|
||||
- `[UNUSED_TOKEN_143]`: End token for invoking external plugins
|
||||
- `[UNUSED_TOKEN_142]`: Code interpreter
|
||||
- `[UNUSED_TOKEN_141]`: External plugins, regular tools
|
||||
|
||||
## Complete Structure
|
||||
|
||||
The complete dialogue format of InternLM2-Chat, based on the basic structure, also includes designs for general-purpose AI agents. Its core purpose is to use a streaming format that allows the same format to support various types of plugin extensions and AI environments while being compatible with general dialogue. The state of a general AI agent dialogue is shown below:
|
||||
|
||||
```
|
||||
[UNUSED_TOKEN_146]system
|
||||
You are InternLM2-Chat, a harmless AI assistant[UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]system name=[UNUSED_TOKEN_142]
|
||||
You now have access to a Jupyter notebook environment supporting Python code execution. Just send code to python to run in this stateful environment. This feature is suitable for:
|
||||
- Data analysis or processing (such as data manipulation and graphic creation)
|
||||
- Complex calculations (such as math and physics problems)
|
||||
- Programming examples (for understanding programming concepts or language features)
|
||||
- Text processing and analysis (including text analysis and natural language processing)
|
||||
- Machine learning and data science (model training and data visualization)
|
||||
- File operations and data import (handling CSV, JSON, etc. formats)
|
||||
[UNUSED_TOKEN_146]system name=[UNUSED_TOKEN_141]
|
||||
[
|
||||
{
|
||||
"name": "get_current_weather",
|
||||
"description": "Get the current weather in a given location",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"location": {
|
||||
"type": "string",
|
||||
"description": "The city and state, e.g. San Francisco, CA",
|
||||
},
|
||||
"unit": {"type": "string"},
|
||||
},
|
||||
"required": ["location"],
|
||||
},
|
||||
}
|
||||
]
|
||||
[UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]user
|
||||
Please help me process and visualize this dataset.
|
||||
[UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]user name=file
|
||||
[{"path": "data.csv", size='10K'}][UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]assistant
|
||||
I have processed the data and visualized it for you.
|
||||
|
||||
[UNUSED_TOKEN_144][UNUSED_TOKEN_142]
|
||||
```python
|
||||
import plotly.express as px
|
||||
import pandas as pd
|
||||
|
||||
# Load the data into a pandas dataframe
|
||||
df = pd.read_csv('data.csv')
|
||||
|
||||
# Create a scatter plot of rainfall vs wind direction
|
||||
fig = px.scatter(df, x='WindDir9am', y='Rainfall', color='WindDir3pm',
|
||||
labels={'WindDir9am': 'Wind Direction 9am', 'Rainfall': '
|
||||
|
||||
Rainfall', 'WindDir3pm': 'Wind Direction 3pm'},
|
||||
title='Rainfall vs Wind Direction',
|
||||
template='plotly_dark',
|
||||
width=600, height=500)
|
||||
|
||||
# Add a hover effect to show the date
|
||||
fig.update_traces(hovertemplate='<b>Date: %{text}</b><br>Wind Direction 9am: %{x}<br>Rainfall: %{y}<br>Wind Direction 3pm: %{marker.color}')
|
||||
|
||||
# Show the plot
|
||||
fig.show()
|
||||
```[UNUSED_TOKEN_143]
|
||||
[UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]environment name=[UNUSED_TOKEN_142]
|
||||
![image](xxx.png)
|
||||
[UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]assistant
|
||||
Since the code output is not included here, I cannot provide specific chart content. However, if the code executed correctly, it should display a polar plot with two filled areas representing the relationship between wind direction at 9 am and rainfall, and between wind direction at 3 pm and rainfall, respectively. The values for each direction are based on the average rainfall calculated from the provided dataset. The chart should have a clear title, a legend, and be intuitive for comparing rainfall with different wind directions. Given the use of a dark theme, the overall appearance of the chart should be bright lines and filled areas on a dark background.[UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]user
|
||||
Can you explain the code?[UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]assistant
|
||||
The code uses Python's Plotly library to create a polar plot that shows the relationship between wind direction and rainfall. It starts by creating a Plotly Figure object. Then, I added two `Scatterpolar` traces. The first trace shows the relationship between wind direction at 9 am and average rainfall, and the second trace shows the same for 3 pm. In these traces, the `r` parameter represents the average rainfall, and `theta` represents the wind direction. `fill='toself'` means the shape is filled to its own boundary. Next, I updated the chart layout, hid the radial axis, added a legend, set the title and its font, chose a dark theme, and set the chart's background color, width, and height. Finally, the chart was displayed using `fig.show()`.
|
||||
[UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]user
|
||||
I want to know today's weather in Shanghai[UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_144][UNUSED_TOKEN_141]
|
||||
{"name": "get_current_weather", "parameters": {"location": "Shanghai"}}[UNUSED_TOKEN_143]
|
||||
```
|
|
@ -33,6 +33,14 @@ InternLM2-Chat 的完整对话格式在上述基本结构的基础上还包含
|
|||
```
|
||||
[UNUSED_TOKEN_146]system
|
||||
你是书生浦语2,一个无害的人工智能助手[UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]system name=[UNUSED_TOKEN_142]
|
||||
你现在可以使用一个支持 Python 代码执行的 Jupyter 笔记本环境。只需向 python 发送代码,即可在这个有状态环境中进行运行。这个功能适用于:
|
||||
- 数据分析或处理(如数据操作和图形制作)
|
||||
- 复杂计算(如数学和物理问题)
|
||||
- 编程示例(用于理解编程概念或语言特性)
|
||||
- 文本处理和分析(包括文本分析和自然语言处理)
|
||||
- 机器学习和数据科学(模型训练和数据可视化展示)
|
||||
- 文件操作和数据导入(处理CSV、JSON等格式文件)
|
||||
[UNUSED_TOKEN_146]system name=[UNUSED_TOKEN_141]
|
||||
[
|
||||
{
|
||||
|
@ -56,7 +64,7 @@ InternLM2-Chat 的完整对话格式在上述基本结构的基础上还包含
|
|||
请帮我对该数据集进行数据处理并可视化。
|
||||
[UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]user name=file
|
||||
{"path": "data.csv"}[UNUSED_TOKEN_145]
|
||||
[{"path": "data.csv", size='10K'}][UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]assistant
|
||||
我已经帮您处理了数据并进行了可视化。
|
||||
|
||||
|
@ -83,6 +91,7 @@ fig.show()
|
|||
```[UNUSED_TOKEN_143]
|
||||
[UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]environment name=[UNUSED_TOKEN_142]
|
||||
![image](xxx.png)
|
||||
[UNUSED_TOKEN_145]
|
||||
[UNUSED_TOKEN_146]assistant
|
||||
由于代码输出没有包含在这里,我无法提供具体的图表内容。但是,如果代码执行无误,它会显示一个极坐标图,其中包含两个填充区域,一个代表上午9点的风向与降雨量的关系,另一个代表下午3点的风向与降雨量的关系。每个方向上的值是根据提供的数据集计算得到的平均降雨量。图表应该有一个清晰的标题、图例,并且能够直观地比较不同风向下的降雨量。由于使用了暗色主题,图表的整体外观应该是深色背景上的亮色线条和填充区域。[UNUSED_TOKEN_145]
|
||||
|
|
Loading…
Reference in New Issue