Skip to content

Commit

Permalink
update default prompt (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
liujiangning30 authored Jan 31, 2024
1 parent d61dc03 commit 94959c1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
4 changes: 2 additions & 2 deletions examples/internlm2_agent_cli_demo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from argparse import ArgumentParser

from lagent.actions import ActionExecutor, ArxivSearch, IPythonInterpreter
from lagent.agents.internlm2_agent import INTERPRETER_CN, META_INS, PLUGIN_CN, Internlm2Agent, Internlm2Protocol
from lagent.agents.internlm2_agent import INTERPRETER_CN, META_CN, PLUGIN_CN, Internlm2Agent, Internlm2Protocol
from lagent.llms import HFTransformer
from lagent.llms.meta_template import INTERNLM2_META as META
from lagent.schema import AgentStatusCode
Expand Down Expand Up @@ -37,7 +37,7 @@ def main():
plugin_executor=None,
interpreter_executor=interpreter_executor,
protocol=Internlm2Protocol(
meta_prompt=META_INS,
meta_prompt=META_CN,
interpreter_prompt=INTERPRETER_CN,
plugin_prompt=PLUGIN_CN,
tool=dict(
Expand Down
4 changes: 2 additions & 2 deletions examples/internlm2_agent_web_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import streamlit as st

from lagent.actions import ActionExecutor, ArxivSearch, IPythonInterpreter
from lagent.agents.internlm2_agent import INTERPRETER_CN, META_INS, PLUGIN_CN, Internlm2Agent, Internlm2Protocol
from lagent.agents.internlm2_agent import INTERPRETER_CN, META_CN, PLUGIN_CN, Internlm2Agent, Internlm2Protocol
from lagent.llms.lmdepoly_wrapper import LMDeployClient
from lagent.llms.meta_template import INTERNLM2_META as META
from lagent.schema import AgentStatusCode
Expand Down Expand Up @@ -63,7 +63,7 @@ def init_streamlit(self):
def setup_sidebar(self):
"""Setup the sidebar for model and plugin selection."""
model_name = st.sidebar.selectbox('模型选择:', options=['internlm'])
meta_prompt = st.sidebar.text_area('系统提示词', value=META_INS)
meta_prompt = st.sidebar.text_area('系统提示词', value=META_CN)
da_prompt = st.sidebar.text_area('数据分析提示词', value=INTERPRETER_CN)
plugin_prompt = st.sidebar.text_area('插件提示词', value=PLUGIN_CN)
model_ip = st.sidebar.text_input('模型IP:', value='10.140.0.220:23333')
Expand Down
30 changes: 13 additions & 17 deletions lagent/agents/internlm2_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,27 @@
"This is the subfunction for tool '{tool_name}', you can use this tool. "
'The description of this function is: \n{description}')

META_INS = ('You are InternLM, a large language model trained by PJLab. '
'Answer as concisely as possible. '
'当开启工具以及代码时,根据需求选择合适的工具进行调用')
META_CN = ('当开启工具以及代码时,根据需求选择合适的工具进行调用')

INTERPRETER_CN = ('你现在可以通过如下格式向 Jupyter Notebook 发送并执行代码:'
'\n<|action_start|><|interpreter|>```python\n\n代码\n\n```\n'
'\n当遇到以下问题时,请使用上述格式调用 Jupyter Notebook 去解决,并根据执行结果做出友好的回复:\n'
'1. 文件操作和数据导入,比如处理CSV、JSON等格式文件\n'
'2. 数据分析或处理,比如数据操作或图像绘制如折线图、柱状图等\n'
'3. 数学相关的问题。当遇到数学问题时,你需要分析题目,并给出代码去解决这个题目')
INTERPRETER_CN = ('你现在已经能够在一个有状态的 Jupyter 笔记本环境中运行 Python 代码。'
'当你向 python 发送含有 Python 代码的消息时,它将在该环境中执行。'
'这个工具适用于多种场景,如数据分析或处理(包括数据操作、统计分析、图表绘制),'
'复杂的计算问题(解决数学和物理难题),编程示例(理解编程概念或特性),'
'文本处理和分析(比如文本解析和自然语言处理),'
'机器学习和数据科学(用于展示模型训练和数据可视化),'
'以及文件操作和数据导入(处理CSV、JSON等格式的文件)。')

PLUGIN_CN = (
'你可以使用如下工具:'
'\n{prompt}\n'
'当你需要使用工具时,你可以使用如下格式:\n'
'<|action_start|><|plugin|>{{"name": "工具名称", "parameters": {{参数}}}}\n'
'如果你已经获得足够信息,请直接给出答案. 避免不必要的工具调用! '
'同时注意你可以使用的工具,不要随意捏造!')
PLUGIN_CN = ('你可以使用如下工具:'
'\n{prompt}\n'
'如果你已经获得足够信息,请直接给出答案. 避免不必要的工具调用! '
'同时注意你可以使用的工具,不要随意捏造!')


class Internlm2Protocol:

def __init__(
self,
meta_prompt: str = META_INS,
meta_prompt: str = META_CN,
interpreter_prompt: str = INTERPRETER_CN,
plugin_prompt: str = PLUGIN_CN,
few_shot: Optional[List] = None,
Expand Down

0 comments on commit 94959c1

Please sign in to comment.