Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -114,14 +114,28 @@ def load_chatbot():
|
|
| 114 |
standard_prompt = "Schreibe immer höflich und auf Deutsch und frage immer nach Jahren, wenn keines explizit angegeben ist. "
|
| 115 |
return load_qa_chain(llm=OpenAI(model_name="gpt-3.5-turbo-instruct", prompt=standard_prompt), chain_type="stuff")
|
| 116 |
|
|
|
|
| 117 |
def ask_bot(query):
|
| 118 |
chain = load_chatbot()
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
return response
|
| 123 |
|
| 124 |
|
|
|
|
| 125 |
def display_chat_history(chat_history):
|
| 126 |
for chat in chat_history:
|
| 127 |
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
|
@@ -250,20 +264,18 @@ def page1():
|
|
| 250 |
|
| 251 |
# Start timing
|
| 252 |
start_time = time.time()
|
| 253 |
-
|
| 254 |
with st.spinner('Bot is thinking...'):
|
| 255 |
chain = load_chatbot()
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
# Kombiniere den standardmäßigen Prompt mit der Benutzeranfrage
|
| 259 |
-
full_query = chain.llm.prompt + " " + query # Achte darauf, wie der Prompt und die Benutzeranfrage kombiniert werden
|
| 260 |
|
| 261 |
with get_openai_callback() as cb:
|
| 262 |
# Übergib die kombinierte Anfrage an die run-Funktion
|
| 263 |
response = chain.run(input_documents=docs, question=full_query)
|
| 264 |
response = handle_no_answer(response) # Verarbeite die Antwort durch die neue Funktion
|
| 265 |
-
|
| 266 |
-
|
| 267 |
|
| 268 |
|
| 269 |
# Stop timing
|
|
|
|
| 114 |
standard_prompt = "Schreibe immer höflich und auf Deutsch und frage immer nach Jahren, wenn keines explizit angegeben ist. "
|
| 115 |
return load_qa_chain(llm=OpenAI(model_name="gpt-3.5-turbo-instruct", prompt=standard_prompt), chain_type="stuff")
|
| 116 |
|
| 117 |
+
|
| 118 |
def ask_bot(query):
|
| 119 |
chain = load_chatbot()
|
| 120 |
+
|
| 121 |
+
# Definiere hier den standardmäßigen Prompt
|
| 122 |
+
standard_prompt = "Schreibe immer höflich und auf Deutsch und frage immer nach Jahren, wenn keines explizit angegeben ist. "
|
| 123 |
+
|
| 124 |
+
# Kombiniere den standardmäßigen Prompt mit der Benutzeranfrage
|
| 125 |
+
full_query = standard_prompt + query
|
| 126 |
+
|
| 127 |
+
# Suche nach den ähnlichsten Dokumenten
|
| 128 |
+
docs = VectorStore.similarity_search(query=full_query, k=5)
|
| 129 |
+
|
| 130 |
+
with get_openai_callback() as cb:
|
| 131 |
+
# Übergib die kombinierte Anfrage an die run-Funktion
|
| 132 |
+
response = chain.run(input_documents=docs, question=full_query)
|
| 133 |
+
response = handle_no_answer(response) # Verarbeite die Antwort durch die neue Funktion
|
| 134 |
+
|
| 135 |
return response
|
| 136 |
|
| 137 |
|
| 138 |
+
|
| 139 |
def display_chat_history(chat_history):
|
| 140 |
for chat in chat_history:
|
| 141 |
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
|
|
|
| 264 |
|
| 265 |
# Start timing
|
| 266 |
start_time = time.time()
|
| 267 |
+
|
| 268 |
with st.spinner('Bot is thinking...'):
|
| 269 |
chain = load_chatbot()
|
| 270 |
+
full_query = ask_bot(query) # Hier wird die Funktion ask_bot aufgerufen
|
| 271 |
+
docs = VectorStore.similarity_search(query=full_query, k=5)
|
|
|
|
|
|
|
| 272 |
|
| 273 |
with get_openai_callback() as cb:
|
| 274 |
# Übergib die kombinierte Anfrage an die run-Funktion
|
| 275 |
response = chain.run(input_documents=docs, question=full_query)
|
| 276 |
response = handle_no_answer(response) # Verarbeite die Antwort durch die neue Funktion
|
| 277 |
+
|
| 278 |
+
|
| 279 |
|
| 280 |
|
| 281 |
# Stop timing
|