pvanand commited on
Commit
7174a4c
·
verified ·
1 Parent(s): d902022

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +28 -7
main.py CHANGED
@@ -40,6 +40,24 @@ SysPromptList = "You are now in the role of an expert AI who can extract structu
40
  SysPromptDefault = "You are an expert AI, complete the given task. Do not add any additional comments."
41
  SysPromptMd = "You are an expert AI who can create a structured report using information provided in the context from user request.The report should be in markdown format consists of markdown tables structured into subtopics. Do not add any additional comments."
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  sys_prompts = {
44
  "offline": {
45
  "Chat": "You are an expert AI, complete the given task. Do not add any additional comments.",
@@ -47,7 +65,8 @@ sys_prompts = {
47
  "Tabular Report": "You are an expert AI who can create a structured report from user request.The report should be in markdown format structured into subtopics/tables/lists. Do not add any additional comments.",
48
  "Tables only": "You are an expert AI who can create a structured tabular report from user request.The report should be in markdown format consists of only markdown tables. Do not add any additional comments.",
49
  },
50
- "online": {
 
51
  "Chat": "You are an expert AI, complete the given task using the provided context. Do not add any additional comments.",
52
  "Full Text Report": "You are an expert AI who can create a detailed report using information scraped from the internet. You should decide which information is relevant to the given task and use it to create a report. The report should be in markdown format. Do not add any additional comments.",
53
  "Tabular Report": "You are an expert AI who can create a structured report using information scraped from the internet. You should decide which information is relevant to the given task and use it to create a report. The report should be in markdown format structured into subtopics/tables/lists. Do not add any additional comments.",
@@ -61,8 +80,8 @@ class QueryModel(BaseModel):
61
  user_id: str = Query(default="", description="unique user id")
62
  user_name: str = Query(default="", description="user name")
63
  internet: bool = Query(default=True, description="Enable Internet search")
64
- output_format: str = Query(default="Tabular Report", description="Output format for the report",
65
- enum=["Chat", "Full Text Report", "Tabular Report", "Tables only"])
66
  data_format: str = Query(default="Structured data", description="Type of data to extract from the internet",
67
  enum=["No presets", "Structured data", "Quantitative data"])
68
 
@@ -72,7 +91,8 @@ async def generate_report(query: QueryModel):
72
  description = query.description
73
  user_id = query.user_id
74
  internet = "online" if query.internet else "offline"
75
- sys_prompt_output_format = sys_prompts[internet][query.output_format]
 
76
  data_format = query.data_format
77
  optimized_search_query = ""
78
  all_text_with_urls = [("", "")]
@@ -82,8 +102,8 @@ async def generate_report(query: QueryModel):
82
  try:
83
  urls, optimized_search_query = search_brave(search_query, num_results=8)
84
  all_text_with_urls = fetch_and_extract_content(data_format, urls, query_str)
85
- additional_context = limit_tokens(str(all_text_with_urls))
86
- prompt = f"#### COMPLETE THE TASK: {description} #### IN THE CONTEXT OF ### CONTEXT: {query_str} USING THE #### SCRAPED DATA:{additional_context}"
87
  except Exception as e:
88
  print(e)
89
  query.internet = False
@@ -91,8 +111,9 @@ async def generate_report(query: QueryModel):
91
 
92
  if not query.internet:
93
  prompt = f"#### COMPLETE THE TASK: {description} #### IN THE CONTEXT OF ### CONTEXT: {query_str}"
 
94
 
95
- md_report = together_response(prompt, model=llm_default_medium, SysPrompt=sys_prompt_output_format)
96
 
97
  if user_id != "test":
98
  insert_data(user_id, query_str, description, str(all_text_with_urls), md_report)
 
40
  SysPromptDefault = "You are an expert AI, complete the given task. Do not add any additional comments."
41
  SysPromptMd = "You are an expert AI who can create a structured report using information provided in the context from user request.The report should be in markdown format consists of markdown tables structured into subtopics. Do not add any additional comments."
42
 
43
+ prompt_user = {}
44
+ prompt_user["online"] = {}
45
+ prompt_user["offline"] = {}
46
+ prompt_user["online"]["chat"] = "Write a well thought out answer to the query:: {description} #### , refer the provided internet search results reference:{reference}
47
+ prompt_user["online"]["report"] = "Write a well thought out Report to the query:: {description} #### , refer the provided internet search results reference:{reference}
48
+ prompt_user["online"]["report_table"] = "Write a well thought out Report to the query:: {description}, include any relevant tables if present in the source #### , refer the provided internet search results reference:{reference}
49
+
50
+ prompt_user["offline"]["chat"] = "Write a well thought out answer to the query:: {description}"
51
+ prompt_user["offline"]["report"] = "Write a well thought out Report to the query:: {description}"
52
+ prompt_user["offline"]["report_table"] = "Write a well thought out Report to the query:: {description}, include any relevant tables as markdown"
53
+
54
+ prompt_system["online"] = """You are an expert AI who can provide answers using internet search results.
55
+ 1 filter and summarize relevant information, if there are conflicting information, use the latest source.
56
+ 2. use it to construct a clear and factual answer.
57
+ Your response should be properly formatted and well readable using markdown formatting. """
58
+
59
+ prompt_system["offline"] = """Your response should be properly formatted and well readable using markdown formatting."""
60
+
61
  sys_prompts = {
62
  "offline": {
63
  "Chat": "You are an expert AI, complete the given task. Do not add any additional comments.",
 
65
  "Tabular Report": "You are an expert AI who can create a structured report from user request.The report should be in markdown format structured into subtopics/tables/lists. Do not add any additional comments.",
66
  "Tables only": "You are an expert AI who can create a structured tabular report from user request.The report should be in markdown format consists of only markdown tables. Do not add any additional comments.",
67
  },
68
+ "online":
69
+ "user":{
70
  "Chat": "You are an expert AI, complete the given task using the provided context. Do not add any additional comments.",
71
  "Full Text Report": "You are an expert AI who can create a detailed report using information scraped from the internet. You should decide which information is relevant to the given task and use it to create a report. The report should be in markdown format. Do not add any additional comments.",
72
  "Tabular Report": "You are an expert AI who can create a structured report using information scraped from the internet. You should decide which information is relevant to the given task and use it to create a report. The report should be in markdown format structured into subtopics/tables/lists. Do not add any additional comments.",
 
80
  user_id: str = Query(default="", description="unique user id")
81
  user_name: str = Query(default="", description="user name")
82
  internet: bool = Query(default=True, description="Enable Internet search")
83
+ output_format: str = Query(default="report_table", description="Output format for the report",
84
+ enum=["chat", "report", "report_table"])
85
  data_format: str = Query(default="Structured data", description="Type of data to extract from the internet",
86
  enum=["No presets", "Structured data", "Quantitative data"])
87
 
 
91
  description = query.description
92
  user_id = query.user_id
93
  internet = "online" if query.internet else "offline"
94
+ user_prompt_final = prompt_user[internet][query.output_format]
95
+ system_prompt_final = prompt_system[internet]
96
  data_format = query.data_format
97
  optimized_search_query = ""
98
  all_text_with_urls = [("", "")]
 
102
  try:
103
  urls, optimized_search_query = search_brave(search_query, num_results=8)
104
  all_text_with_urls = fetch_and_extract_content(data_format, urls, query_str)
105
+ reference = limit_tokens(str(all_text_with_urls))
106
+ prompt = user_prompt_final.format(description,reference)
107
  except Exception as e:
108
  print(e)
109
  query.internet = False
 
111
 
112
  if not query.internet:
113
  prompt = f"#### COMPLETE THE TASK: {description} #### IN THE CONTEXT OF ### CONTEXT: {query_str}"
114
+ system_prompt_final = prompt_system["offline"]
115
 
116
+ md_report = together_response(prompt, model=llm_default_medium, SysPrompt=system_prompt_final)
117
 
118
  if user_id != "test":
119
  insert_data(user_id, query_str, description, str(all_text_with_urls), md_report)