internlm2_agent

Module Contents

Classes

Internlm2Protocol

Internlm2Agent

BaseAgent is the base class of all agents.

Attributes

API_PREFIX

META_INS

INTERPRETER_CN

PLUGIN_CN

lagent.agents.internlm2_agent.API_PREFIX = Multiline-String
Show Value
"""This is the subfunction for tool '{tool_name}', you can use this tool. The description of this function is:
{description}"""
lagent.agents.internlm2_agent.META_INS = 'You are InternLM, a large language model trained by PJLab. Answer as concisely as possible....'
lagent.agents.internlm2_agent.INTERPRETER_CN = Multiline-String
Show Value
"""你现在可以通过如下格式向 Jupyter Notebook 发送并执行代码:
<|action_start|><|interpreter|>```python

代码

```

当遇到以下问题时,请使用上述格式调用 Jupyter Notebook 去解决,并根据执行结果做出友好的回复:
1. 文件操作和数据导入,比如处理CSV、JSON等格式文件
2. 数据分析或处理,比如数据操作或图像绘制如折线图、柱状图等
3. 数学相关的问题。当遇到数学问题时,你需要分析题目,并给出代码去解决这个题目"""
lagent.agents.internlm2_agent.PLUGIN_CN = Multiline-String
Show Value
"""你可以使用如下工具:
{prompt}
当你需要使用工具时,你可以使用如下格式:
<|action_start|><|plugin|>{{"name": "工具名称", "parameters": {{参数}}}}
如果你已经获得足够信息,请直接给出答案. 避免不必要的工具调用! 同时注意你可以使用的工具,不要随意捏造!"""
class lagent.agents.internlm2_agent.Internlm2Protocol(meta_prompt=META_INS, interpreter_prompt=INTERPRETER_CN, plugin_prompt=PLUGIN_CN, few_shot=None, language=dict(begin='', end='', belong='assistant'), tool=dict(begin='{start_token}{name}\n', start_token='<|action_start|>', name_map=dict(plugin='<|plugin|>', interpreter='<|interpreter|>'), belong='assistant', end='<|action_end|>\n'), execute=dict(role='execute', begin='', end='', fallback_role='environment'))
Parameters:
  • meta_prompt (str) –

  • interpreter_prompt (str) –

  • plugin_prompt (str) –

  • few_shot (Optional[List]) –

  • language (Dict) –

  • tool (Dict) –

  • execute (Dict) –

format_sub_role(messages)
Parameters:

messages (List[Dict]) –

Return type:

List[Dict]

format(inner_step, plugin_executor=None, interpreter_executor=None, **kwargs)
Parameters:
  • inner_step (List[Dict]) –

  • plugin_executor (lagent.actions.ActionExecutor) –

  • interpreter_executor (lagent.actions.ActionExecutor) –

Return type:

list

parse(message, plugin_executor, interpreter_executor)
Parameters:
  • plugin_executor (lagent.actions.ActionExecutor) –

  • interpreter_executor (lagent.actions.ActionExecutor) –

format_response(action_return, name)
Return type:

dict

class lagent.agents.internlm2_agent.Internlm2Agent(llm, plugin_executor=None, interpreter_executor=None, protocol=Internlm2Protocol(), max_turn=3)

Bases: lagent.BaseAgent

BaseAgent is the base class of all agents.

Parameters:
  • llm (BaseModel) – the language model.

  • action_executor (ActionExecutor) – the action executor.

  • protocol (object) – the protocol of the agent, which is used to generate the prompt of the agent and parse the response from the llm.

  • plugin_executor (lagent.actions.ActionExecutor) –

  • interpreter_executor (lagent.actions.ActionExecutor) –

  • max_turn (int) –

chat(message, **kwargs)
Parameters:

message (Union[str, Dict]) –

Return type:

lagent.schema.AgentReturn

stream_chat(message, **kwargs)
Parameters:

message (List[dict]) –

Return type:

lagent.schema.AgentReturn