Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -59,25 +59,28 @@ async def generate_report(request: Request, query: QueryModel):
|
|
59 |
query_str = query.topic
|
60 |
description = query.description
|
61 |
user_id = query.user_id
|
62 |
-
internet =
|
63 |
sys_prompt_output_format = sys_prompts[internet][query.output_format]
|
64 |
data_format = query.data_format
|
65 |
|
66 |
# Combine query with user keywords
|
67 |
-
if
|
68 |
search_query = description
|
69 |
# Search for relevant URLs
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
81 |
all_text_with_urls = [("","")]
|
82 |
|
83 |
md_report = together_response(prompt, model=llm_default_medium, SysPrompt=sys_prompt_output_format)
|
|
|
59 |
query_str = query.topic
|
60 |
description = query.description
|
61 |
user_id = query.user_id
|
62 |
+
internet = query.internet
|
63 |
sys_prompt_output_format = sys_prompts[internet][query.output_format]
|
64 |
data_format = query.data_format
|
65 |
|
66 |
# Combine query with user keywords
|
67 |
+
if internet:
|
68 |
search_query = description
|
69 |
# Search for relevant URLs
|
70 |
+
try:
|
71 |
+
urls = search_brave(search_query, num_results=4)
|
72 |
+
# Fetch and extract content from the URLs
|
73 |
+
all_text_with_urls = fetch_and_extract_content(data_format, urls, query_str)
|
74 |
+
# Prepare the prompt for generating the report
|
75 |
+
additional_context = limit_tokens(str(all_text_with_urls))
|
76 |
+
prompt = f"#### COMPLETE THE TASK: {description} #### IN THE CONTEXT OF ### CONTEXT: {query_str} USING THE #### SCRAPED DATA:{additional_context}"
|
77 |
+
|
78 |
+
except Exception as e:
|
79 |
+
internet = False
|
80 |
+
print("failed to search/scrape results, falling back to LLM response")
|
81 |
+
|
82 |
+
if not internet:
|
83 |
+
prompt = f"#### COMPLETE THE TASK: {description} #### IN THE CONTEXT OF ### CONTEXT: {query_str}"
|
84 |
all_text_with_urls = [("","")]
|
85 |
|
86 |
md_report = together_response(prompt, model=llm_default_medium, SysPrompt=sys_prompt_output_format)
|