Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,30 +32,30 @@ daysoff_assistant_booking_prompt= PromptTemplate(
|
|
32 |
|
33 |
api_url_template = """
|
34 |
Given the following API Documentation for Daysoff's official
|
35 |
-
booking information API: {
|
36 |
Your task is to construct the most efficient API URL to answer
|
37 |
the user's question, ensuring the
|
38 |
call is optimized to include only the necessary information.
|
39 |
Question: {question}
|
40 |
"""
|
41 |
-
api_url_prompt = PromptTemplate(input_variables=['
|
42 |
template=api_url_template)
|
43 |
|
44 |
api_response_template = """"
|
45 |
-
With the API Documentation for Daysoff's official API: {
|
46 |
and the specific user question: {question} in mind,
|
47 |
-
and given this API URL: {
|
48 |
-
response from Daysoff's API: {
|
49 |
Please provide user with their booking information,
|
50 |
focusing on delivering the answer with clarity and conciseness,
|
51 |
as if a human customer service agent is providing this information.
|
52 |
Adapt to user's language. By default, you speak Norwegian.
|
53 |
Booking information:
|
54 |
"""
|
55 |
-
api_response_prompt = PromptTemplate(input_variables=['
|
56 |
'question',
|
57 |
-
'
|
58 |
-
'
|
59 |
template=api_response_template)
|
60 |
|
61 |
@cl.on_chat_start
|
@@ -73,9 +73,9 @@ def setup_multiple_chains():
|
|
73 |
|
74 |
cl.user_session.set("llm_chain", llm_chain)
|
75 |
|
76 |
-
api_chain = APIChain(
|
77 |
llm=llm,
|
78 |
-
|
79 |
api_url_prompt=api_url_prompt,
|
80 |
api_response_prompt=api_response_prompt,
|
81 |
verbose=True,
|
@@ -113,7 +113,11 @@ async def handle_message(message: cl.Message):
|
|
113 |
re.search(keyword, user_message, re.IGNORECASE)
|
114 |
for keyword in BOOKING_KEYWORDS + [BOOKING_ID]
|
115 |
)
|
|
|
|
|
|
|
116 |
|
|
|
117 |
if is_booking_query:
|
118 |
response = await api_chain.acall(user_message,
|
119 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
|
|
32 |
|
33 |
api_url_template = """
|
34 |
Given the following API Documentation for Daysoff's official
|
35 |
+
booking information API: {daysoff_api_docs}
|
36 |
Your task is to construct the most efficient API URL to answer
|
37 |
the user's question, ensuring the
|
38 |
call is optimized to include only the necessary information.
|
39 |
Question: {question}
|
40 |
"""
|
41 |
+
api_url_prompt = PromptTemplate(input_variables=['daysoff_api_docs', 'question'],
|
42 |
template=api_url_template)
|
43 |
|
44 |
api_response_template = """"
|
45 |
+
With the API Documentation for Daysoff's official API: {daysoff_api_docs}
|
46 |
and the specific user question: {question} in mind,
|
47 |
+
and given this API URL: {base_url} for querying, here is the
|
48 |
+
response from Daysoff's API: {response}.
|
49 |
Please provide user with their booking information,
|
50 |
focusing on delivering the answer with clarity and conciseness,
|
51 |
as if a human customer service agent is providing this information.
|
52 |
Adapt to user's language. By default, you speak Norwegian.
|
53 |
Booking information:
|
54 |
"""
|
55 |
+
api_response_prompt = PromptTemplate(input_variables=['daysoff_api_docs',
|
56 |
'question',
|
57 |
+
'base_url',
|
58 |
+
'response'],
|
59 |
template=api_response_template)
|
60 |
|
61 |
@cl.on_chat_start
|
|
|
73 |
|
74 |
cl.user_session.set("llm_chain", llm_chain)
|
75 |
|
76 |
+
api_chain = APIChain.from_llm_and_api_docs(
|
77 |
llm=llm,
|
78 |
+
api_docs=daysoff_api_docs,
|
79 |
api_url_prompt=api_url_prompt,
|
80 |
api_response_prompt=api_response_prompt,
|
81 |
verbose=True,
|
|
|
113 |
re.search(keyword, user_message, re.IGNORECASE)
|
114 |
for keyword in BOOKING_KEYWORDS + [BOOKING_ID]
|
115 |
)
|
116 |
+
"""
|
117 |
+
match = re.search(r'\b[A-Z]{6}\d{6}\b', user_message)
|
118 |
+
return match.group(0) if match else None
|
119 |
|
120 |
+
"""
|
121 |
if is_booking_query:
|
122 |
response = await api_chain.acall(user_message,
|
123 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|