Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@
|
|
3 |
|
4 |
import asyncio
|
5 |
import os
|
|
|
6 |
import time
|
7 |
import json
|
8 |
import torch
|
@@ -10,8 +11,6 @@ import torch
|
|
10 |
from api_docs_mck import daysoff_api_docs
|
11 |
|
12 |
import chainlit as cl
|
13 |
-
#from chainlit import LLMSettings # hmm..
|
14 |
-
#from chainlit.config import config # hmm...
|
15 |
|
16 |
from langchain import hub
|
17 |
from langchain.chains import LLMChain, APIChain
|
@@ -19,16 +18,6 @@ from langchain_core.prompts import PromptTemplate
|
|
19 |
from langchain_community.llms import HuggingFaceHub
|
20 |
from langchain.memory.buffer import ConversationBufferMemory
|
21 |
|
22 |
-
|
23 |
-
HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
24 |
-
LANGCHAIN_API_KEY = os.environ.get("LANGCHAIN_API_KEY")
|
25 |
-
HF_TOKEN = os.environ.get("HF_TOKEN")
|
26 |
-
|
27 |
-
#os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:true"
|
28 |
-
|
29 |
-
dtype = torch.float16
|
30 |
-
device = torch.device("cuda")
|
31 |
-
|
32 |
daysoff_assistant_booking_template = """
|
33 |
You are a customer support assistant for Daysoff.no. Your expertise is
|
34 |
retrieving booking information for a given booking ID."
|
@@ -69,15 +58,10 @@ api_response_prompt = PromptTemplate(input_variables=['api_docs_mck',
|
|
69 |
'api_response'],
|
70 |
template=api_response_template)
|
71 |
|
72 |
-
|
73 |
-
# --model, memory object, and llm_chain
|
74 |
@cl.on_chat_start
|
75 |
def setup_multiple_chains():
|
76 |
-
llm = HuggingFaceHub(repo_id="google/gemma-2-2b-it")
|
77 |
-
|
78 |
-
#huggingface_api_token=HUGGINGFACEHUB_API_TOKEN,
|
79 |
-
#device=device)
|
80 |
-
|
81 |
conversation_memory = ConversationBufferMemory(memory_key="chat_history",
|
82 |
max_len=200,
|
83 |
return_messages=True,
|
@@ -99,11 +83,8 @@ def setup_multiple_chains():
|
|
99 |
|
100 |
cl.user_session.set("api_chain", api_chain)
|
101 |
|
|
|
102 |
|
103 |
-
# --regex for alphanum. "LLLLLLxxxxxx", i.e. booking_id |==> 308.9 trillion unique possibilities
|
104 |
-
BOOKING_ID = r'\b[A-Z]{6}\d{6}\b'
|
105 |
-
|
106 |
-
# --keywords based from email-data
|
107 |
BOOKING_KEYWORDS = [
|
108 |
"booking",
|
109 |
"bestillingsnummer",
|
@@ -122,7 +103,6 @@ BOOKING_KEYWORDS = [
|
|
122 |
"identyfikacyjny pลatnoลci"
|
123 |
]
|
124 |
|
125 |
-
# --wrapper function around the @cl.on_message decorator; chain trigger(s)
|
126 |
@cl.on_message
|
127 |
async def handle_message(message: cl.Message):
|
128 |
user_message = message.content.lower()
|
|
|
3 |
|
4 |
import asyncio
|
5 |
import os
|
6 |
+
import re
|
7 |
import time
|
8 |
import json
|
9 |
import torch
|
|
|
11 |
from api_docs_mck import daysoff_api_docs
|
12 |
|
13 |
import chainlit as cl
|
|
|
|
|
14 |
|
15 |
from langchain import hub
|
16 |
from langchain.chains import LLMChain, APIChain
|
|
|
18 |
from langchain_community.llms import HuggingFaceHub
|
19 |
from langchain.memory.buffer import ConversationBufferMemory
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
daysoff_assistant_booking_template = """
|
22 |
You are a customer support assistant for Daysoff.no. Your expertise is
|
23 |
retrieving booking information for a given booking ID."
|
|
|
58 |
'api_response'],
|
59 |
template=api_response_template)
|
60 |
|
|
|
|
|
61 |
@cl.on_chat_start
|
62 |
def setup_multiple_chains():
|
63 |
+
llm = HuggingFaceHub(repo_id="google/gemma-2-2b-it")
|
64 |
+
|
|
|
|
|
|
|
65 |
conversation_memory = ConversationBufferMemory(memory_key="chat_history",
|
66 |
max_len=200,
|
67 |
return_messages=True,
|
|
|
83 |
|
84 |
cl.user_session.set("api_chain", api_chain)
|
85 |
|
86 |
+
BOOKING_ID = r'\b[A-Z]{6}\d{6}\b'
|
87 |
|
|
|
|
|
|
|
|
|
88 |
BOOKING_KEYWORDS = [
|
89 |
"booking",
|
90 |
"bestillingsnummer",
|
|
|
103 |
"identyfikacyjny pลatnoลci"
|
104 |
]
|
105 |
|
|
|
106 |
@cl.on_message
|
107 |
async def handle_message(message: cl.Message):
|
108 |
user_message = message.content.lower()
|