mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-18 20:14:28 +00:00
fix: override chunks,promps with api-key-data
This commit is contained in:
1 parent
0618153390
commit
3d9288f82f
1 file changed
+17
-12
@@ -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"
|
||||||
|
|||||||
Reference in new issue
Block a user