Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
92d056c9
"sgl-router/src/git@developer.sourcefind.cn:change/sglang.git" did not exist on "d05a968ba8aa563355300df335f19f9f05ed7fa7"
Commit
92d056c9
authored
Jun 04, 2024
by
Timothy J. Baek
Browse files
fix: running models
parent
2be9c25b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
28 deletions
+27
-28
backend/apps/socket/main.py
backend/apps/socket/main.py
+26
-27
src/lib/components/layout/Sidebar/UserMenu.svelte
src/lib/components/layout/Sidebar/UserMenu.svelte
+1
-1
No files found.
backend/apps/socket/main.py
View file @
92d056c9
...
...
@@ -34,6 +34,7 @@ async def connect(sid, environ, auth):
print
(
len
(
set
(
USER_POOL
)))
await
sio
.
emit
(
"user-count"
,
{
"count"
:
len
(
set
(
USER_POOL
))})
await
sio
.
emit
(
"usage"
,
{
"models"
:
get_models_in_use
()})
@
sio
.
on
(
"user-join"
)
...
...
@@ -64,10 +65,9 @@ async def user_count(sid):
def
get_models_in_use
():
# Aggregate all models in use
models_in_use
=
[]
for
s
id
,
data
in
USAGE_POOL
.
items
():
models_in_use
.
ext
end
(
data
[
"
model
s"
]
)
for
model_
id
,
data
in
USAGE_POOL
.
items
():
models_in_use
.
app
end
(
model
_id
)
print
(
f
"Models in use:
{
models_in_use
}
"
)
return
models_in_use
...
...
@@ -77,46 +77,45 @@ def get_models_in_use():
async
def
usage
(
sid
,
data
):
print
(
f
'Received "usage" event from
{
sid
}
:
{
data
}
'
)
# Cancel previous task if there is one
if
sid
in
USAGE_POOL
:
USAGE_POOL
[
sid
][
"task"
].
cancel
()
# Store the new usage data and task
model_id
=
data
[
"model"
]
if
sid
in
USAGE_POOL
and
"models"
in
USAGE_POOL
[
sid
]:
# Cancel previous callback if there is one
if
model_id
in
USAGE_POOL
:
USAGE_POOL
[
model_id
][
"callback"
].
cancel
()
print
(
USAGE_POOL
[
sid
])
# Store the new usage data and task
models
=
USAGE_POOL
[
sid
][
"models"
]
if
model_id
not
in
models
:
models
.
append
(
model_id
)
USAGE_POOL
[
sid
]
=
{
"models"
:
models
}
if
model_id
in
USAGE_POOL
:
USAGE_POOL
[
model_id
][
"sids"
].
append
(
sid
)
USAGE_POOL
[
model_id
][
"sids"
]
=
list
(
set
(
USAGE_POOL
[
model_id
][
"sids"
]))
else
:
USAGE_POOL
[
s
id
]
=
{
"
models"
:
[
model_
id
]}
USAGE_POOL
[
model_
id
]
=
{
"
sids"
:
[
s
id
]}
# Schedule a task to remove the usage data after TIMEOUT_DURATION
USAGE_POOL
[
sid
][
"task"
]
=
asyncio
.
create_task
(
remove_after_timeout
(
sid
,
model_id
))
USAGE_POOL
[
model_id
][
"callback"
]
=
asyncio
.
create_task
(
remove_after_timeout
(
sid
,
model_id
)
)
models_in_use
=
get_models_in_use
()
# Broadcast the usage data to all clients
await
sio
.
emit
(
"usage"
,
{
"models"
:
models_in_use
})
await
sio
.
emit
(
"usage"
,
{
"models"
:
get_
models_in_use
()
})
async
def
remove_after_timeout
(
sid
,
model_id
):
try
:
print
(
"remove_after_timeout"
,
sid
,
model_id
)
await
asyncio
.
sleep
(
TIMEOUT_DURATION
)
if
sid
in
USAGE_POOL
:
if
model_id
in
USAGE_POOL
[
sid
][
"models"
]:
USAGE_POOL
[
sid
][
"models"
].
remove
(
model_id
)
if
len
(
USAGE_POOL
[
sid
][
"models"
])
==
0
:
del
USAGE_POOL
[
sid
]
print
(
f
"Removed usage data for
{
sid
}
due to timeout"
)
models_in_use
=
get_models_in_use
()
if
model_id
in
USAGE_POOL
:
print
(
USAGE_POOL
[
model_id
][
"sids"
])
USAGE_POOL
[
model_id
][
"sids"
].
remove
(
sid
)
USAGE_POOL
[
model_id
][
"sids"
]
=
list
(
set
(
USAGE_POOL
[
model_id
][
"sids"
]))
if
len
(
USAGE_POOL
[
model_id
][
"sids"
])
==
0
:
del
USAGE_POOL
[
model_id
]
print
(
f
"Removed usage data for
{
model_id
}
due to timeout"
)
# Broadcast the usage data to all clients
await
sio
.
emit
(
"usage"
,
{
"models"
:
models_in_use
})
await
sio
.
emit
(
"usage"
,
{
"models"
:
get_
models_in_use
()
})
except
asyncio
.
CancelledError
:
# Task was cancelled due to new 'usage' event
pass
...
...
src/lib/components/layout/Sidebar/UserMenu.svelte
View file @
92d056c9
...
...
@@ -145,7 +145,7 @@
<Tooltip
content={$USAGE_POOL && $USAGE_POOL.length > 0
? `Running: ${$USAGE_POOL.join(',')} ✨`
? `Running: ${$USAGE_POOL.join(',
')} ✨`
: ''}
>
<div class="flex rounded-md py-1.5 px-3 text-xs gap-2.5 items-center">
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment