mirror of
https://github.com/open-webui/open-webui
synced 2024-11-24 04:54:12 +00:00
fix: query generation
This commit is contained in:
parent
3cfd4f8993
commit
429fa2befa
@ -515,32 +515,32 @@ async def chat_completion_files_handler(
|
|||||||
) -> tuple[dict, dict[str, list]]:
|
) -> tuple[dict, dict[str, list]]:
|
||||||
sources = []
|
sources = []
|
||||||
|
|
||||||
try:
|
|
||||||
queries_response = await generate_queries(
|
|
||||||
{
|
|
||||||
"model": body["model"],
|
|
||||||
"messages": body["messages"],
|
|
||||||
"type": "retrieval",
|
|
||||||
},
|
|
||||||
user,
|
|
||||||
)
|
|
||||||
queries_response = queries_response["choices"][0]["message"]["content"]
|
|
||||||
|
|
||||||
try:
|
|
||||||
queries_response = json.loads(queries_response)
|
|
||||||
except Exception as e:
|
|
||||||
queries_response = {"queries": []}
|
|
||||||
|
|
||||||
queries = queries_response.get("queries", [])
|
|
||||||
except Exception as e:
|
|
||||||
queries = []
|
|
||||||
|
|
||||||
if len(queries) == 0:
|
|
||||||
queries = [get_last_user_message(body["messages"])]
|
|
||||||
|
|
||||||
print(f"{queries=}")
|
|
||||||
|
|
||||||
if files := body.get("metadata", {}).get("files", None):
|
if files := body.get("metadata", {}).get("files", None):
|
||||||
|
try:
|
||||||
|
queries_response = await generate_queries(
|
||||||
|
{
|
||||||
|
"model": body["model"],
|
||||||
|
"messages": body["messages"],
|
||||||
|
"type": "retrieval",
|
||||||
|
},
|
||||||
|
user,
|
||||||
|
)
|
||||||
|
queries_response = queries_response["choices"][0]["message"]["content"]
|
||||||
|
|
||||||
|
try:
|
||||||
|
queries_response = json.loads(queries_response)
|
||||||
|
except Exception as e:
|
||||||
|
queries_response = {"queries": []}
|
||||||
|
|
||||||
|
queries = queries_response.get("queries", [])
|
||||||
|
except Exception as e:
|
||||||
|
queries = []
|
||||||
|
|
||||||
|
if len(queries) == 0:
|
||||||
|
queries = [get_last_user_message(body["messages"])]
|
||||||
|
|
||||||
|
print(f"{queries=}")
|
||||||
|
|
||||||
sources = get_sources_from_files(
|
sources = get_sources_from_files(
|
||||||
files=files,
|
files=files,
|
||||||
queries=queries,
|
queries=queries,
|
||||||
@ -691,6 +691,7 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
|
|||||||
|
|
||||||
# If context is not empty, insert it into the messages
|
# If context is not empty, insert it into the messages
|
||||||
if len(sources) > 0:
|
if len(sources) > 0:
|
||||||
|
print("\n\n\n\n\n\n\nHI\n\n\n\n\n\n")
|
||||||
context_string = ""
|
context_string = ""
|
||||||
for source_idx, source in enumerate(sources):
|
for source_idx, source in enumerate(sources):
|
||||||
source_id = source.get("source", {}).get("name", "")
|
source_id = source.get("source", {}).get("name", "")
|
||||||
|
Loading…
Reference in New Issue
Block a user