Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
|
2 |
# ===========================================
|
3 |
-
#
|
4 |
# ===========================================
|
5 |
|
6 |
import asyncio
|
@@ -8,61 +8,35 @@ import os
|
|
8 |
import re
|
9 |
import time
|
10 |
import json
|
11 |
-
import torch
|
12 |
-
|
13 |
-
import logging
|
14 |
-
|
15 |
-
from api_docs_mck import api_docs_str
|
16 |
|
17 |
import chainlit as cl
|
18 |
|
19 |
from langchain import hub
|
|
|
20 |
from langchain.chains import LLMChain, APIChain
|
21 |
from langchain_core.prompts import PromptTemplate
|
22 |
from langchain.memory.buffer import ConversationBufferMemory
|
23 |
|
24 |
-
from
|
25 |
-
|
26 |
-
from
|
27 |
-
from langchain_huggingface import HuggingFacePipeline
|
28 |
-
from langchain_huggingface import HuggingFaceEndpoint
|
29 |
-
from langchain_core.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
30 |
|
31 |
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
|
32 |
-
#HF_INFERENCE_ENDPOINT =
|
33 |
-
#BOOKING_ID = re.compile(r'\b[A-Z]{6}\d{6}\b')
|
34 |
-
#HUGGINGFACEHUB_API_TOKEN = os.environ.get("HUGGINGFACEHUB_API_TOKEN")
|
35 |
-
|
36 |
-
BOOKING_KEYWORDS = [
|
37 |
-
"booking",
|
38 |
-
"bestillingsnummer",
|
39 |
-
"bookingen",
|
40 |
-
"ordrenummer",
|
41 |
-
"reservation",
|
42 |
-
"rezerwacji",
|
43 |
-
"bookingreferanse",
|
44 |
-
"rezerwacja",
|
45 |
-
"booket",
|
46 |
-
"reservation number",
|
47 |
-
"bestilling",
|
48 |
-
"order number",
|
49 |
-
"booking ID",
|
50 |
-
"identyfikacyjny płatności"
|
51 |
-
]
|
52 |
|
53 |
daysoff_assistant_template = """
|
54 |
You are a customer support assistant (’kundeservice AI assistent’) for Daysoff.no
|
55 |
By default, you respond in Norwegian language, using a warm, direct and professional tone.
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
60 |
Chat History: {chat_history}
|
61 |
Question: {question}
|
62 |
Answer:
|
63 |
"""
|
64 |
|
65 |
-
daysoff_assistant_prompt= PromptTemplate(
|
66 |
input_variables=["chat_history", "question"],
|
67 |
template=daysoff_assistant_template
|
68 |
)
|
@@ -79,7 +53,6 @@ API URL:
|
|
79 |
api_url_prompt = PromptTemplate(input_variables=['api_docs', 'question'],
|
80 |
template=api_url_template)
|
81 |
|
82 |
-
# (..) If {question} contains an alphanumeric identifier consisting of 6 letters followed by 6 digits (e.g., DAGHNS116478)
|
83 |
api_response_template = """
|
84 |
With the API Documentation for Daysoff's official API: {api_docs} in mind,
|
85 |
and the specific user question: {question} in mind,
|
@@ -152,7 +125,7 @@ async def handle_message(message: cl.Message):
|
|
152 |
|
153 |
},
|
154 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
155 |
-
|
156 |
else:
|
157 |
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
158 |
|
|
|
1 |
|
2 |
# ===========================================
|
3 |
+
# ver01.01-5.workload-----app.py
|
4 |
# ===========================================
|
5 |
|
6 |
import asyncio
|
|
|
8 |
import re
|
9 |
import time
|
10 |
import json
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
import chainlit as cl
|
13 |
|
14 |
from langchain import hub
|
15 |
+
from langchain_openai import OpenAI
|
16 |
from langchain.chains import LLMChain, APIChain
|
17 |
from langchain_core.prompts import PromptTemplate
|
18 |
from langchain.memory.buffer import ConversationBufferMemory
|
19 |
|
20 |
+
from api_docs_mck import api_docs_str
|
21 |
+
from faq_data import help, ansatte_faq_data, utleiere_faq_data
|
22 |
+
from personvernspolicy import help2, personvernspolicy_data
|
|
|
|
|
|
|
23 |
|
24 |
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
daysoff_assistant_template = """
|
27 |
You are a customer support assistant (’kundeservice AI assistent’) for Daysoff.no
|
28 |
By default, you respond in Norwegian language, using a warm, direct and professional tone.
|
29 |
+
You can provide information associated with a given booking ID, and with {help} in mind, you
|
30 |
+
can also answer frequently asked questions (FAQ) about DaysOff firmahytteordning for
|
31 |
+
employees: {ansatte_faq_data} and for employers:{utleiere_faq_data}.
|
32 |
+
To understand how best to answer queries about privacy policy,
|
33 |
+
refer to {help2} and {personvernspolicy_data}
|
34 |
Chat History: {chat_history}
|
35 |
Question: {question}
|
36 |
Answer:
|
37 |
"""
|
38 |
|
39 |
+
daysoff_assistant_prompt = PromptTemplate(
|
40 |
input_variables=["chat_history", "question"],
|
41 |
template=daysoff_assistant_template
|
42 |
)
|
|
|
53 |
api_url_prompt = PromptTemplate(input_variables=['api_docs', 'question'],
|
54 |
template=api_url_template)
|
55 |
|
|
|
56 |
api_response_template = """
|
57 |
With the API Documentation for Daysoff's official API: {api_docs} in mind,
|
58 |
and the specific user question: {question} in mind,
|
|
|
125 |
|
126 |
},
|
127 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
128 |
+
|
129 |
else:
|
130 |
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
131 |
|