camparchimedes commited on
Commit
bef3e08
Β·
verified Β·
1 Parent(s): 858abfd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -14
app.py CHANGED
@@ -1,5 +1,5 @@
1
  # ===========================================
2
- # title: daysoff-assistant-API-v2
3
  # file: app.py
4
  # ===========================================
5
 
@@ -29,16 +29,26 @@ auth_token = os.environ.get("DAYSOFF_API_TOKEN")
29
 
30
  API_URL = "https://aivisions.no/data/daysoff/api/v1/booking/"
31
 
 
 
 
 
 
 
 
32
  daysoff_assistant_template = """
33
  You are a customer support assistant for Daysoff kundeservice and help users retrieve booking information associated with their booking IDs.
34
  By default, you respond using Norwegian bokmΓ₯l.
35
  Provide a conversational answer.
36
  This way you directly address the user's question in a manner that reflects the professionalism and warmth
37
  of a customer support representative (female).
 
38
  Chat History: {chat_history}
39
  Question: {question}
40
- Answer:
 
41
  """
 
42
  daysoff_assistant_prompt = PromptTemplate(
43
  input_variables=["chat_history", "question"],
44
  template=daysoff_assistant_template,
@@ -48,6 +58,30 @@ daysoff_assistant_prompt = PromptTemplate(
48
  async def async_post_request(url, headers, data):
49
  return await asyncio.to_thread(requests.post, url, headers=headers, json=data)
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  @cl.on_chat_start
53
  def setup_multiple_chains():
@@ -100,29 +134,37 @@ async def handle_message(message: cl.Message):
100
  if "booking_id" in booking_data:
101
  try:
102
  # --markdown_table
103
- table = (
104
  "| π‘­π’Šπ’†π’π’… | π—œπ—»π—³π—Ό |\n"
105
  "|:-----------|:---------------------|\n"
106
- f"| π™±πšŽπšœπšπš’πš•πš•πš’πš—πšπšœπš”πš˜πšπšŽ | {booking_data.get('booking_id', 'N/A')} |\n"
107
- f"| 𝙁π™ͺ𝙑𝙑 π™‰π™–π™’π™š | {booking_data.get('full_name', 'N/A')} |\n"
108
- f"| π˜Όπ™’π™€π™ͺ𝙣𝙩 | {booking_data.get('amount', 0)} kr |\n"
109
- f"| π˜Ύπ™π™šπ™˜π™ -π™žπ™£ | {booking_data.get('checkin', 'N/A')} |\n"
110
- f"| π˜Ύπ™π™šπ™˜π™ -𝙀π™ͺ𝙩 | {booking_data.get('checkout', 'N/A')} |\n"
111
- f"| π˜Όπ™™π™™π™§π™šπ™¨π™¨ | {booking_data.get('address', 'N/A')} |\n"
112
- f"| π™π™¨π™šπ™§ π™„π˜Ώ | {booking_data.get('user_id', 0)} |\n"
113
- f"| 𝙄𝙣𝙛𝙀 π™π™šπ™­π™© | {booking_data.get('infotext', 'N/A')} |\n"
114
- f"| π™„π™£π™˜π™‘π™ͺπ™™π™šπ™™ | {booking_data.get('included', 'N/A')} |"
115
  )
116
 
 
 
 
 
 
 
 
 
117
  # --send both as combined_message
118
- combined_message = f"### Informasjon for Bestillingskode:\n\n{table}"
119
  await cl.Message(content=combined_message).send()
120
 
121
  except Exception as e:
122
  await cl.Message(content=f"Error processing booking data: {str(e)}").send()
123
 
124
  else:
125
- await cl.Message(content="Booking not found").send()
126
 
127
  except requests.exceptions.RequestException as e:
128
  await cl.Message(content=f"Request failed: {str(e)}").send()
 
1
  # ===========================================
2
+ # title: daysoff-assistant-API-v2, table
3
  # file: app.py
4
  # ===========================================
5
 
 
29
 
30
  API_URL = "https://aivisions.no/data/daysoff/api/v1/booking/"
31
 
32
+ #If booking information is requested, and with
33
+ #retrieved booking information: {table} in mind, provide a conversational answer.
34
+ #If no booking information is requested, provide a conversational answer.
35
+
36
+
37
+
38
+
39
  daysoff_assistant_template = """
40
  You are a customer support assistant for Daysoff kundeservice and help users retrieve booking information associated with their booking IDs.
41
  By default, you respond using Norwegian bokmΓ₯l.
42
  Provide a conversational answer.
43
  This way you directly address the user's question in a manner that reflects the professionalism and warmth
44
  of a customer support representative (female).
45
+ ============================
46
  Chat History: {chat_history}
47
  Question: {question}
48
+ ============================
49
+ Answer in Markdown:
50
  """
51
+
52
  daysoff_assistant_prompt = PromptTemplate(
53
  input_variables=["chat_history", "question"],
54
  template=daysoff_assistant_template,
 
58
  async def async_post_request(url, headers, data):
59
  return await asyncio.to_thread(requests.post, url, headers=headers, json=data)
60
 
61
+ @cl.set_starters
62
+ async def set_starters():
63
+ return [
64
+ cl.Starter(
65
+ label="Booking ID request",
66
+ message="Kan du gi meg info om en reservasjon?",
67
+ icon="/public/booking_id.svg",
68
+ ),
69
+ cl.Starter(
70
+ label="Metric Space Self-Identity Framework",
71
+ message="Explain the Metric Space Self-Identity Framework like I'm five years old.",
72
+ icon="/public/learn.svg",
73
+ ),
74
+ cl.Starter(
75
+ label="Python script for daily email reports",
76
+ message="Write a script to automate sending daily email reports in Python, and walk me through how I would set it up.",
77
+ icon="/public/terminal.svg",
78
+ ),
79
+ cl.Starter(
80
+ label="Morning routine ideation",
81
+ message="Can you help me create a personalized Yoga/pranayama/meditation morning routine that would help increase my productivity throughout the day? Start by asking me about my current habits and what activities energize me in the morning.",
82
+ icon="/public/idea.svg",
83
+ )
84
+ ]
85
 
86
  @cl.on_chat_start
87
  def setup_multiple_chains():
 
134
  if "booking_id" in booking_data:
135
  try:
136
  # --markdown_table
137
+ #table = (
138
  "| π‘­π’Šπ’†π’π’… | π—œπ—»π—³π—Ό |\n"
139
  "|:-----------|:---------------------|\n"
140
+ #f"| π™±πšŽπšœπšπš’πš•πš•πš’πš—πšπšœπš”πš˜πšπšŽ | {booking_data.get('booking_id', 'N/A')} |\n"
141
+ #f"| 𝙁π™ͺ𝙑𝙑 π™‰π™–π™’π™š | {booking_data.get('full_name', 'N/A')} |\n"
142
+ #f"| π˜Όπ™’π™€π™ͺ𝙣𝙩 | {booking_data.get('amount', 0)} kr |\n"
143
+ #f"| π˜Ύπ™π™šπ™˜π™ -π™žπ™£ | {booking_data.get('checkin', 'N/A')} |\n"
144
+ #f"| π˜Ύπ™π™šπ™˜π™ -𝙀π™ͺ𝙩 | {booking_data.get('checkout', 'N/A')} |\n"
145
+ #f"| π˜Όπ™™π™™π™§π™šπ™¨π™¨ | {booking_data.get('address', 'N/A')} |\n"
146
+ #f"| π™π™¨π™šπ™§ π™„π˜Ώ | {booking_data.get('user_id', 0)} |\n"
147
+ #f"| 𝙄𝙣𝙛𝙀 π™π™šπ™­π™© | {booking_data.get('infotext', 'N/A')} |\n"
148
+ #f"| π™„π™£π™˜π™‘π™ͺπ™™π™šπ™™ | {booking_data.get('included', 'N/A')} |"
149
  )
150
 
151
+ # --invoke LLM w/ table + user_message
152
+ response = await llm_chain.ainvoke({
153
+ #"table": table,
154
+ "booking_data": booking_data,
155
+ "question": user_message,
156
+ "chat_history": ""
157
+ }, callbacks=[cl.AsyncLangchainCallbackHandler()])
158
+
159
  # --send both as combined_message
160
+ #combined_message = f"### Informasjon for Bestillingskode:\n\n{table}"
161
  await cl.Message(content=combined_message).send()
162
 
163
  except Exception as e:
164
  await cl.Message(content=f"Error processing booking data: {str(e)}").send()
165
 
166
  else:
167
+ await cl.Message(content="Booking not found or invalid response.").send()
168
 
169
  except requests.exceptions.RequestException as e:
170
  await cl.Message(content=f"Request failed: {str(e)}").send()