Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -115,31 +115,55 @@ client= InferenceClient("openai/gpt-oss-20b")
|
|
| 115 |
|
| 116 |
information=""
|
| 117 |
|
| 118 |
-
def respond(message,history):
|
| 119 |
topic_chunks = []
|
| 120 |
-
if
|
| 121 |
topic_chunks = get_top_chunks(message, charity_embeddings, cleaned_charities)
|
| 122 |
-
elif
|
| 123 |
-
topic_chunks = get_top_chunks(message,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
|
| 126 |
#return information
|
| 127 |
#return topic_chunks
|
| 128 |
-
chatbot_mode=="Advice Mode"
|
| 129 |
-
messages = [{"role": "assistant", "content": f"You are a helpful and insightful chatbot who acts like a financial advisor of a university student who wants to learn to manage their personal finances. You analyse their situation and give relevant advice and insights. You only answer in complete sentences with correct grammar, punctuation, and complete ideas. You respond clearly in under five complete bullet points under 500 characters. When you give advice, keep in mind the following information {topic_chunks}"}]
|
| 130 |
-
|
| 131 |
-
if chatbot_mode == "Advice Mode":
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
|
| 138 |
-
|
| 139 |
|
| 140 |
-
response=client.chat_completion(messages, temperature=0.2)#capping how many words the LLM is allowed to generate as a respond (100 words)
|
| 141 |
|
| 142 |
-
return response['choices'][0]['message']['content'].strip() #storing value of response in a readable format to display
|
| 143 |
|
| 144 |
### STEP 6
|
| 145 |
# Call the preprocess_text function and store the result in a cleaned_chunks variable
|
|
|
|
| 115 |
|
| 116 |
information=""
|
| 117 |
|
| 118 |
+
def respond(message, history, chatbot_topic_values, chatbot_mode_values):
|
| 119 |
topic_chunks = []
|
| 120 |
+
if chatbot_topic_values and "Helping Charities" in chatbot_topic_values:
|
| 121 |
topic_chunks = get_top_chunks(message, charity_embeddings, cleaned_charities)
|
| 122 |
+
elif chatbot_topic_values and "Financial Aid" in chatbot_topic_values:
|
| 123 |
+
topic_chunks = get_top_chunks(message, finance_embeddings2, cleaned_finance)
|
| 124 |
+
|
| 125 |
+
if chatbot_mode_values and "Advice Mode" in chatbot_mode_values:
|
| 126 |
+
role_message = (
|
| 127 |
+
"You are a helpful and insightful chatbot who acts like a financial "
|
| 128 |
+
"advisor of a university student. Respond in under five bullet points, "
|
| 129 |
+
f"under 500 characters, using this context: {topic_chunks}"
|
| 130 |
+
)
|
| 131 |
+
else:
|
| 132 |
+
role_message = f"You are a helpful chatbot. Use this context: {topic_chunks}"
|
| 133 |
+
|
| 134 |
+
messages = [{"role": "assistant", "content": role_message}]
|
| 135 |
+
if history:
|
| 136 |
+
messages.extend(history)
|
| 137 |
+
messages.append({"role": "user", "content": message})
|
| 138 |
+
|
| 139 |
+
response = client.chat_completion(messages, temperature=0.2)
|
| 140 |
+
return response['choices'][0]['message']['content'].strip()
|
| 141 |
+
|
| 142 |
+
#def respond(message,history):
|
| 143 |
+
# topic_chunks = []
|
| 144 |
+
# if chatbot_topic and "Helping Charities" in chatbot_topic:
|
| 145 |
+
# topic_chunks = get_top_chunks(message, charity_embeddings, cleaned_charities)
|
| 146 |
+
#elif chatbot_topic and "Financial Aid" in chatbot_topic:
|
| 147 |
+
# topic_chunks = get_top_chunks(message, finance_embeddings, cleaned_finance)
|
| 148 |
|
| 149 |
|
| 150 |
#return information
|
| 151 |
#return topic_chunks
|
| 152 |
+
#chatbot_mode=="Advice Mode"
|
| 153 |
+
#messages = [{"role": "assistant", "content": f"You are a helpful and insightful chatbot who acts like a financial advisor of a university student who wants to learn to manage their personal finances. You analyse their situation and give relevant advice and insights. You only answer in complete sentences with correct grammar, punctuation, and complete ideas. You respond clearly in under five complete bullet points under 500 characters. When you give advice, keep in mind the following information {topic_chunks}"}]
|
| 154 |
+
|
| 155 |
+
# if chatbot_mode == "Advice Mode":
|
| 156 |
+
# role_message = ( "You are a helpful and insightful chatbot who acts like a financial " "advisor of a university student. Respond in under five bullet points, " f"under 500 characters, using this context: {topic_chunks}" )
|
| 157 |
+
# else: role_message = f"You are a helpful chatbot. Use this context: {topic_chunks}"
|
| 158 |
+
#
|
| 159 |
+
# if history:
|
| 160 |
+
# messages.extend(history) #keep adding history
|
| 161 |
|
| 162 |
+
# messages.append({"role":"user","content": message})
|
| 163 |
|
| 164 |
+
#response=client.chat_completion(messages, temperature=0.2)#capping how many words the LLM is allowed to generate as a respond (100 words)
|
| 165 |
|
| 166 |
+
#return response['choices'][0]['message']['content'].strip() #storing value of response in a readable format to display
|
| 167 |
|
| 168 |
### STEP 6
|
| 169 |
# Call the preprocess_text function and store the result in a cleaned_chunks variable
|