Update app.py
Browse files
app.py
CHANGED
|
@@ -4,14 +4,22 @@
|
|
| 4 |
# file: app.py
|
| 5 |
# ===================================================================================================
|
| 6 |
|
| 7 |
-
import json
|
| 8 |
-
import asyncio
|
| 9 |
import os
|
| 10 |
import re
|
| 11 |
-
import
|
|
|
|
| 12 |
import requests
|
|
|
|
|
|
|
|
|
|
| 13 |
from dotenv import load_dotenv
|
|
|
|
| 14 |
import chainlit as cl
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
from langchain import hub
|
| 16 |
from langchain_openai import OpenAI
|
| 17 |
from langchain.chains import LLMChain
|
|
@@ -19,8 +27,6 @@ from langchain_core.prompts import PromptTemplate
|
|
| 19 |
from langchain.memory.buffer import ConversationBufferMemory
|
| 20 |
|
| 21 |
|
| 22 |
-
from concurrent.futures import ThreadPoolExecutor
|
| 23 |
-
|
| 24 |
load_dotenv()
|
| 25 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 26 |
auth_token = os.environ.get("DAYSOFF_API_TOKEN")
|
|
@@ -81,7 +87,7 @@ async def set_starters():
|
|
| 81 |
),
|
| 82 |
cl.Starter(
|
| 83 |
label="Metric Space Self-Identity Framework",
|
| 84 |
-
message="Explain the Metric Space Self-Identity Framework like I'm
|
| 85 |
icon="/public/learn.svg",
|
| 86 |
),
|
| 87 |
cl.Starter(
|
|
@@ -131,7 +137,7 @@ async def setup():
|
|
| 131 |
|
| 132 |
cl.user_session.set("llm_chain", llm_chain)
|
| 133 |
|
| 134 |
-
asyncio.create_task(keep_alive())
|
| 135 |
|
| 136 |
|
| 137 |
async def long_running_task(message_content: str):
|
|
@@ -152,7 +158,7 @@ async def handle_message(message: cl.Message):
|
|
| 152 |
|
| 153 |
try:
|
| 154 |
if not cl.user_session.get("socket_auth"):
|
| 155 |
-
await cl.Message(content="Session authentication failed
|
| 156 |
return
|
| 157 |
|
| 158 |
user_message = message.content
|
|
@@ -182,7 +188,7 @@ async def handle_message(message: cl.Message):
|
|
| 182 |
booking_data = response.json()
|
| 183 |
|
| 184 |
if not booking_data:
|
| 185 |
-
raise BookingNotFoundError("
|
| 186 |
|
| 187 |
if "error" in booking_data:
|
| 188 |
raise APIResponseError(booking_data["error"])
|
|
@@ -231,7 +237,7 @@ async def handle_message(message: cl.Message):
|
|
| 231 |
error_messages = {
|
| 232 |
APIConnectionError: "Kunne ikke koble til bookingsystemet. Prรธv igjen senere.",
|
| 233 |
APIResponseError: "Det oppstod en feil ved henting av bookingdata.",
|
| 234 |
-
BookingNotFoundError: "Ingen
|
| 235 |
}
|
| 236 |
await cl.Message(content=f"โ {error_messages[type(e)]}\n\nPrรธv igjen, kanskje du feilstavet eller glemte ett siffer eller en bokstav?\n\nHvis du ser denne feilmedlingen gjentatte ganger, vennligst kontakt kundeservice@daysoff.no sรฅ de kan hjelpe deg.").send()
|
| 237 |
return None
|
|
|
|
| 4 |
# file: app.py
|
| 5 |
# ===================================================================================================
|
| 6 |
|
|
|
|
|
|
|
| 7 |
import os
|
| 8 |
import re
|
| 9 |
+
import json
|
| 10 |
+
import asyncio
|
| 11 |
import requests
|
| 12 |
+
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
from datetime import datetime
|
| 15 |
from dotenv import load_dotenv
|
| 16 |
+
|
| 17 |
import chainlit as cl
|
| 18 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 19 |
+
|
| 20 |
+
from chainlit import user_session
|
| 21 |
+
from chainlit.session import WebsocketSession
|
| 22 |
+
|
| 23 |
from langchain import hub
|
| 24 |
from langchain_openai import OpenAI
|
| 25 |
from langchain.chains import LLMChain
|
|
|
|
| 27 |
from langchain.memory.buffer import ConversationBufferMemory
|
| 28 |
|
| 29 |
|
|
|
|
|
|
|
| 30 |
load_dotenv()
|
| 31 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 32 |
auth_token = os.environ.get("DAYSOFF_API_TOKEN")
|
|
|
|
| 87 |
),
|
| 88 |
cl.Starter(
|
| 89 |
label="Metric Space Self-Identity Framework",
|
| 90 |
+
message="Explain the Metric Space Self-Identity Framework like I'm six years old.",
|
| 91 |
icon="/public/learn.svg",
|
| 92 |
),
|
| 93 |
cl.Starter(
|
|
|
|
| 137 |
|
| 138 |
cl.user_session.set("llm_chain", llm_chain)
|
| 139 |
|
| 140 |
+
#asyncio.create_task(keep_alive())
|
| 141 |
|
| 142 |
|
| 143 |
async def long_running_task(message_content: str):
|
|
|
|
| 158 |
|
| 159 |
try:
|
| 160 |
if not cl.user_session.get("socket_auth"):
|
| 161 |
+
await cl.Message(content="Session authentication failed โโโโ> refresh the page.").send()
|
| 162 |
return
|
| 163 |
|
| 164 |
user_message = message.content
|
|
|
|
| 188 |
booking_data = response.json()
|
| 189 |
|
| 190 |
if not booking_data:
|
| 191 |
+
raise BookingNotFoundError("Ingen booking informasjon ble funnet.")
|
| 192 |
|
| 193 |
if "error" in booking_data:
|
| 194 |
raise APIResponseError(booking_data["error"])
|
|
|
|
| 237 |
error_messages = {
|
| 238 |
APIConnectionError: "Kunne ikke koble til bookingsystemet. Prรธv igjen senere.",
|
| 239 |
APIResponseError: "Det oppstod en feil ved henting av bookingdata.",
|
| 240 |
+
BookingNotFoundError: "Ingen informasjon ble funnet med dette bookingnummeret."
|
| 241 |
}
|
| 242 |
await cl.Message(content=f"โ {error_messages[type(e)]}\n\nPrรธv igjen, kanskje du feilstavet eller glemte ett siffer eller en bokstav?\n\nHvis du ser denne feilmedlingen gjentatte ganger, vennligst kontakt kundeservice@daysoff.no sรฅ de kan hjelpe deg.").send()
|
| 243 |
return None
|