mirror of
https://github.com/open-webui/open-webui
synced 2025-01-19 09:16:44 +00:00
refac: file handler
This commit is contained in:
parent
0425621494
commit
4645943066
@ -621,17 +621,28 @@ async def chat_completion_files_handler(
|
|||||||
if len(queries) == 0:
|
if len(queries) == 0:
|
||||||
queries = [get_last_user_message(body["messages"])]
|
queries = [get_last_user_message(body["messages"])]
|
||||||
|
|
||||||
sources = get_sources_from_files(
|
try:
|
||||||
files=files,
|
# Offload get_sources_from_files to a separate thread
|
||||||
queries=queries,
|
loop = asyncio.get_running_loop()
|
||||||
embedding_function=request.app.state.EMBEDDING_FUNCTION,
|
with ThreadPoolExecutor() as executor:
|
||||||
k=request.app.state.config.TOP_K,
|
sources = await loop.run_in_executor(
|
||||||
reranking_function=request.app.state.rf,
|
executor,
|
||||||
r=request.app.state.config.RELEVANCE_THRESHOLD,
|
lambda: get_sources_from_files(
|
||||||
hybrid_search=request.app.state.config.ENABLE_RAG_HYBRID_SEARCH,
|
files=files,
|
||||||
)
|
queries=queries,
|
||||||
|
embedding_function=request.app.state.EMBEDDING_FUNCTION,
|
||||||
|
k=request.app.state.config.TOP_K,
|
||||||
|
reranking_function=request.app.state.rf,
|
||||||
|
r=request.app.state.config.RELEVANCE_THRESHOLD,
|
||||||
|
hybrid_search=request.app.state.config.ENABLE_RAG_HYBRID_SEARCH,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
log.exception(e)
|
||||||
|
|
||||||
log.debug(f"rag_contexts:sources: {sources}")
|
log.debug(f"rag_contexts:sources: {sources}")
|
||||||
|
|
||||||
return body, {"sources": sources}
|
return body, {"sources": sources}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user