Update app.py
Browse files
app.py
CHANGED
|
@@ -131,16 +131,17 @@ def invoke(openai_api_key, rag_option, prompt):
|
|
| 131 |
#raise gr.Error("OpenAI API Key is required.")
|
| 132 |
openai_api_key= OAI_API_KEY
|
| 133 |
if (rag_option is None):
|
| 134 |
-
raise gr.Error("Retrieval Augmented Generation
|
| 135 |
if (prompt == ""):
|
| 136 |
-
raise gr.Error("Prompt
|
| 137 |
try:
|
| 138 |
llm = ChatOpenAI(model_name = MODEL_NAME,
|
| 139 |
openai_api_key = openai_api_key,
|
| 140 |
temperature = 0)
|
| 141 |
if (rag_option == "Chroma"):
|
| 142 |
-
|
| 143 |
-
|
|
|
|
| 144 |
db = document_retrieval_chroma(llm, prompt)
|
| 145 |
result = rag_chain(llm, prompt, db)
|
| 146 |
elif (rag_option == "MongoDB"):
|
|
@@ -157,7 +158,7 @@ def invoke(openai_api_key, rag_option, prompt):
|
|
| 157 |
description = """<strong>Überblick:</strong> Hier wird ein <strong>Large Language Model (LLM)</strong> mit
|
| 158 |
<strong>Retrieval Augmented Generation (RAG)</strong> auf <strong>externen Daten</strong> demonstriert.\n\n
|
| 159 |
<strong>Genauer:</strong> Folgende externe Daten sind als Beispiel gegeben:
|
| 160 |
-
<a href='""" + YOUTUBE_URL_1 + """'>YouTube</a>, <a href='""" + PDF_URL + """'>PDF</a>, and <a href='""" + WEB_URL + """'>Web.</a>
|
| 161 |
Alle neueren Datums!.
|
| 162 |
<ul style="list-style-type:square;">
|
| 163 |
<li>Setze "Retrieval Augmented Generation" auf "<strong>Off</strong>" und gib einen Prompt ein." Das entspricht <strong> ein LLM nutzen ohne RAG</strong></li>
|
|
@@ -169,7 +170,8 @@ description = """<strong>Überblick:</strong> Hier wird ein <strong>Large Langua
|
|
| 169 |
gr.close_all()
|
| 170 |
demo = gr.Interface(fn=invoke,
|
| 171 |
inputs = [gr.Textbox(label = "OpenAI API Key", value = "sk-", lines = 1),
|
| 172 |
-
gr.Radio(["Off", "Chroma", "MongoDB"], label="Retrieval Augmented Generation", value = "Off"),
|
|
|
|
| 173 |
gr.Textbox(label = "Prompt", value = "What is GPT-4?", lines = 1)],
|
| 174 |
outputs = [gr.Textbox(label = "Completion", lines = 1)],
|
| 175 |
title = "Generative AI - LLM & RAG",
|
|
|
|
| 131 |
#raise gr.Error("OpenAI API Key is required.")
|
| 132 |
openai_api_key= OAI_API_KEY
|
| 133 |
if (rag_option is None):
|
| 134 |
+
raise gr.Error("Retrieval Augmented Generation ist erforderlich.")
|
| 135 |
if (prompt == ""):
|
| 136 |
+
raise gr.Error("Prompt ist erforderlich.")
|
| 137 |
try:
|
| 138 |
llm = ChatOpenAI(model_name = MODEL_NAME,
|
| 139 |
openai_api_key = openai_api_key,
|
| 140 |
temperature = 0)
|
| 141 |
if (rag_option == "Chroma"):
|
| 142 |
+
#muss nur einmal ausgeführt werden...
|
| 143 |
+
#splits = document_loading_splitting()
|
| 144 |
+
#document_storage_chroma(splits)
|
| 145 |
db = document_retrieval_chroma(llm, prompt)
|
| 146 |
result = rag_chain(llm, prompt, db)
|
| 147 |
elif (rag_option == "MongoDB"):
|
|
|
|
| 158 |
description = """<strong>Überblick:</strong> Hier wird ein <strong>Large Language Model (LLM)</strong> mit
|
| 159 |
<strong>Retrieval Augmented Generation (RAG)</strong> auf <strong>externen Daten</strong> demonstriert.\n\n
|
| 160 |
<strong>Genauer:</strong> Folgende externe Daten sind als Beispiel gegeben:
|
| 161 |
+
<a href='""" + YOUTUBE_URL_1 + """'>YouTube</a>, <a href='""" + PDF_URL + """'>PDF</a>, and <a href='""" + WEB_URL + """'>Web.</a> <br>
|
| 162 |
Alle neueren Datums!.
|
| 163 |
<ul style="list-style-type:square;">
|
| 164 |
<li>Setze "Retrieval Augmented Generation" auf "<strong>Off</strong>" und gib einen Prompt ein." Das entspricht <strong> ein LLM nutzen ohne RAG</strong></li>
|
|
|
|
| 170 |
gr.close_all()
|
| 171 |
demo = gr.Interface(fn=invoke,
|
| 172 |
inputs = [gr.Textbox(label = "OpenAI API Key", value = "sk-", lines = 1),
|
| 173 |
+
#gr.Radio(["Off", "Chroma", "MongoDB"], label="Retrieval Augmented Generation", value = "Off"),
|
| 174 |
+
gr.Radio(["Off", "Chroma"], label="Retrieval Augmented Generation", value = "Off"),
|
| 175 |
gr.Textbox(label = "Prompt", value = "What is GPT-4?", lines = 1)],
|
| 176 |
outputs = [gr.Textbox(label = "Completion", lines = 1)],
|
| 177 |
title = "Generative AI - LLM & RAG",
|