Skip to content

Commit

Permalink
fix bug of building plugin prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
braisedpork1964 committed Oct 24, 2024
1 parent d02cadf commit 5e6055c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lagent/agents/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_plugin_prompt(actions, api_desc_template=API_PREFIX):
plugin_descriptions.append(api)
else:
action_desc['description'] = api_desc_template.format(
tool_name=action.name, description=api['description'])
tool_name=action.name, description=action_desc['description'])
action_desc['parameters'] = [
param for param in action_desc['parameters']
if param['name'] in action_desc['required']
Expand Down
25 changes: 13 additions & 12 deletions usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,13 @@ from lagent.llms import GPTAPI
from lagent.hooks import InternLMActionProcessor

TOOL_TEMPLATE = (
"You are a helpful AI assistant, collaborating with other assistants."
" Use the provided tools to progress towards answering the question."
" If you are unable to fully answer, that's OK, another assistant with different tools "
" will help where you left off. Execute what you can to make progress."
" If you or any of the other assistants have the final answer or deliverable,"
" prefix your response with {finish_pattern} so the team knows to stop."
" You have access to the following tools:\n{tool_description}.\\\\n**{system_prompt}**"
"You are a helpful AI assistant, collaborating with other assistants. Use the provided tools to progress"
" towards answering the question. If you are unable to fully answer, that's OK, another assistant with"
" different tools will help where you left off. Execute what you can to make progress. If you or any of"
" the other assistants have the final answer or deliverable, prefix your response with {finish_pattern}"
" so the team knows to stop. You have access to the following tools:\n{tool_description}\nPlease provide"
" your thought process when you need to use a tool, followed by the call statement in this format:"
"\n{invocation_format}\\\\n**{system_prompt}**"
)

class DataVisualizer(Agent):
Expand All @@ -425,15 +425,15 @@ class DataVisualizer(Agent):
llm,
TOOL_TEMPLATE.format(
finish_pattern=finish_pattern,
tool_description=get_plugin_prompt(browser) +
'\nInvoke a tool in this format: ```json\n{"name": {{tool name}}, "parameters": {{keyword arguments}}}\n```\n',
tool_description=get_plugin_prompt(browser),
invocation_format='```json\n{"name": {{tool name}}, "parameters": {{keyword arguments}}}\n```\n',
system_prompt=research_prompt,
),
output_format=ToolParser(
"browser",
begin="```json\n",
end="\n```\n",
validate=lambda x: json.loads(x.rstrip('\n`')),
validate=lambda x: json.loads(x.rstrip('`')),
),
aggregator=InternLMToolAggregator(),
name="researcher",
Expand All @@ -442,14 +442,15 @@ class DataVisualizer(Agent):
llm,
TOOL_TEMPLATE.format(
finish_pattern=finish_pattern,
tool_description=interpreter.name + '\nInvoke a tool in this format: ```python\n{{code}}\n```\n',
tool_description=interpreter.name,
invocation_format='```python\n{{code}}\n```\n',
system_prompt=chart_prompt,
),
output_format=ToolParser(
"interpreter",
begin="```python\n",
end="\n```\n",
validate=lambda x: x.rstrip('\n`'),
validate=lambda x: x.rstrip('`'),
),
aggregator=InternLMToolAggregator(),
name="charter",
Expand Down

0 comments on commit 5e6055c

Please sign in to comment.