代码拉取完成,页面将自动刷新
# -*- 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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。