From 7462c00135cf42c0f8b1843403fb50e862f6f6db Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 8 Feb 2023 19:41:35 +0000 Subject: [PATCH] Bug fix --- application/app.py | 16 ++++++++++++++-- application/static/dist/css/output.css | 10 ---------- application/templates/index.html | 15 ++++++++++++++- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/application/app.py b/application/app.py index b49ae9c2..aa9089ed 100644 --- a/application/app.py +++ b/application/app.py @@ -24,6 +24,13 @@ dotenv.load_dotenv() with open("combine_prompt.txt", "r") as f: template = f.read() +# check if OPENAI_API_KEY is set +if os.getenv("OPENAI_API_KEY") is not None: + api_key_set = True + +else: + api_key_set = False + app = Flask(__name__) @@ -31,14 +38,18 @@ app = Flask(__name__) @app.route("/") def home(): - return render_template("index.html") + return render_template("index.html", api_key_set=api_key_set) @app.route("/api/answer", methods=["POST"]) def api_answer(): data = request.get_json() question = data["question"] - api_key = data["api_key"] + if not api_key_set: + api_key = data["api_key"] + else: + api_key = os.getenv("OPENAI_API_KEY") + # check if the vectorstore is set if "active_docs" in data: vectorstore = "vectors/" + data["active_docs"] @@ -57,6 +68,7 @@ def api_answer(): # create a prompt template c_prompt = PromptTemplate(input_variables=["summaries", "question"], template=template) # create a chain with the prompt template and the store + chain = VectorDBQAWithSourcesChain.from_llm(llm=OpenAI(openai_api_key=api_key, temperature=0), vectorstore=store, combine_prompt=c_prompt) # fetch the answer result = chain({"question": question}) diff --git a/application/static/dist/css/output.css b/application/static/dist/css/output.css index 7a6e59a4..1b5360e1 100644 --- a/application/static/dist/css/output.css +++ b/application/static/dist/css/output.css @@ -785,16 +785,6 @@ video { color: rgb(17 24 39 / var(--tw-text-opacity)); } -.text-green-500 { - --tw-text-opacity: 1; - color: rgb(34 197 94 / var(--tw-text-opacity)); -} - -.text-red-500 { - --tw-text-opacity: 1; - color: rgb(239 68 68 / var(--tw-text-opacity)); -} - .opacity-75 { opacity: 0.75; } diff --git a/application/templates/index.html b/application/templates/index.html index a85dc37b..fc91f46f 100644 --- a/application/templates/index.html +++ b/application/templates/index.html @@ -18,7 +18,9 @@

DocsGPT 🦖 Preview

About + {% if not api_key_set %} + {% endif %}
@@ -72,6 +74,8 @@ This will return a new DataFrame with all the columns from both tables, and only
+ +{% if not api_key_set %} +{% endif %} + {% if not api_key_set %} + {% endif %}