alexkueck commited on
Commit
9501c88
·
1 Parent(s): 06777f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -17
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(llm, prompt):
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
- #später entsprechend mit Vektorstore...
263
- #context="Nuremberg is the second-largest city of the German state of Bavaria after its capital Munich, and its 541,000 inhabitants make it the 14th-largest city in Germany. On the Pegnitz River (from its confluence with the Rednitz in Fürth onwards: Regnitz, a tributary of the River Main) and the Rhine–Main–Danube Canal, it lies in the Bavarian administrative region of Middle Franconia, and is the largest city and the unofficial capital of Franconia. Nuremberg forms with the neighbouring cities of Fürth, Erlangen and Schwabach a continuous conurbation with a total population of 812,248 (2022), which is the heart of the urban area region with around 1.4 million inhabitants,[4] while the larger Nuremberg Metropolitan Region has approximately 3.6 million inhabitants. The city lies about 170 kilometres (110 mi) north of Munich. It is the largest city in the East Franconian dialect area."
264
-
265
- #prompt = f"""Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.
266
- #{context} Question: {text}"""
267
 
268
  try:
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(llm, history_text_und_prompt)
274
- #result = rag_chain(llm, history_text_und_prompt, db)
275
- #mit RAG:
276
- neu_text_mit_chunks = rag_chain(text, db)
277
- prompt = generate_prompt_with_history_openai(neu_text_mit_chunks, history)
278
-
279
- #zusammengesetzte Anfrage an Modell...
 
 
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(