Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -182,7 +182,7 @@ def document_storage_chroma(splits):
|
|
| 182 |
|
| 183 |
#Vektorstore vorbereiten...
|
| 184 |
#dokumente in chroma db vektorisiert ablegen können - die Db vorbereiten daüfur
|
| 185 |
-
def document_retrieval_chroma(
|
| 186 |
#OpenAI embeddings -------------------------------
|
| 187 |
embeddings = OpenAIEmbeddings()
|
| 188 |
|
|
@@ -259,24 +259,25 @@ def generate_prompt_with_history_openai(prompt, history):
|
|
| 259 |
##############################################
|
| 260 |
def generate(text, history, rag_option, model_option, temperature=0.5, max_new_tokens=4048, top_p=0.6, repetition_penalty=1.3):
|
| 261 |
#mit RAG
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
#{context} Question: {text}"""
|
| 267 |
|
| 268 |
try:
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
|
|
|
|
|
|
| 280 |
#payload = tokenizer.apply_chat_template([{"role":"user","content":prompt}],tokenize=False)
|
| 281 |
payload = tokenizer.apply_chat_template(prompt,tokenize=False)
|
| 282 |
result = client.text_generation(
|
|
|
|
| 182 |
|
| 183 |
#Vektorstore vorbereiten...
|
| 184 |
#dokumente in chroma db vektorisiert ablegen können - die Db vorbereiten daüfur
|
| 185 |
+
def document_retrieval_chroma():
|
| 186 |
#OpenAI embeddings -------------------------------
|
| 187 |
embeddings = OpenAIEmbeddings()
|
| 188 |
|
|
|
|
| 259 |
##############################################
|
| 260 |
def generate(text, history, rag_option, model_option, temperature=0.5, max_new_tokens=4048, top_p=0.6, repetition_penalty=1.3):
|
| 261 |
#mit RAG
|
| 262 |
+
if (rag_option is None):
|
| 263 |
+
raise gr.Error("Retrieval Augmented Generation ist erforderlich.")
|
| 264 |
+
if (prompt == ""):
|
| 265 |
+
raise gr.Error("Prompt ist erforderlich.")
|
|
|
|
| 266 |
|
| 267 |
try:
|
| 268 |
+
if (rag_option == "An"):
|
| 269 |
+
#muss nur einmal ausgeführt werden...
|
| 270 |
+
if not splittet:
|
| 271 |
+
splits = document_loading_splitting()
|
| 272 |
+
document_storage_chroma(splits)
|
| 273 |
+
db = document_retrieval_chroma()
|
| 274 |
+
#mit RAG:
|
| 275 |
+
neu_text_mit_chunks = rag_chain(text, db)
|
| 276 |
+
prompt = generate_prompt_with_history_openai(neu_text_mit_chunks, history)
|
| 277 |
+
else:
|
| 278 |
+
prompt = generate_prompt_with_history_openai(text, history)
|
| 279 |
+
|
| 280 |
+
#Anfrage an Modell (mit RAG: mit chunks aus Vektorstore, ohne: nur promt und history)
|
| 281 |
#payload = tokenizer.apply_chat_template([{"role":"user","content":prompt}],tokenize=False)
|
| 282 |
payload = tokenizer.apply_chat_template(prompt,tokenize=False)
|
| 283 |
result = client.text_generation(
|