Spaces:
Sleeping
Sleeping
James MacQuillan
commited on
Commit
·
f63a79e
1
Parent(s):
1adeb8a
push
Browse files- app.py +31 -2
- healthcheck.txt +4 -0
- search_requirements.txt +8 -0
app.py
CHANGED
@@ -37,7 +37,29 @@ BOT_AVATAR = 'https://automatedstockmining.org/wp-content/uploads/2024/08/south-
|
|
37 |
|
38 |
|
39 |
|
|
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
|
43 |
|
@@ -156,12 +178,19 @@ def process_query(user_input, history):
|
|
156 |
# Retrieve and concatenate results
|
157 |
retrieved_texts = " ".join([doc.page_content for doc in docs])
|
158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
yield 'Preparing your request 🛠️'
|
160 |
|
161 |
# Step 1: Generate a search term based on the user query
|
162 |
stream_search = client.chat_completion(
|
163 |
model="Qwen/Qwen2.5-72B-Instruct",
|
164 |
-
messages=[{"role": "user", "content": f"Based on this chat history {history}
|
165 |
max_tokens=400,
|
166 |
stream=True
|
167 |
)
|
@@ -184,7 +213,7 @@ def process_query(user_input, history):
|
|
184 |
# Step 3: Generate a response using the search results
|
185 |
response = client.chat_completion(
|
186 |
model="Qwen/Qwen2.5-72B-Instruct",
|
187 |
-
messages=[{"role": "user", "content": f"Using the search results: {search_results_str} and chat history {history}, this vector database on health checks {retrieved_texts} answer the user's query '{user_input}' in a concise, precise way, using numerical data if available. ONLY GIVE ONE RESPONSE BACK, CONCISE OR DETAILED BASED ON THE USERS INPUT
|
188 |
max_tokens=3000,
|
189 |
stream=True
|
190 |
)
|
|
|
37 |
|
38 |
|
39 |
|
40 |
+
#for the search vector database
|
41 |
|
42 |
+
# Initialize Chroma vector store directory
|
43 |
+
db_name2 = "search_checkvector_db"
|
44 |
+
|
45 |
+
# Read in the text for processing
|
46 |
+
health_check_text = ''
|
47 |
+
with open('search_requirements.txt', 'r', encoding='utf-8') as search_text:
|
48 |
+
search_requirements_text = search_text.read()
|
49 |
+
|
50 |
+
# Split text into chunks
|
51 |
+
search_splitter = CharacterTextSplitter(chunk_size=20, chunk_overlap=2)
|
52 |
+
parts = search_splitter.split_text(search_requirements_text)
|
53 |
+
|
54 |
+
|
55 |
+
search_documents = [Document(page_content=chunk) for chunk in chunks]
|
56 |
+
|
57 |
+
# Initialize Chroma with documents and embeddings
|
58 |
+
search_vectorstore = Chroma.from_documents(
|
59 |
+
documents=search_documents,
|
60 |
+
embedding=embedding_model,
|
61 |
+
persist_directory=db_name
|
62 |
+
)
|
63 |
|
64 |
|
65 |
|
|
|
178 |
# Retrieve and concatenate results
|
179 |
retrieved_texts = " ".join([doc.page_content for doc in docs])
|
180 |
|
181 |
+
|
182 |
+
#similarity search on searches
|
183 |
+
searches = search_vectorstore.similarity_search(user_input, k=3)
|
184 |
+
|
185 |
+
# Retrieve and concatenate results
|
186 |
+
search_texts = " ".join([doc.page_content for doc in searches])
|
187 |
+
|
188 |
yield 'Preparing your request 🛠️'
|
189 |
|
190 |
# Step 1: Generate a search term based on the user query
|
191 |
stream_search = client.chat_completion(
|
192 |
model="Qwen/Qwen2.5-72B-Instruct",
|
193 |
+
messages=[{"role": "user", "content": f"Based on this chat history {history} the user's request '{user_input}', and this vector database {search_texts}, suggest a Google search term in a single line without specific dates; use 'this year', 'this month', etc. INCLUDE NOTHING IN YOUR RESPONSE EXCEPT THE RELEVANT SEARCH RESULT. EXAMPLE: USER: WHAT IS THE CURRENT PRICE OF COCA COLA STOCK. YOUR RESPONSE: WHAT IS THE CURRENT PRICE OF COCA COLA STOCK"}],
|
194 |
max_tokens=400,
|
195 |
stream=True
|
196 |
)
|
|
|
213 |
# Step 3: Generate a response using the search results
|
214 |
response = client.chat_completion(
|
215 |
model="Qwen/Qwen2.5-72B-Instruct",
|
216 |
+
messages=[{"role": "user", "content": f"Using the search results: {search_results_str} and chat history {history}, this vector database on health checks {retrieved_texts} answer the user's query '{user_input}' in a concise, precise way, using numerical data if available. ONLY GIVE ONE RESPONSE BACK, CONCISE OR DETAILED BASED ON THE USERS INPUT"}],
|
217 |
max_tokens=3000,
|
218 |
stream=True
|
219 |
)
|
healthcheck.txt
CHANGED
@@ -166,3 +166,7 @@ you will return:
|
|
166 |
A QuantiNeuron Health Check Score on a 1-10 scale.
|
167 |
A Health Summary, outlining strengths and weaknesses based on metrics.
|
168 |
A Recommendation Statement, if necessary, for areas needing attention.
|
|
|
|
|
|
|
|
|
|
166 |
A QuantiNeuron Health Check Score on a 1-10 scale.
|
167 |
A Health Summary, outlining strengths and weaknesses based on metrics.
|
168 |
A Recommendation Statement, if necessary, for areas needing attention.
|
169 |
+
|
170 |
+
|
171 |
+
SMART SHEET OBJECTIVE:
|
172 |
+
ANALYSE THE NEWS BROUGHT IN ON THE TOPIC IN IMMENSE DETAIL, ANALYSING EVERYTHING AND SIMULATING POSSIBLE OUTCOMES(WHERE NECCESSARY), EXPLAIN THE IMPLICATIONS OF THE NEWS AND WHAT MAY HAPPEN BECAUSE OF IT, ANALYSE IT IN DEPTH.
|
search_requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
OBJECTIVE:
|
2 |
+
you produce searches based on the users query.
|
3 |
+
|
4 |
+
WHEN THE USER ASKS FOR A HEALTH CHECK:
|
5 |
+
search for the latest metrics on the company
|
6 |
+
|
7 |
+
WHEN THE USER ASKS FOR A SMART SHEET:
|
8 |
+
search for the latest news on the event
|