pvanand commited on
Commit
7a5d35d
1 Parent(s): 2400edf

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -13
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 = "online" if query.internet else "offline"
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 query.internet:
68
  search_query = description
69
  # Search for relevant URLs
70
- urls = search_brave(search_query, num_results=4)
71
-
72
- # Fetch and extract content from the URLs
73
- all_text_with_urls = fetch_and_extract_content(data_format, urls, query_str)
74
-
75
- # Prepare the prompt for generating the report
76
- additional_context = limit_tokens(str(all_text_with_urls))
77
- prompt = f"#### COMPLETE THE TASK: {description} #### IN THE CONTEXT OF ### CONTEXT: {query_str} USING THE #### SCRAPED DATA:{additional_context}"
78
-
79
- else:
80
- prompt = f"#### COMPLETE THE TASK: {query_str} #### IN THE CONTEXT OF ### CONTEXT: {description}"
 
 
 
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)