1 Star 8 Fork 5

openai/llm-agent

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
prompt.py 3.50 KB
一键复制 编辑 原始数据 按行查看 历史
acedar 提交于 2024-05-18 22:38 . update agent
# -*- encoding: utf-8 -*-
"""
@author: acedar
@time: 2024/5/12 11:40
@file: prompt.py
"""
# -*- coding: utf-8 -*-
# ----------------------------
# @Time : 2024/5/6 11:33
# @Author : acedar
# @FileName: prompt.py
# ----------------------------
from tools import gen_tools_desc
constraints = [
'Exclusively use the actions listed below.',
'You can only act proactively, and are unable to start background jobs or set up webhooks for yourself. Take this into account when planning your actions.',
'You are unable to interact with physical objects. If this is absolutely necessary to fulfill a task or objective or to complete a step, you must ask the user to do it for you. If the user refuses this, and there is no other way to achieve your goals, you must terminate to avoid wasting time and energy.'
]
resources = [
'Internet access for searches and information gathering.',
'The ability to read and write files.',
'You are a Large Language Model, trained on millions of pages of text, including a lot of factual knowledge. Make use of this factual knowledge to avoid unnecessary gathering of information.'
]
best_practices = [
'Continuously review and analyze your actions to ensure you are performing to the best of your abilities.',
'Constructively self-criticize your big-picture behavior constantly.',
'Reflect on past decisions and strategies to refine your approach.',
'Every action has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.',
'Only make use of your information gathering abilities to find information that you don''t yet have knowledge of.'
]
prompt_template = """
You are Q&A experts, Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications.
goal:
{query}
Constraints:
{constraints}
actions: there are the ONLY actions you can use. Any action you perform must be possible through one of these actions:
{actions}
Resources:
{resources}
best_practices:
{best_practices}
agent_scratch:{agent_scratch}
You should only respond in JSON format as described below
Response Format:
{response_format_prompt}
Ensure the response can be parsed by Python json.loads
"""
response_format_prompt = """{
"thoughts": {
"reasoning": "reasoning",
"plan": "- short bulleted\n- list that conveys\n- long-term plan",
"criticism": "constructive self-criticism",
"speak": "thoughts summary to say to user"
},
"action": {
"name": "action name",
"args": {
"answer": "the goal's final answer"
}
},
"observation": "the result of the action",
}
"""
user_prompt = "Determine exactly one command to use next based on the given goals and the progress you have made so far, and respond using the JSON schema specified previously:"
actions_prompt = gen_tools_desc()
constraints_prompt = "\n".join([f"{idx+1}. {con}" for idx, con in enumerate(constraints)])
resources_prompt = "\n".join([f"{idx+1}. {con}" for idx, con in enumerate(resources)])
best_practices_prompt = "\n".join([f"{idx+1}. {con}" for idx, con in enumerate(best_practices)])
def gen_prompt(query, agent_scratch):
# 1)触发llm思考下一步action
prompt = prompt_template.format(
query=query, constraints=constraints_prompt, actions=actions_prompt,
resources=resources_prompt, best_practices=best_practices_prompt,
agent_scratch=agent_scratch, response_format_prompt=response_format_prompt)
return prompt
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/open-llm/llm-agent.git
[email protected]:open-llm/llm-agent.git
open-llm
llm-agent
llm-agent
master

搜索帮助