-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
249 additions
and
70 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
xtuner/configs/internlm/internlm2_chat_1_8b/hybrid/agent.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"messages": [ | ||
{"role": "system", "content": "You are InternLM2-Chat, a harmless AI assistant"}, | ||
{ | ||
"role": "user", | ||
"content": "Please help me process and visualize this dataset.", | ||
"files": [{"path": "data.csv", "size": "10K"}] | ||
}, | ||
{ | ||
"role": "assistant", | ||
"content": "I have processed the data and visualized it for you.", | ||
"code_interpreter_call": "```python\nimport plotly.express as px\nimport pandas as pd\n\n# Load the data into a pandas dataframe\ndf = pd.read_csv('data.csv')\n\n# Create a scatter plot of rainfall vs wind direction\nfig = px.scatter(df, x='WindDir9am', y='Rainfall', color='WindDir3pm',\n labels={'WindDir9am': 'Wind Direction 9am', 'Rainfall': '\n\nRainfall', 'WindDir3pm': 'Wind Direction 3pm'},\n title='Rainfall vs Wind Direction',\n template='plotly_dark',\n width=600, height=500)\n\n# Add a hover effect to show the date\nfig.update_traces(hovertemplate='<b>Date: %{text}</b><br>Wind Direction 9am: %{x}<br>Rainfall: %{y}<br>Wind Direction 3pm: %{marker.color}')\n\n# Show the plot\nfig.show()\n```" | ||
}, | ||
{ | ||
"role": "code_interpreter", | ||
"content": "![image](xxx.png)" | ||
}, | ||
{ | ||
"role": "assistant", | ||
"content": "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." | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "I want to know today's weather in Shanghai" | ||
}, | ||
{ | ||
"role": "assistant", | ||
"content": "Sure, I will search for the weather of Shanghai.", | ||
"function_call": { | ||
"name": "get_current_weather", | ||
"parameters": {"location": "Shanghai"} | ||
} | ||
}, | ||
{ | ||
"role": "function", | ||
"name": "get_current_weather", | ||
"content": "{'temperature': 22}" | ||
}, | ||
{ | ||
"role": "assistant", | ||
"content": "The weather in Shanghai is 22 celsius" | ||
} | ||
], | ||
|
||
"functions": [ | ||
{ | ||
"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"] | ||
} | ||
} | ||
} | ||
], | ||
|
||
"code_interpreter": "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:\n- Data analysis or processing (such as data manipulation and graphic creation)\n- Complex calculations (such as math and physics problems)\n- Programming examples (for understanding programming concepts or language features)\n- Text processing and analysis (including text analysis and natural language processing)\n- Machine learning and data science (model training and data visualization)\n- File operations and data import (handling CSV, JSON, etc. formats)"} |
29 changes: 29 additions & 0 deletions
29
xtuner/configs/internlm/internlm2_chat_1_8b/hybrid/example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import json | ||
|
||
from xtuner.types import HybridChatTemplate, TrainingHybridChatMessages | ||
|
||
|
||
chat_template = HybridChatTemplate( | ||
system='<|im_start|>system\n{system}<|im_end|>\n', | ||
user='<|im_start|>user\n{user}<|im_end|>\n<|im_start|>assistant\n', | ||
assistant='{assistant}<|im_end|>\n', | ||
stop_words=['<|im_end|>'], | ||
image_token='<image>', | ||
files='<|im_start|>user name=file\n{files}<|im_end|>\n', | ||
function_call='{assistant}<|action_start|><|plugin|>\n{function_call}<|action_end|><|im_end|>\n', # noqa: E501, E251 | ||
function_result='<|im_start|>environment name=<|plugin|>\n{function_result}<|im_end|>\n<|im_start|>assistant\n', # noqa: E501, E251 | ||
functions='<|im_start|>system name=<|plugin|>\n{functions}<|im_end|>\n', | ||
code_interpreter_call='{assistant}<|action_start|><|interpreter|>\n{code_interpreter_call}<|action_end|><|im_end|>\n', # noqa: E501, E251 | ||
code_interpreter_result='<|im_start|>environment name=<|interpreter|>\n{code_interpreter_result}<|im_end|>\n<|im_start|>assistant\n', # noqa: E501, E251 | ||
code_interpreter='<|im_start|>system name=<|interpreter|>\n{code_interpreter}<|im_end|>\n' | ||
|
||
) | ||
|
||
agent_data = json.load(open('agent.json')) | ||
|
||
msg = TrainingHybridChatMessages.from_dict(agent_data) | ||
print(msg.apply_chat_template(chat_template)) | ||
|
||
from transformers import AutoTokenizer | ||
tokenizer = AutoTokenizer.from_pretrained('internlm/internlm2-chat-7b', trust_remote_code=True) | ||
print(msg.tokenize(tokenizer, chat_template)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.