pull/50/head
Alex 2 years ago
parent ac7cc26022
commit 7462c00135

@ -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})

@ -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;
}

@ -18,7 +18,9 @@
<h1 class="text-lg font-medium">DocsGPT 🦖 Preview</h1>
<div>
<a href="https://github.com/arc53/docsgpt" class="text-blue-500 hover:text-blue-800 text-sm">About</a>
{% if not api_key_set %}
<button class="text-sm text-yellow-500 hover:text-yellow-800" onclick="resetApiKey()">Reset Key</button>
{% endif %}
</div>
</header>
<div class="lg:flex ml-2 mr-2">
@ -72,6 +74,8 @@ This will return a new DataFrame with all the columns from both tables, and only
<div class="flex items-center justify-center h-full">
</div>
{% if not api_key_set %}
<div class="fixed z-10 overflow-y-auto top-0 w-full left-0 hidden" id="modal">
<div class="flex items-center justify-center min-height-100vh pt-4 px-4 pb-20 text-center sm:block sm:p-0">
<div class="fixed inset-0 transition-opacity">
@ -95,6 +99,7 @@ This will return a new DataFrame with all the columns from both tables, and only
</div>
</div>
</div>
{% endif %}
<script>
function docsIndex() {
// loads latest index from https://raw.githubusercontent.com/arc53/DocsHUB/main/combined.json
@ -104,6 +109,7 @@ This will return a new DataFrame with all the columns from both tables, and only
.then(data => {
console.log('Success:', data);
localStorage.setItem("docsIndex", JSON.stringify(data));
loacalStorage.setItem("docsIndexDate", Date.now());
generateOptions()
}
@ -134,20 +140,27 @@ This will return a new DataFrame with all the columns from both tables, and only
}
}
// check if api_key is set
{% if not api_key_set %}
if (localStorage.getItem('apiKey') === null) {
console.log("apiKey is not set")
document.getElementById('modal').classList.toggle('hidden')
}
{% endif %}
if (localStorage.getItem('docsIndex') === null) {
console.log("docsIndex is not set")
docsIndex()
}
else if (localStorage.getItem("docsIndexDate") < Date.now() - 900000) {
console.log("docsIndex is older than 24 hours")
docsIndex()
}
generateOptions()
</script>
{% if not api_key_set %}
<script src="{{url_for('static',filename='src/authapi.js')}}"></script>
{% endif %}
<script src="{{url_for('static',filename='src/chat.js')}}"></script>
<script src="{{url_for('static',filename='src/choiceChange.js')}}"></script>

Loading…
Cancel
Save