Spaces:
Sleeping
Sleeping
import textwrap | |
def get_system_prompt(app_name, app_description, relevant_database, user_state, task, | |
current_page, last_page, actions, sitemap_page, jinjia_prerender): | |
system_prompt = textwrap.dedent(f""" | |
You are a text-based CLI {app_name} ({app_description}) simulator. | |
The {app_name} app contains the following database tables: {relevant_database}. | |
You are interacting with a user whose task is: {task}. | |
User's current state: {user_state}. | |
The user's last page was {last_page}, and they have taken the following actions: {actions}. | |
After performing the most recent action, the user is now on the {current_page} page. | |
Details and buttons on the current page: | |
{sitemap_page} | |
This page should display following pre-rendered page to user and making sure replace the placeholders with real data from database. | |
{jinjia_prerender} | |
### **Rules**: | |
1. Display all information from the pre-rendered page. | |
2. Remain robotic and emotionless. Avoid offering any advice or opinions to the user. | |
3. If there are two Home option, only keep the 'Back to last page: button' option. | |
4. Mimic the real {app_name} scenario as much as possible. | |
5. Provide the user with user name and password if they are on the sign in page. | |
""") | |
return system_prompt | |
def get_database_update_prompt(user_input, current_page, database): | |
update_database = textwrap.dedent(f""" | |
You will now update the database. | |
The user takes the action '{user_input}' on the {current_page} page. Determine how will database change. | |
Recall the current Database: | |
{database} | |
### Output Format: | |
1. Start with "REASON": Explain which fields in database need to be updated and why. | |
2. End with "UPDATED": Provide only the updated database. Follow the input database schema structure exactly without modifying its organization. Do not include explanations or any additional text after updated database. | |
""") | |
return update_database | |
def get_user_state_update_prompt(user_input, current_page, task, database, solution, user_state, sitemap): | |
update_prompt = textwrap.dedent(f""" | |
You will now update the user state. | |
The user takes the action '{user_input}' on the {current_page} page. Determine which page the user will move to next. | |
The next page must from the sitemap: {sitemap} | |
Recall the user's task: {task}. Recall the current Database: {database}. Solution to the user's task: {solution}. | |
Update the `user_state` dictionary based on the user's last action: | |
Current user_state: {user_state}. | |
### Instructions: | |
1. If the 'current_page' has changed, update it to a valid page from the sitemap. | |
2. If the task is completed, update 'task_completed' to `True`. Otherwise, leave it as `False`. | |
3. If no updates are needed, return the `user_state` exactly as provided, without any changes. | |
### Important Notes: | |
- Ensure 'current_page' and 'task_completed' are always present as keys in the returned dictionary. | |
- If the user go back a page from current page, set 'back' to `True`. Otherwise, it should remain `False`. | |
- Return only the updated dictionary, without additional text, explanations, or wrapping. | |
### Output Format: | |
1. Start with "REASON": Explain which fields in `user_state` need to be updated and why. | |
2. End with "UPDATED": Provide only the updated `user_state` dictionary. Follow the input user_state schema structure exactly without modifying its organization. Do not include explanations or any additional text after updated user state. | |
""") | |
return update_prompt | |
def get_agent_prompt(app_name, task, conversation): | |
agent_prompt = textwrap.dedent(f""" | |
Imagine you are an agent navigate through the {app_name} environment. | |
Your overarching task is: {task}. You may have done some part of the task, or none at all. | |
You will have access to all of your previous actions in the environment, as well as the last message from the assistant giving the current state of the environment. | |
The last message from the assistant was: {conversation[-1]['content']} | |
Respond first with a brief "Plan" which suggests what steps you are going to take to accomplish the task, and what your immediate. | |
Then generate an "Action" which is the immediate next step you can take. | |
""") | |
return agent_prompt |