mirror of
https://github.com/arc53/DocsGPT
synced 2024-11-17 21:26:26 +00:00
Bug fix
This commit is contained in:
parent
ac7cc26022
commit
7462c00135
@ -24,6 +24,13 @@ dotenv.load_dotenv()
|
|||||||
with open("combine_prompt.txt", "r") as f:
|
with open("combine_prompt.txt", "r") as f:
|
||||||
template = f.read()
|
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__)
|
app = Flask(__name__)
|
||||||
@ -31,14 +38,18 @@ app = Flask(__name__)
|
|||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def home():
|
def home():
|
||||||
return render_template("index.html")
|
return render_template("index.html", api_key_set=api_key_set)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/answer", methods=["POST"])
|
@app.route("/api/answer", methods=["POST"])
|
||||||
def api_answer():
|
def api_answer():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
question = data["question"]
|
question = data["question"]
|
||||||
|
if not api_key_set:
|
||||||
api_key = data["api_key"]
|
api_key = data["api_key"]
|
||||||
|
else:
|
||||||
|
api_key = os.getenv("OPENAI_API_KEY")
|
||||||
|
|
||||||
# check if the vectorstore is set
|
# check if the vectorstore is set
|
||||||
if "active_docs" in data:
|
if "active_docs" in data:
|
||||||
vectorstore = "vectors/" + data["active_docs"]
|
vectorstore = "vectors/" + data["active_docs"]
|
||||||
@ -57,6 +68,7 @@ def api_answer():
|
|||||||
# create a prompt template
|
# create a prompt template
|
||||||
c_prompt = PromptTemplate(input_variables=["summaries", "question"], template=template)
|
c_prompt = PromptTemplate(input_variables=["summaries", "question"], template=template)
|
||||||
# create a chain with the prompt template and the store
|
# 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)
|
chain = VectorDBQAWithSourcesChain.from_llm(llm=OpenAI(openai_api_key=api_key, temperature=0), vectorstore=store, combine_prompt=c_prompt)
|
||||||
# fetch the answer
|
# fetch the answer
|
||||||
result = chain({"question": question})
|
result = chain({"question": question})
|
||||||
|
10
application/static/dist/css/output.css
vendored
10
application/static/dist/css/output.css
vendored
@ -785,16 +785,6 @@ video {
|
|||||||
color: rgb(17 24 39 / var(--tw-text-opacity));
|
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-75 {
|
||||||
opacity: 0.75;
|
opacity: 0.75;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,9 @@
|
|||||||
<h1 class="text-lg font-medium">DocsGPT 🦖 Preview</h1>
|
<h1 class="text-lg font-medium">DocsGPT 🦖 Preview</h1>
|
||||||
<div>
|
<div>
|
||||||
<a href="https://github.com/arc53/docsgpt" class="text-blue-500 hover:text-blue-800 text-sm">About</a>
|
<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>
|
<button class="text-sm text-yellow-500 hover:text-yellow-800" onclick="resetApiKey()">Reset Key</button>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<div class="lg:flex ml-2 mr-2">
|
<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 class="flex items-center justify-center h-full">
|
||||||
|
|
||||||
</div>
|
</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="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="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">
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
<script>
|
<script>
|
||||||
function docsIndex() {
|
function docsIndex() {
|
||||||
// loads latest index from https://raw.githubusercontent.com/arc53/DocsHUB/main/combined.json
|
// 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 => {
|
.then(data => {
|
||||||
console.log('Success:', data);
|
console.log('Success:', data);
|
||||||
localStorage.setItem("docsIndex", JSON.stringify(data));
|
localStorage.setItem("docsIndex", JSON.stringify(data));
|
||||||
|
loacalStorage.setItem("docsIndexDate", Date.now());
|
||||||
generateOptions()
|
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) {
|
if (localStorage.getItem('apiKey') === null) {
|
||||||
console.log("apiKey is not set")
|
console.log("apiKey is not set")
|
||||||
document.getElementById('modal').classList.toggle('hidden')
|
document.getElementById('modal').classList.toggle('hidden')
|
||||||
}
|
}
|
||||||
|
{% endif %}
|
||||||
if (localStorage.getItem('docsIndex') === null) {
|
if (localStorage.getItem('docsIndex') === null) {
|
||||||
console.log("docsIndex is not set")
|
console.log("docsIndex is not set")
|
||||||
docsIndex()
|
docsIndex()
|
||||||
}
|
}
|
||||||
|
else if (localStorage.getItem("docsIndexDate") < Date.now() - 900000) {
|
||||||
|
console.log("docsIndex is older than 24 hours")
|
||||||
|
docsIndex()
|
||||||
|
}
|
||||||
|
|
||||||
generateOptions()
|
generateOptions()
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
{% if not api_key_set %}
|
||||||
<script src="{{url_for('static',filename='src/authapi.js')}}"></script>
|
<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/chat.js')}}"></script>
|
||||||
<script src="{{url_for('static',filename='src/choiceChange.js')}}"></script>
|
<script src="{{url_for('static',filename='src/choiceChange.js')}}"></script>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user