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
d7dd901f
Commit
d7dd901f
authored
Jul 09, 2024
by
Michael Poluektov
Browse files
refac: remove nesting
parent
e3e02e04
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
78 deletions
+81
-78
backend/main.py
backend/main.py
+81
-78
No files found.
backend/main.py
View file @
d7dd901f
...
...
@@ -465,51 +465,53 @@ async def chat_completion_functions_handler(
**
(
valves
if
valves
else
{})
)
if
not
hasattr
(
function_module
,
"inlet"
):
continue
try
:
if
hasattr
(
function_module
,
"inlet"
):
inlet
=
function_module
.
inlet
# Get the signature of the function
sig
=
inspect
.
signature
(
inlet
)
params
=
{
"body"
:
body
}
# Extra parameters to be passed to the function
extra_params
=
{
"__model__"
:
model
,
"__id__"
:
filter_id
,
"__event_emitter__"
:
__event_emitter__
,
"__event_call__"
:
__event_call__
,
inlet
=
function_module
.
inlet
# Get the signature of the function
sig
=
inspect
.
signature
(
inlet
)
params
=
{
"body"
:
body
}
# Extra parameters to be passed to the function
extra_params
=
{
"__model__"
:
model
,
"__id__"
:
filter_id
,
"__event_emitter__"
:
__event_emitter__
,
"__event_call__"
:
__event_call__
,
}
# Add extra params in contained in function signature
for
key
,
value
in
extra_params
.
items
():
if
key
in
sig
.
parameters
:
params
[
key
]
=
value
if
"__user__"
in
sig
.
parameters
:
__user__
=
{
"id"
:
user
.
id
,
"email"
:
user
.
email
,
"name"
:
user
.
name
,
"role"
:
user
.
role
,
}
# Add extra params in contained in function signature
for
key
,
value
in
extra_params
.
items
():
if
key
in
sig
.
parameters
:
params
[
key
]
=
value
if
"__user__"
in
sig
.
parameters
:
__user__
=
{
"id"
:
user
.
id
,
"email"
:
user
.
email
,
"name"
:
user
.
name
,
"role"
:
user
.
role
,
}
try
:
if
hasattr
(
function_module
,
"UserValves"
):
__user__
[
"valves"
]
=
function_module
.
UserValves
(
**
Functions
.
get_user_valves_by_id_and_user_id
(
filter_id
,
user
.
id
)
try
:
if
hasattr
(
function_module
,
"UserValves"
):
__user__
[
"valves"
]
=
function_module
.
UserValves
(
**
Functions
.
get_user_valves_by_id_and_user_id
(
filter_id
,
user
.
id
)
except
Exception
as
e
:
print
(
e
)
)
except
Exception
as
e
:
print
(
e
)
params
=
{
**
params
,
"__user__"
:
__user__
}
params
=
{
**
params
,
"__user__"
:
__user__
}
if
inspect
.
iscoroutinefunction
(
inlet
):
body
=
await
inlet
(
**
params
)
else
:
body
=
inlet
(
**
params
)
if
inspect
.
iscoroutinefunction
(
inlet
):
body
=
await
inlet
(
**
params
)
else
:
body
=
inlet
(
**
params
)
except
Exception
as
e
:
print
(
f
"Error:
{
e
}
"
)
...
...
@@ -1184,51 +1186,52 @@ async def chat_completed(form_data: dict, user=Depends(get_verified_user)):
**
(
valves
if
valves
else
{})
)
if
not
hasattr
(
function_module
,
"outlet"
):
continue
try
:
if
hasattr
(
function_module
,
"outlet"
):
outlet
=
function_module
.
outlet
# Get the signature of the function
sig
=
inspect
.
signature
(
outlet
)
params
=
{
"body"
:
data
}
# Extra parameters to be passed to the function
extra_params
=
{
"__model__"
:
model
,
"__id__"
:
filter_id
,
"__event_emitter__"
:
__event_emitter__
,
"__event_call__"
:
__event_call__
,
outlet
=
function_module
.
outlet
# Get the signature of the function
sig
=
inspect
.
signature
(
outlet
)
params
=
{
"body"
:
data
}
# Extra parameters to be passed to the function
extra_params
=
{
"__model__"
:
model
,
"__id__"
:
filter_id
,
"__event_emitter__"
:
__event_emitter__
,
"__event_call__"
:
__event_call__
,
}
# Add extra params in contained in function signature
for
key
,
value
in
extra_params
.
items
():
if
key
in
sig
.
parameters
:
params
[
key
]
=
value
if
"__user__"
in
sig
.
parameters
:
__user__
=
{
"id"
:
user
.
id
,
"email"
:
user
.
email
,
"name"
:
user
.
name
,
"role"
:
user
.
role
,
}
# Add extra params in contained in function signature
for
key
,
value
in
extra_params
.
items
():
if
key
in
sig
.
parameters
:
params
[
key
]
=
value
if
"__user__"
in
sig
.
parameters
:
__user__
=
{
"id"
:
user
.
id
,
"email"
:
user
.
email
,
"name"
:
user
.
name
,
"role"
:
user
.
role
,
}
try
:
if
hasattr
(
function_module
,
"UserValves"
):
__user__
[
"valves"
]
=
function_module
.
UserValves
(
**
Functions
.
get_user_valves_by_id_and_user_id
(
filter_id
,
user
.
id
)
try
:
if
hasattr
(
function_module
,
"UserValves"
):
__user__
[
"valves"
]
=
function_module
.
UserValves
(
**
Functions
.
get_user_valves_by_id_and_user_id
(
filter_id
,
user
.
id
)
except
Exception
as
e
:
print
(
e
)
)
except
Exception
as
e
:
print
(
e
)
params
=
{
**
params
,
"__user__"
:
__user__
}
params
=
{
**
params
,
"__user__"
:
__user__
}
if
inspect
.
iscoroutinefunction
(
outlet
):
data
=
await
outlet
(
**
params
)
else
:
data
=
outlet
(
**
params
)
if
inspect
.
iscoroutinefunction
(
outlet
):
data
=
await
outlet
(
**
params
)
else
:
data
=
outlet
(
**
params
)
except
Exception
as
e
:
print
(
f
"Error:
{
e
}
"
)
...
...
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