Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,9 @@
|
|
1 |
-
|
2 |
-
|
|
|
|
|
|
|
|
|
3 |
|
4 |
import asyncio
|
5 |
import os
|
@@ -107,28 +111,6 @@ def setup_multiple_chains():
|
|
107 |
frequency_penalty=0.5,
|
108 |
presence_penalty=0.3
|
109 |
)
|
110 |
-
|
111 |
-
|
112 |
-
#llm = HuggingFaceEndpoint(
|
113 |
-
#repo_id="google/gemma-2-2b", #"norallm/normistral-7b-warm-instruct",
|
114 |
-
#endpoint_url="http://localhost:8010/",
|
115 |
-
|
116 |
-
#model="google/gemma-2-2b",
|
117 |
-
#max_new_tokens=512,
|
118 |
-
#top_k=10,
|
119 |
-
#top_p=0.95,
|
120 |
-
#typical_p=0.95,
|
121 |
-
#temperature=0.7,
|
122 |
-
#repetition_penalty=1.03,
|
123 |
-
#huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
|
124 |
-
#task="text-generation"
|
125 |
-
#)
|
126 |
-
|
127 |
-
#llm = HuggingFacePipeline.from_model_id(
|
128 |
-
#model_id="normistral-7b-warm-instruct",
|
129 |
-
#task="text-generation",
|
130 |
-
#pipeline_kwargs={"max_new_tokens": 10},
|
131 |
-
#)
|
132 |
|
133 |
conversation_memory = ConversationBufferMemory(memory_key="chat_history",
|
134 |
max_len=300,
|
@@ -147,7 +129,7 @@ def setup_multiple_chains():
|
|
147 |
api_url_prompt=api_url_prompt,
|
148 |
api_response_prompt=api_response_prompt,
|
149 |
verbose=True,
|
150 |
-
limit_to_domains=None
|
151 |
)
|
152 |
|
153 |
cl.user_session.set("api_chain", api_chain)
|
@@ -171,26 +153,11 @@ async def handle_message(message: cl.Message):
|
|
171 |
response = await api_chain.acall(
|
172 |
{
|
173 |
"booking_id": booking_id,
|
174 |
-
"question": question
|
|
|
175 |
},
|
176 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
177 |
|
178 |
-
booking_info = response.get("output", {})
|
179 |
-
|
180 |
-
if booking_info:
|
181 |
-
markdown_response = f"""
|
182 |
-
Informasjon for bestillingskode: {booking_id}
|
183 |
-
|
184 |
-
| Felt | Detaljer |
|
185 |
-
|-----------------|-----------------------------------|
|
186 |
-
| Navn: | {booking_info.get('full_name', 'N/A')} |
|
187 |
-
| Belรธp: | {booking_info.get('amount', 'N/A')} NOK |
|
188 |
-
| Check-In: | {booking_info.get('checkin', 'N/A')} |
|
189 |
-
| Check-Out: | {booking_info.get('checkout', 'N/A')} |
|
190 |
-
| Addresse: | {booking_info.get('address', 'N/A')} |
|
191 |
-
| Bruker ID: | {booking_info.get('user_id', 'N/A')} |
|
192 |
-
"""
|
193 |
-
await cl.Message(content=markdown_response).send()
|
194 |
else:
|
195 |
await cl.Message("Vi kan desverre ikke finne noen informasjon for det oppgitte bookingnummeret.").send()
|
196 |
|
@@ -204,53 +171,3 @@ async def handle_message(message: cl.Message):
|
|
204 |
response_key = "output" if "output" in response else "text"
|
205 |
await cl.Message(response.get(response_key, "")).send()
|
206 |
return message.content
|
207 |
-
|
208 |
-
|
209 |
-
"""
|
210 |
-
@cl.on_message
|
211 |
-
async def handle_message(message: cl.Message):
|
212 |
-
user_message = message.content
|
213 |
-
llm_chain = cl.user_session.get("llm_chain")
|
214 |
-
api_chain = cl.user_session.get("api_chain")
|
215 |
-
|
216 |
-
# api_keywords = ["firmahytteordning", "personvernspolicy"]
|
217 |
-
|
218 |
-
#base_url = "https://670dccd0073307b4ee447f2f.mockapi.io/daysoff/api/V1/booking"
|
219 |
-
#url = f"{base_url}?search={booking_id}"
|
220 |
-
|
221 |
-
try:
|
222 |
-
# --check message for booking ID
|
223 |
-
if re.search(r'\b[A-Z]{6}\d{6}\b', user_message):
|
224 |
-
logging.debug(f"Booking ID detected in message: {user_message}")
|
225 |
-
response = await api_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
226 |
-
|
227 |
-
# --check message for keywords
|
228 |
-
#elif any(keyword in user_message for keyword in ["firmahytteordning", "personvernspolicy"]): # any(keyword in user_message for keyword in api_keywords):
|
229 |
-
#logging.debug(f"API keyword detected in message: {user_message}")
|
230 |
-
#response = await api_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
231 |
-
|
232 |
-
else:
|
233 |
-
logging.debug("Triggers LLMChain for everything else.")
|
234 |
-
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
235 |
-
|
236 |
-
except Exception as e:
|
237 |
-
logging.error(f"Error in processing message: {str(e)}")
|
238 |
-
response = {"output": "Jeg fรฅr desverre ikke hentet fram din informasjon akkurat nรฅ."}
|
239 |
-
|
240 |
-
response_key = "output" if "output" in response else "text"
|
241 |
-
await cl.Message(response.get(response_key, "")).send()
|
242 |
-
return message.content
|
243 |
-
|
244 |
-
"""
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
#def is_booking_query(user_message):
|
250 |
-
#match = re.search(r'\b[A-Z]{6}\d{6}\b', user_message)
|
251 |
-
#return match is not None # --works boolean
|
252 |
-
#booked = is_booking_query(user_message)
|
253 |
-
#if booked:
|
254 |
-
#response = await api_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
255 |
-
# etc..
|
256 |
-
|
|
|
1 |
+
|
2 |
+
# ===========================================
|
3 |
+
# ver2-----app.py
|
4 |
+
# ===========================================
|
5 |
+
|
6 |
+
|
7 |
|
8 |
import asyncio
|
9 |
import os
|
|
|
111 |
frequency_penalty=0.5,
|
112 |
presence_penalty=0.3
|
113 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
conversation_memory = ConversationBufferMemory(memory_key="chat_history",
|
116 |
max_len=300,
|
|
|
129 |
api_url_prompt=api_url_prompt,
|
130 |
api_response_prompt=api_response_prompt,
|
131 |
verbose=True,
|
132 |
+
limit_to_domains=None
|
133 |
)
|
134 |
|
135 |
cl.user_session.set("api_chain", api_chain)
|
|
|
153 |
response = await api_chain.acall(
|
154 |
{
|
155 |
"booking_id": booking_id,
|
156 |
+
"question": question,
|
157 |
+
"url": url
|
158 |
},
|
159 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
else:
|
162 |
await cl.Message("Vi kan desverre ikke finne noen informasjon for det oppgitte bookingnummeret.").send()
|
163 |
|
|
|
171 |
response_key = "output" if "output" in response else "text"
|
172 |
await cl.Message(response.get(response_key, "")).send()
|
173 |
return message.content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|