Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,14 +19,14 @@ import chainlit as cl
|
|
19 |
from langchain import hub
|
20 |
from langchain.chains import LLMChain, APIChain
|
21 |
from langchain_core.prompts import PromptTemplate
|
22 |
-
|
23 |
from langchain_huggingface import HuggingFaceEndpoint
|
24 |
from langchain.memory.buffer import ConversationBufferMemory
|
25 |
|
26 |
logging.basicConfig(level=logging.DEBUG)
|
27 |
|
28 |
HUGGINGFACEHUB_API_TOKEN = os.environ.get("HUGGINGFACEHUB_API_TOKEN")
|
29 |
-
BOOKING_ID = re.compile(r'\b[A-Z]{6}\d{6}\b')
|
30 |
BOOKING_KEYWORDS = [
|
31 |
"booking",
|
32 |
"bestillingsnummer",
|
@@ -96,7 +96,7 @@ def setup_multiple_chains():
|
|
96 |
huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
|
97 |
#max_new_tokens=512,
|
98 |
temperature=0.7,
|
99 |
-
task="text-generation"
|
100 |
)
|
101 |
|
102 |
conversation_memory = ConversationBufferMemory(memory_key="chat_history",
|
@@ -137,17 +137,18 @@ async def handle_message(message: cl.Message):
|
|
137 |
#booked = is_booking_query(user_message)
|
138 |
#if booked:
|
139 |
|
140 |
-
if re.search(r'\b[A-Z]{6}\d{6}\b', user_message): # ex
|
141 |
-
|
142 |
response = await api_chain.acall(user_message,
|
143 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
144 |
|
145 |
else:
|
146 |
response = await llm_chain.acall(user_message,
|
147 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
148 |
-
|
149 |
-
|
150 |
|
151 |
response_key = "output" if "output" in response else "text"
|
|
|
152 |
await cl.Message(response.get(response_key, "")).send()
|
153 |
return message.content
|
|
|
19 |
from langchain import hub
|
20 |
from langchain.chains import LLMChain, APIChain
|
21 |
from langchain_core.prompts import PromptTemplate
|
22 |
+
from langchain_community.llms import HuggingFaceHub
|
23 |
from langchain_huggingface import HuggingFaceEndpoint
|
24 |
from langchain.memory.buffer import ConversationBufferMemory
|
25 |
|
26 |
logging.basicConfig(level=logging.DEBUG)
|
27 |
|
28 |
HUGGINGFACEHUB_API_TOKEN = os.environ.get("HUGGINGFACEHUB_API_TOKEN")
|
29 |
+
#BOOKING_ID = re.compile(r'\b[A-Z]{6}\d{6}\b')
|
30 |
BOOKING_KEYWORDS = [
|
31 |
"booking",
|
32 |
"bestillingsnummer",
|
|
|
96 |
huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
|
97 |
#max_new_tokens=512,
|
98 |
temperature=0.7,
|
99 |
+
#task="text-generation"
|
100 |
)
|
101 |
|
102 |
conversation_memory = ConversationBufferMemory(memory_key="chat_history",
|
|
|
137 |
#booked = is_booking_query(user_message)
|
138 |
#if booked:
|
139 |
|
140 |
+
if re.search(r'\b[A-Z]{6}\d{6}\b', user_message): # ex. "EQJLCQ362149"
|
141 |
+
|
142 |
response = await api_chain.acall(user_message,
|
143 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
144 |
|
145 |
else:
|
146 |
response = await llm_chain.acall(user_message,
|
147 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
148 |
+
|
149 |
+
|
150 |
|
151 |
response_key = "output" if "output" in response else "text"
|
152 |
+
logging.debug({response}")
|
153 |
await cl.Message(response.get(response_key, "")).send()
|
154 |
return message.content
|