James MacQuillan commited on
Commit
1067ef6
Β·
1 Parent(s): 20d2697
Files changed (1) hide show
  1. app.py +32 -10
app.py CHANGED
@@ -60,7 +60,7 @@ def search(query):
60
  resp = session.get(
61
  url="https://www.google.com/search",
62
  headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0"},
63
- params={"q": term, "num": 4},
64
  timeout=5
65
  )
66
  resp.raise_for_status()
@@ -89,25 +89,26 @@ def search(query):
89
  print(f"Google search failed: {e}")
90
 
91
  return all_results
92
-
93
  def process_query(user_input, history):
94
 
 
95
  # Accumulate streamed content from the initial request
96
  stream_search = client.chat_completion(
97
  model="Qwen/Qwen2.5-72B-Instruct",
98
- messages=[{"role": "user", "content": f"Based on this chat history {history} and the user's request '{user_input}', suggest a Google search term in a single line without assuming any specific dates (use 'this year', 'this month', etc.)"}],
99
  max_tokens=400,
100
  stream=True
101
  )
102
-
103
  # Accumulate content from the streamed response
104
  streamed_search_query = ""
105
  for chunk in stream_search:
106
  content = chunk.choices[0].delta.content or ''
107
  streamed_search_query += content
108
 
109
- print("Search Query:", streamed_search_query) # Debugging: Check the final search term
110
-
111
  # Perform the web search based on the accumulated query
112
  search_results = search(streamed_search_query)
113
  search_results_str = json.dumps(search_results)
@@ -115,11 +116,11 @@ def process_query(user_input, history):
115
  # Create the response request with HuggingFace using search results
116
  response = client.chat_completion(
117
  model="Qwen/Qwen2.5-72B-Instruct",
118
- messages=[{"role": "user", "content": f"YOU ARE IM.S, AN INVESTMENT CHATBOT BUILT BY automatedstockmining.org. Answer the user's request '{user_input}' using the following information: {search_results_str} and the chat history {history}. Provide a concise, direct answer in no more than 2-3 sentences, with appropriate emojis. If the user asks for a detailed analysis, generate up to 3000 tokens analyzing all trends and patterns."}],
119
  max_tokens=3000,
120
  stream=True
121
  )
122
-
123
  # Accumulate the final response and stream it
124
  final_response = ""
125
  for chunk in response:
@@ -133,9 +134,30 @@ theme = gr.themes.Citrus(
133
  )
134
 
135
  examples = [
136
- ["What's the current price of bitcoin"],
137
  ["What's the latest news on Cisco Systems stock"],
138
- # More examples...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  ]
140
 
141
  chatbot = gr.Chatbot(
 
60
  resp = session.get(
61
  url="https://www.google.com/search",
62
  headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0"},
63
+ params={"q": term, "num": 7},
64
  timeout=5
65
  )
66
  resp.raise_for_status()
 
89
  print(f"Google search failed: {e}")
90
 
91
  return all_results
92
+
93
  def process_query(user_input, history):
94
 
95
+ yield 'Preparing your request πŸ› οΈ'
96
  # Accumulate streamed content from the initial request
97
  stream_search = client.chat_completion(
98
  model="Qwen/Qwen2.5-72B-Instruct",
99
+ messages=[{"role": "user", "content": f"Based on this chat history {history} and the user's request '{user_input}', suggest a Google search term in a single line without assuming any specific dates use 'this year', 'this month', etc. make sure that you do generate a good search based on the query, for example if the user asks 'build a DFCF model for Apple', search up something like 'Apple DFCF model', and if they ask for something like a market cap, just search up what is Apple's current market cap"}],
100
  max_tokens=400,
101
  stream=True
102
  )
103
+ yield 'Generating search term based on your input πŸ”'
104
  # Accumulate content from the streamed response
105
  streamed_search_query = ""
106
  for chunk in stream_search:
107
  content = chunk.choices[0].delta.content or ''
108
  streamed_search_query += content
109
 
110
+
111
+ yield 'Searching the web for relevant information 🌐'
112
  # Perform the web search based on the accumulated query
113
  search_results = search(streamed_search_query)
114
  search_results_str = json.dumps(search_results)
 
116
  # Create the response request with HuggingFace using search results
117
  response = client.chat_completion(
118
  model="Qwen/Qwen2.5-72B-Instruct",
119
+ messages=[{"role": "user", "content": f"YOU ARE AN INVESTMENT CHATBOT . Answer the user's request '{user_input}' using the following information: {search_results} and the chat history {history}. Provide a concise, direct answer in no more than 2-3 sentences, with appropriate emojis. If the user asks for a smart sheet, generate up to 3000 tokens analyzing all trends and patterns as though you are a stock analyst, look for every pattern and form conclusions. IF YOU ARE ASKED TO BUILD MODELS OR LIST STOCKS, USE THE SEARCH DATA TO HELP YOU BUILD THEM AND MAKE SURE YOU ACTUALLY GIVE THE VALUES AND WHAT THE ARTICLE SAYS RATHER THAN JUST SAYING THAT IT IS AVAILABLE FROM THE WEBSITE. unless the user asks for a smart sheet. keep responses short, quick and logical, using the data provided"}],
120
  max_tokens=3000,
121
  stream=True
122
  )
123
+ yield "Analyzing the search results and crafting a response πŸ“Š"
124
  # Accumulate the final response and stream it
125
  final_response = ""
126
  for chunk in response:
 
134
  )
135
 
136
  examples = [
137
+ ["whats the trending social sentiment like for Nvidia"],
138
  ["What's the latest news on Cisco Systems stock"],
139
+ ["Analyze technical indicators for Adobe, are they presenting buy or sell signals"],
140
+ ["Write me a smart sheet on the trending social sentiment and techncial indicators for nvidia"],
141
+ ["What are the best stocks to buy this month"],
142
+ ["What companies report earnings this week"],
143
+ ["What's Apple's current market cap"],
144
+ ["analyse the technical indicators for apple"],
145
+ ["build a DFCF model for Apple"],
146
+ ["Make a table of Apple's stock price for the last 3 days"],
147
+ ['what is Apples PE ratio and how does it compare top other companies in consumer electronics'],
148
+ ['how did salesforce do on its last earnings?'],
149
+ ['what is the average analyst price target for Nvidia'],
150
+ ['whats the outlook for the stock market in 2025'],
151
+ ['when does Nvidia next report earnings'],
152
+ ['what are the latest products from apple'],
153
+ ["What is Tesla's current price-to-earnings ratio and how does it compare to other car manufacturers?"],
154
+ ["List the top 5 performing stocks in the S&P 500 this month"],
155
+ ["What is the dividend yield for Coca-Cola?"],
156
+ ["Which companies in the tech sector are announcing dividends this month?"],
157
+ ["Analyze the latest moving averages for Microsoft; are they indicating a trend reversal?"],
158
+ ["What is the latest guidance on revenue for Meta?"],
159
+ ["What is the current beta of Amazon stock and how does it compare to the industry average?"],
160
+ ["What are the top-rated ETFs for technology exposure this quarter?"]
161
  ]
162
 
163
  chatbot = gr.Chatbot(