mirror of
https://github.com/arc53/DocsGPT
synced 2024-11-19 21:25:39 +00:00
Merge pull request #952 from ManishMadan2882/fix-api-key-parse
FIx: API Key Parsing
This commit is contained in:
commit
40f16f8ef1
@ -78,7 +78,7 @@ def get_data_from_api_key(api_key):
|
|||||||
if data is None:
|
if data is None:
|
||||||
return bad_request(401, "Invalid API key")
|
return bad_request(401, "Invalid API key")
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def get_vectorstore(data):
|
def get_vectorstore(data):
|
||||||
if "active_docs" in data:
|
if "active_docs" in data:
|
||||||
@ -95,7 +95,6 @@ def get_vectorstore(data):
|
|||||||
vectorstore = os.path.join("application", vectorstore)
|
vectorstore = os.path.join("application", vectorstore)
|
||||||
return vectorstore
|
return vectorstore
|
||||||
|
|
||||||
|
|
||||||
def is_azure_configured():
|
def is_azure_configured():
|
||||||
return (
|
return (
|
||||||
settings.OPENAI_API_BASE
|
settings.OPENAI_API_BASE
|
||||||
@ -223,12 +222,13 @@ def stream():
|
|||||||
else:
|
else:
|
||||||
chunks = 2
|
chunks = 2
|
||||||
|
|
||||||
prompt = get_prompt(prompt_id)
|
|
||||||
|
|
||||||
# check if active_docs is set
|
# check if active_docs or api_key is set
|
||||||
|
|
||||||
if "api_key" in data:
|
if "api_key" in data:
|
||||||
data_key = get_data_from_api_key(data["api_key"])
|
data_key = get_data_from_api_key(data["api_key"])
|
||||||
|
chunks = int(data_key["chunks"])
|
||||||
|
prompt_id = data_key["prompt_id"]
|
||||||
source = {"active_docs": data_key["source"]}
|
source = {"active_docs": data_key["source"]}
|
||||||
user_api_key = data["api_key"]
|
user_api_key = data["api_key"]
|
||||||
elif "active_docs" in data:
|
elif "active_docs" in data:
|
||||||
@ -246,6 +246,8 @@ def stream():
|
|||||||
else:
|
else:
|
||||||
retriever_name = source["active_docs"]
|
retriever_name = source["active_docs"]
|
||||||
|
|
||||||
|
prompt = get_prompt(prompt_id)
|
||||||
|
|
||||||
retriever = RetrieverCreator.create_retriever(
|
retriever = RetrieverCreator.create_retriever(
|
||||||
retriever_name,
|
retriever_name,
|
||||||
question=question,
|
question=question,
|
||||||
@ -290,13 +292,13 @@ def api_answer():
|
|||||||
else:
|
else:
|
||||||
chunks = 2
|
chunks = 2
|
||||||
|
|
||||||
prompt = get_prompt(prompt_id)
|
|
||||||
|
|
||||||
# use try and except to check for exception
|
# use try and except to check for exception
|
||||||
try:
|
try:
|
||||||
# check if the vectorstore is set
|
# check if the vectorstore is set
|
||||||
if "api_key" in data:
|
if "api_key" in data:
|
||||||
data_key = get_data_from_api_key(data["api_key"])
|
data_key = get_data_from_api_key(data["api_key"])
|
||||||
|
chunks = int(data_key["chunks"])
|
||||||
|
prompt_id = data_key["prompt_id"]
|
||||||
source = {"active_docs": data_key["source"]}
|
source = {"active_docs": data_key["source"]}
|
||||||
user_api_key = data["api_key"]
|
user_api_key = data["api_key"]
|
||||||
else:
|
else:
|
||||||
@ -311,6 +313,8 @@ def api_answer():
|
|||||||
else:
|
else:
|
||||||
retriever_name = source["active_docs"]
|
retriever_name = source["active_docs"]
|
||||||
|
|
||||||
|
prompt = get_prompt(prompt_id)
|
||||||
|
|
||||||
retriever = RetrieverCreator.create_retriever(
|
retriever = RetrieverCreator.create_retriever(
|
||||||
retriever_name,
|
retriever_name,
|
||||||
question=question,
|
question=question,
|
||||||
@ -334,9 +338,9 @@ def api_answer():
|
|||||||
)
|
)
|
||||||
|
|
||||||
result = {"answer": response_full, "sources": source_log_docs}
|
result = {"answer": response_full, "sources": source_log_docs}
|
||||||
result["conversation_id"] = str(save_conversation(
|
result["conversation_id"] = save_conversation(
|
||||||
conversation_id, question, response_full, source_log_docs, llm
|
conversation_id, question, response_full, source_log_docs, llm
|
||||||
))
|
)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -351,9 +355,13 @@ def api_search():
|
|||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
# get parameter from url question
|
# get parameter from url question
|
||||||
question = data["question"]
|
question = data["question"]
|
||||||
|
if "chunks" in data:
|
||||||
|
chunks = int(data["chunks"])
|
||||||
|
else:
|
||||||
|
chunks = 2
|
||||||
if "api_key" in data:
|
if "api_key" in data:
|
||||||
data_key = get_data_from_api_key(data["api_key"])
|
data_key = get_data_from_api_key(data["api_key"])
|
||||||
|
chunks = int(data_key["chunks"])
|
||||||
source = {"active_docs": data_key["source"]}
|
source = {"active_docs": data_key["source"]}
|
||||||
user_api_key = data["api_key"]
|
user_api_key = data["api_key"]
|
||||||
elif "active_docs" in data:
|
elif "active_docs" in data:
|
||||||
@ -362,10 +370,7 @@ def api_search():
|
|||||||
else:
|
else:
|
||||||
source = {}
|
source = {}
|
||||||
user_api_key = None
|
user_api_key = None
|
||||||
if "chunks" in data:
|
|
||||||
chunks = int(data["chunks"])
|
|
||||||
else:
|
|
||||||
chunks = 2
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
source["active_docs"].split("/")[0] == "default"
|
source["active_docs"].split("/")[0] == "default"
|
||||||
@ -386,4 +391,4 @@ def api_search():
|
|||||||
user_api_key=user_api_key,
|
user_api_key=user_api_key,
|
||||||
)
|
)
|
||||||
docs = retriever.search()
|
docs = retriever.search()
|
||||||
return docs
|
return docs
|
Loading…
Reference in New Issue
Block a user