Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
@@ -55,25 +55,31 @@ async def generate_report(request: Request, query: QueryModel):
|
|
55 |
description = query.description
|
56 |
user_id = query.user_id
|
57 |
internet = "online" if query.internet else "offline"
|
58 |
-
|
59 |
data_format = query.data_format
|
60 |
-
|
61 |
# Combine query with user keywords
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
md_report = together_response(prompt, model=llm_default_medium, SysPrompt=SysPromptMd)
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
# Insert data into database (or other storage)
|
76 |
-
|
77 |
references_html = dict()
|
78 |
for text, url in all_text_with_urls:
|
79 |
references_html[url] = str(md_to_html(text))
|
|
|
55 |
description = query.description
|
56 |
user_id = query.user_id
|
57 |
internet = "online" if query.internet else "offline"
|
58 |
+
sys_prompt_output_format = sys_prompts[internet][query.output_format]
|
59 |
data_format = query.data_format
|
60 |
+
|
61 |
# Combine query with user keywords
|
62 |
+
if query.internet:
|
63 |
+
search_query = query_str
|
64 |
+
|
65 |
+
# Search for relevant URLs
|
66 |
+
urls = search_brave(search_query, num_results=4)
|
67 |
|
68 |
+
# Fetch and extract content from the URLs
|
69 |
+
all_text_with_urls = fetch_and_extract_content(data_format, urls, query_str)
|
70 |
|
71 |
+
# Prepare the prompt for generating the report
|
72 |
+
additional_context = limit_tokens(str(all_text_with_urls))
|
73 |
+
prompt = f"#### COMPLETE THE TASK: {query_str} #### IN THE CONTEXT OF ### CONTEXT: {description} #### ADDITIONAL CONTEXT:{additional_context}"
|
|
|
74 |
|
75 |
+
else:
|
76 |
+
prompt = f"#### COMPLETE THE TASK: {query_str} #### IN THE CONTEXT OF ### CONTEXT: {description}"
|
77 |
+
all_text_with_urls = [("","")]
|
78 |
+
|
79 |
+
md_report = together_response(prompt, model=llm_default_medium, SysPrompt=sys_prompt_output_format)
|
80 |
+
|
81 |
# Insert data into database (or other storage)
|
82 |
+
insert_data(user_id, query_str, description, str(all_text_with_urls), md_report)
|
83 |
references_html = dict()
|
84 |
for text, url in all_text_with_urls:
|
85 |
references_html[url] = str(md_to_html(text))
|