Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -81,8 +81,9 @@ OPENROUTER_API_KEY = "sk-or-v1-"+os.environ['OPENROUTER_API_KEY']
|
|
| 81 |
|
| 82 |
|
| 83 |
class QueryModel(BaseModel):
|
| 84 |
-
|
| 85 |
-
|
|
|
|
| 86 |
user_id: str = Query(default="", description="unique user id")
|
| 87 |
user_name: str = Query(default="", description="user name")
|
| 88 |
internet: bool = Query(default=True, description="Enable Internet search")
|
|
@@ -91,7 +92,7 @@ class QueryModel(BaseModel):
|
|
| 91 |
data_format: str = Query(default="Structured data", description="Type of data to extract from the internet",
|
| 92 |
enum=["No presets", "Structured data", "Quantitative data"])
|
| 93 |
generate_charts: bool = Query(default=False, description="Include generated charts")
|
| 94 |
-
|
| 95 |
|
| 96 |
@cache(expire=604800)
|
| 97 |
async def generate_report(query: QueryModel):
|
|
@@ -105,6 +106,7 @@ async def generate_report(query: QueryModel):
|
|
| 105 |
optimized_search_query = ""
|
| 106 |
all_text_with_urls = [("", "")]
|
| 107 |
generate_charts = query.generate_charts
|
|
|
|
| 108 |
|
| 109 |
if query.internet:
|
| 110 |
search_query = re.sub(r'[^\w\s]', '', description).strip()
|
|
@@ -135,9 +137,8 @@ async def generate_report(query: QueryModel):
|
|
| 135 |
<report>output the full content without any other changes in md format enclosed in tags like this</report> using the following:" + str(md_report)
|
| 136 |
|
| 137 |
messages = [{"role": 'user', "content": prompt}]
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
print(html_report)
|
| 141 |
|
| 142 |
except Exception as e:
|
| 143 |
print(e)
|
|
@@ -149,8 +150,10 @@ async def generate_report(query: QueryModel):
|
|
| 149 |
for text, url in all_text_with_urls:
|
| 150 |
references_html[url] = str(md_to_html(text))
|
| 151 |
|
|
|
|
|
|
|
| 152 |
return {
|
| 153 |
-
"report":
|
| 154 |
"references": references_html,
|
| 155 |
"search_query": optimized_search_query
|
| 156 |
}
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
class QueryModel(BaseModel):
|
| 84 |
+
user_query: str = Query(default="", description="Initial user query")
|
| 85 |
+
topic: str = Query(default="", description="Topic name to generate Report")
|
| 86 |
+
description: str = Query(description="Description/prompt for report (REQUIRED)")
|
| 87 |
user_id: str = Query(default="", description="unique user id")
|
| 88 |
user_name: str = Query(default="", description="user name")
|
| 89 |
internet: bool = Query(default=True, description="Enable Internet search")
|
|
|
|
| 92 |
data_format: str = Query(default="Structured data", description="Type of data to extract from the internet",
|
| 93 |
enum=["No presets", "Structured data", "Quantitative data"])
|
| 94 |
generate_charts: bool = Query(default=False, description="Include generated charts")
|
| 95 |
+
output_as_md: bool = Query(default=False, description="Output report in markdown (default output in HTML)")
|
| 96 |
|
| 97 |
@cache(expire=604800)
|
| 98 |
async def generate_report(query: QueryModel):
|
|
|
|
| 106 |
optimized_search_query = ""
|
| 107 |
all_text_with_urls = [("", "")]
|
| 108 |
generate_charts = query.generate_charts
|
| 109 |
+
output_as_md = query.output_as_md
|
| 110 |
|
| 111 |
if query.internet:
|
| 112 |
search_query = re.sub(r'[^\w\s]', '', description).strip()
|
|
|
|
| 137 |
<report>output the full content without any other changes in md format enclosed in tags like this</report> using the following:" + str(md_report)
|
| 138 |
|
| 139 |
messages = [{"role": 'user', "content": prompt}]
|
| 140 |
+
md_report = extract_data_from_tag(openrouter_response(messages, model="anthropic/claude-3.5-sonnet"),"report")
|
| 141 |
+
print(md_report)
|
|
|
|
| 142 |
|
| 143 |
except Exception as e:
|
| 144 |
print(e)
|
|
|
|
| 150 |
for text, url in all_text_with_urls:
|
| 151 |
references_html[url] = str(md_to_html(text))
|
| 152 |
|
| 153 |
+
final_report = md_report if output_as_md else md_to_html(md_report)
|
| 154 |
+
|
| 155 |
return {
|
| 156 |
+
"report": final_report,
|
| 157 |
"references": references_html,
|
| 158 |
"search_query": optimized_search_query
|
| 159 |
}
|