mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-15 13:55:19 +00:00
refac: direct connections
This commit is contained in:
parent
eb568695e7
commit
6d899b80d0
4 changed files with 10 additions and 6 deletions
|
|
@ -947,6 +947,7 @@ async def chat_completion(
|
||||||
else {}
|
else {}
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
request.state.metadata = metadata
|
request.state.metadata = metadata
|
||||||
form_data["metadata"] = metadata
|
form_data["metadata"] = metadata
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -279,8 +279,8 @@ def get_event_emitter(request_info):
|
||||||
await sio.emit(
|
await sio.emit(
|
||||||
"chat-events",
|
"chat-events",
|
||||||
{
|
{
|
||||||
"chat_id": request_info["chat_id"],
|
"chat_id": request_info.get("chat_id", None),
|
||||||
"message_id": request_info["message_id"],
|
"message_id": request_info.get("message_id", None),
|
||||||
"data": event_data,
|
"data": event_data,
|
||||||
},
|
},
|
||||||
to=session_id,
|
to=session_id,
|
||||||
|
|
@ -329,8 +329,8 @@ def get_event_call(request_info):
|
||||||
response = await sio.call(
|
response = await sio.call(
|
||||||
"chat-events",
|
"chat-events",
|
||||||
{
|
{
|
||||||
"chat_id": request_info["chat_id"],
|
"chat_id": request_info.get("chat_id", None),
|
||||||
"message_id": request_info["message_id"],
|
"message_id": request_info.get("message_id", None),
|
||||||
"data": event_data,
|
"data": event_data,
|
||||||
},
|
},
|
||||||
to=request_info["session_id"],
|
to=request_info["session_id"],
|
||||||
|
|
|
||||||
|
|
@ -164,10 +164,14 @@ async def generate_chat_completion(
|
||||||
if BYPASS_MODEL_ACCESS_CONTROL:
|
if BYPASS_MODEL_ACCESS_CONTROL:
|
||||||
bypass_filter = True
|
bypass_filter = True
|
||||||
|
|
||||||
|
if hasattr(request.state, "metadata"):
|
||||||
|
form_data["metadata"] = request.state.metadata
|
||||||
|
|
||||||
if getattr(request.state, "direct", False) and hasattr(request.state, "model"):
|
if getattr(request.state, "direct", False) and hasattr(request.state, "model"):
|
||||||
models = {
|
models = {
|
||||||
request.state.model["id"]: request.state.model,
|
request.state.model["id"]: request.state.model,
|
||||||
}
|
}
|
||||||
|
log.debug(f"direct connection to model: {models}")
|
||||||
else:
|
else:
|
||||||
models = request.app.state.MODELS
|
models = request.app.state.MODELS
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -266,8 +266,6 @@
|
||||||
if (directConnections) {
|
if (directConnections) {
|
||||||
const urlIdx = model?.urlIdx;
|
const urlIdx = model?.urlIdx;
|
||||||
|
|
||||||
console.log(model, directConnections);
|
|
||||||
|
|
||||||
const OPENAI_API_URL = directConnections.OPENAI_API_BASE_URLS[urlIdx];
|
const OPENAI_API_URL = directConnections.OPENAI_API_BASE_URLS[urlIdx];
|
||||||
const OPENAI_API_KEY = directConnections.OPENAI_API_KEYS[urlIdx];
|
const OPENAI_API_KEY = directConnections.OPENAI_API_KEYS[urlIdx];
|
||||||
const API_CONFIG = directConnections.OPENAI_API_CONFIGS[urlIdx];
|
const API_CONFIG = directConnections.OPENAI_API_CONFIGS[urlIdx];
|
||||||
|
|
@ -315,6 +313,7 @@
|
||||||
const lines = chunk.split('\n').filter((line) => line.trim() !== '');
|
const lines = chunk.split('\n').filter((line) => line.trim() !== '');
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
|
console.log(line);
|
||||||
$socket?.emit(channel, line);
|
$socket?.emit(channel, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue