pvanand commited on
Commit
e9b52b9
1 Parent(s): 54775b1

Update helper_functions_api.py

Browse files
Files changed (1) hide show
  1. helper_functions_api.py +11 -6
helper_functions_api.py CHANGED
@@ -72,6 +72,12 @@ llm_default_medium = "meta-llama/Llama-3-70b-chat-hf"
72
 
73
  SysPromptData = "You are an information retriever and summarizer, return only the factual information regarding the user query"
74
  SysPromptDefault = "You are an expert AI, complete the given task. Do not add any additional comments."
 
 
 
 
 
 
75
 
76
  import tiktoken # Used to limit tokens
77
  encoding = tiktoken.encoding_for_model("gpt-3.5-turbo") # Instead of Llama3 using available option/ replace if found anything better
@@ -214,12 +220,11 @@ def fetch_and_extract_content(data_format, urls, query):
214
  return all_text_with_urls
215
 
216
 
 
217
  def search_brave(query, num_results=5):
218
-
 
 
219
  brave = Brave(BRAVE_API_KEY)
220
-
221
- search_results = brave.search(q=query, count=num_results)
222
-
223
  return [url.__str__() for url in search_results.urls]
224
-
225
-
 
72
 
73
  SysPromptData = "You are an information retriever and summarizer, return only the factual information regarding the user query"
74
  SysPromptDefault = "You are an expert AI, complete the given task. Do not add any additional comments."
75
+ SysPromptSearch = """You are a search query generator, create a concise Google search query, focusing only on the main topic and omitting additional redundant details, include year if necessory, 2024, Do not add any additional comments. OUTPUT ONLY THE SEARCH QUERY
76
+ #Additional instructions:
77
+ ##Use the following search operators if necessory
78
+ OR #to cover multiple topics
79
+ * #wildcard to match any word or phrase
80
+ AND #to include specific topics."""
81
 
82
  import tiktoken # Used to limit tokens
83
  encoding = tiktoken.encoding_for_model("gpt-3.5-turbo") # Instead of Llama3 using available option/ replace if found anything better
 
220
  return all_text_with_urls
221
 
222
 
223
+ @retry(tries=3, delay=0.25)
224
  def search_brave(query, num_results=5):
225
+ cleaned_query = re.sub(r'[^a-zA-Z0-9]+', '', query)
226
+ search_query = together_response(cleaned_query, model=llm_default_small, SysPrompt=SysPromptSearch, max_tokens = 25).strip()
227
+ cleaned_search_query = re.sub(r'[^a-zA-Z0-9*]+', '', search_query)
228
  brave = Brave(BRAVE_API_KEY)
229
+ search_results = brave.search(q=cleaned_search_query, count=num_results)
 
 
230
  return [url.__str__() for url in search_results.urls]