Update prompts
Browse files
main.py
CHANGED
|
@@ -25,6 +25,70 @@ SysPromptMd = "You are an expert AI who can create a structured report using inf
|
|
| 25 |
SysPromptMdOffline = "You are an expert AI who can create a structured report using your knowledge on user request.The report should be in markdown format consists of markdown tables/lists/paragraphs as needed, structured into subtopics. Do not add any additional comments."
|
| 26 |
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
def together_response(message, model = "meta-llama/Llama-3-8b-chat-hf", SysPrompt = SysPromptDefault, temperature=0.2):
|
| 29 |
client = OpenAI(
|
| 30 |
api_key=TOGETHER_API_KEY,
|
|
@@ -61,11 +125,8 @@ def json_from_text(text):
|
|
| 61 |
return loads(fix_json.fix(json_out).line)
|
| 62 |
|
| 63 |
def generate_topics(user_input, num_topics, previous_queries):
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
+""" Respond in the following format:
|
| 67 |
-
[["Subtopic","Description"],["Subtopic","Description"]]"""
|
| 68 |
-
response_topics = together_response(prompt, model="meta-llama/Llama-3-8b-chat-hf", SysPrompt=SysPromptList)
|
| 69 |
subtopics = json_from_text(response_topics)
|
| 70 |
return subtopics
|
| 71 |
|
|
@@ -95,7 +156,13 @@ app.add_middleware(
|
|
| 95 |
class TopicInput(BaseModel):
|
| 96 |
user_input: str = Query(default="market research", description="input query to generate subtopics")
|
| 97 |
num_topics: int = Query(default=5, description="Number of subtopics to generate (default: 5)")
|
| 98 |
-
previous_queries: list[str] = Query(default=[], description="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
class imageInput(BaseModel):
|
| 101 |
user_input: str = Query(default="market research", description="input query to generate subtopics")
|
|
@@ -118,6 +185,11 @@ async def create_topics(input: TopicInput):
|
|
| 118 |
topics = generate_topics(input.user_input, input.num_topics, input.previous_queries)
|
| 119 |
return {"topics": topics}
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
@app.post("/generate_report")
|
| 122 |
async def create_report(input: ReportInput):
|
| 123 |
report = generate_report(input.topic, input.description)
|
|
|
|
| 25 |
SysPromptMdOffline = "You are an expert AI who can create a structured report using your knowledge on user request.The report should be in markdown format consists of markdown tables/lists/paragraphs as needed, structured into subtopics. Do not add any additional comments."
|
| 26 |
|
| 27 |
|
| 28 |
+
prompt_topics = """
|
| 29 |
+
You are an expert data analyst. You have been providing data analysis and structuring services for over 15 years. You specialize in creating detailed and comprehensive lists of subtopics for various fields.
|
| 30 |
+
|
| 31 |
+
Your task is to create a list of essential subtopics along with their descriptions based on the given USER_QUERY. The objective is to generate a detailed and precise list of subtopics that can help in understanding the main topic thoroughly.
|
| 32 |
+
|
| 33 |
+
Follow these steps to complete the task:
|
| 34 |
+
|
| 35 |
+
1. Identify and list 2 to {num_topics} essential subtopics related to {user_input}.
|
| 36 |
+
2. Provide a detailed description for each subtopic explaining its significance and relevance to the main topic.
|
| 37 |
+
3. Format your response as a valid Python list of lists, where each sub-list contains the subtopic and its description.
|
| 38 |
+
|
| 39 |
+
Make sure your response is well-organized and provides comprehensive details for each subtopic.
|
| 40 |
+
|
| 41 |
+
Take a deep breath and work on this problem step-by-step.
|
| 42 |
+
|
| 43 |
+
output format
|
| 44 |
+
[
|
| 45 |
+
["Subtask Title 1", "Detailed description of subtask 1."],
|
| 46 |
+
["Subtask Title 2", "Detailed description of subtask 2."],
|
| 47 |
+
...
|
| 48 |
+
]
|
| 49 |
+
YOUR OUTPUT SHOULD CONSIST ONLY A VALID PYTHON LIST, DO NOT ADD ADDITIONAL COMMENTS
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
prompt_subtopics = """You are a professional task manager and prompt engineer. You have been helping teams and individuals decompose complex tasks into actionable subtasks for over 20 years. Your expertise lies in breaking down intricate tasks into clear, manageable steps and ensuring that all relevant aspects are covered while excluding any specified topics.**
|
| 53 |
+
|
| 54 |
+
Objective: Help create 2 to {num_topics} subtasks for an LLM to perform the specified task in the context of the given user query. Ensure that the generated subtasks are precise, actionable, and detailed. Exclude the specified topics from the subtasks.
|
| 55 |
+
|
| 56 |
+
**Steps to complete the task:**
|
| 57 |
+
|
| 58 |
+
1. **Understand the Main Task and User Query:**
|
| 59 |
+
- Read the main task and user query carefully to grasp the core objectives and context.
|
| 60 |
+
- Identify any specific requirements or constraints mentioned in the query.
|
| 61 |
+
|
| 62 |
+
2. **Identify Key Components:**
|
| 63 |
+
- Break down the main task into its fundamental components.
|
| 64 |
+
- Ensure each component is essential to the overall goal and can be clearly defined.
|
| 65 |
+
|
| 66 |
+
3. **Create Detailed Subtasks:**
|
| 67 |
+
- For each key component, create 2 to 5 detailed subtasks.
|
| 68 |
+
- Ensure each subtask is actionable and provides clear instructions on what needs to be done.
|
| 69 |
+
- Maintain logical order and ensure that the completion of each subtask contributes to the overall objective.
|
| 70 |
+
|
| 71 |
+
4. **Exclude Specified Topics:**
|
| 72 |
+
- Review the list of topics to be excluded.
|
| 73 |
+
- Ensure that none of the generated subtasks include these topics.
|
| 74 |
+
|
| 75 |
+
5. **Format the Response:**
|
| 76 |
+
- Present the subtasks in a structured Python list of lists format.
|
| 77 |
+
- Each sub-list should contain the subtask title and its detailed description.
|
| 78 |
+
|
| 79 |
+
Output Format:
|
| 80 |
+
[
|
| 81 |
+
["Subtask Title 1", "Detailed description of subtask 1."],
|
| 82 |
+
["Subtask Title 2", "Detailed description of subtask 2."],
|
| 83 |
+
...
|
| 84 |
+
]
|
| 85 |
+
|
| 86 |
+
MAIN TASK: {main_task}
|
| 87 |
+
USER QUERY:{user_input}
|
| 88 |
+
TOPICS TO BE EXCLUDED:{excluded_topics}
|
| 89 |
+
YOUR OUTPUT SHOULD CONSIST ONLY A VALID PYTHON LIST, DO NOT ADD ADDITIONAL COMMENTS
|
| 90 |
+
"""
|
| 91 |
+
|
| 92 |
def together_response(message, model = "meta-llama/Llama-3-8b-chat-hf", SysPrompt = SysPromptDefault, temperature=0.2):
|
| 93 |
client = OpenAI(
|
| 94 |
api_key=TOGETHER_API_KEY,
|
|
|
|
| 125 |
return loads(fix_json.fix(json_out).line)
|
| 126 |
|
| 127 |
def generate_topics(user_input, num_topics, previous_queries):
|
| 128 |
+
prompt = prompt_topics.format(user_input=user_input, num_topics=num_topics)
|
| 129 |
+
response_topics = together_response(prompt, model="meta-llama/Llama-3-70b-chat-hf", SysPrompt=SysPromptList, temperature=1)
|
|
|
|
|
|
|
|
|
|
| 130 |
subtopics = json_from_text(response_topics)
|
| 131 |
return subtopics
|
| 132 |
|
|
|
|
| 156 |
class TopicInput(BaseModel):
|
| 157 |
user_input: str = Query(default="market research", description="input query to generate subtopics")
|
| 158 |
num_topics: int = Query(default=5, description="Number of subtopics to generate (default: 5)")
|
| 159 |
+
previous_queries: list[str] = Query(default=[], description="Deprecated: Use /generate_subtopics instead for subtopics")
|
| 160 |
+
|
| 161 |
+
class SubTopicInput(BaseModel):
|
| 162 |
+
main_task: str = Query(default="detailed market research", description="Main task to be completed")
|
| 163 |
+
user_input: str = Query(default="I want to start a business in retail", description="input query to generate subtopics")
|
| 164 |
+
num_topics: int = Query(default=3, description="Number of max subtopics to generate (default: 3)")
|
| 165 |
+
excluded_topics: list[str] = Query(default=[], description="List all other main tasks to exclude")
|
| 166 |
|
| 167 |
class imageInput(BaseModel):
|
| 168 |
user_input: str = Query(default="market research", description="input query to generate subtopics")
|
|
|
|
| 185 |
topics = generate_topics(input.user_input, input.num_topics, input.previous_queries)
|
| 186 |
return {"topics": topics}
|
| 187 |
|
| 188 |
+
@app.post("/generate_subtopics")
|
| 189 |
+
async def create_subtopics(input: SubTopicInput):
|
| 190 |
+
topics = generate_subtopics(input.main_task, input.user_input, input.num_topics, input.excluded_topics)
|
| 191 |
+
return {"subtopics": topics}
|
| 192 |
+
|
| 193 |
@app.post("/generate_report")
|
| 194 |
async def create_report(input: ReportInput):
|
| 195 |
report = generate_report(input.topic, input.description)
|