Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
427ca9ab
Unverified
Commit
427ca9ab
authored
Nov 04, 2025
by
Yan Ru Pei
Committed by
GitHub
Nov 05, 2025
Browse files
chore: no need for explicit Python::with_gil (#4075)
Signed-off-by:
PeaBrane
<
yanrpei@gmail.com
>
parent
17af7a0f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
48 deletions
+33
-48
lib/bindings/python/rust/llm/kv.rs
lib/bindings/python/rust/llm/kv.rs
+33
-48
No files found.
lib/bindings/python/rust/llm/kv.rs
View file @
427ca9ab
...
@@ -1115,47 +1115,36 @@ impl KvPushRouter {
...
@@ -1115,47 +1115,36 @@ impl KvPushRouter {
extra_args
:
Option
<
PyObject
>
,
extra_args
:
Option
<
PyObject
>
,
)
->
PyResult
<
Bound
<
'p
,
PyAny
>>
{
)
->
PyResult
<
Bound
<
'p
,
PyAny
>>
{
// Depythonize the options with defaults
// Depythonize the options with defaults
let
(
stop_conditions
,
sampling_options
,
output_options
,
router_config_override
,
extra_args
)
=
let
stop_conditions
:
StopConditions
=
if
let
Some
(
obj
)
=
stop_conditions
{
Python
::
with_gil
(|
py
|
{
depythonize
(
obj
.bind
(
py
))
.map_err
(
to_pyerr
)
?
let
stop_conditions
:
StopConditions
=
if
let
Some
(
obj
)
=
stop_conditions
{
}
else
{
depythonize
(
obj
.bind
(
py
))
.map_err
(
to_pyerr
)
?
StopConditions
::
default
()
}
else
{
};
StopConditions
::
default
()
};
let
sampling_options
:
SamplingOptions
=
if
let
Some
(
obj
)
=
sampling_options
{
let
sampling_options
:
SamplingOptions
=
if
let
Some
(
obj
)
=
sampling_options
{
depythonize
(
obj
.bind
(
py
))
.map_err
(
to_pyerr
)
?
depythonize
(
obj
.bind
(
py
))
.map_err
(
to_pyerr
)
?
}
else
{
}
else
{
SamplingOptions
::
default
()
SamplingOptions
::
default
()
};
};
let
output_options
:
OutputOptions
=
if
let
Some
(
obj
)
=
output_options
{
let
output_options
:
OutputOptions
=
if
let
Some
(
obj
)
=
output_options
{
depythonize
(
obj
.bind
(
py
))
.map_err
(
to_pyerr
)
?
depythonize
(
obj
.bind
(
py
))
.map_err
(
to_pyerr
)
?
}
else
{
}
else
{
OutputOptions
::
default
()
OutputOptions
::
default
()
};
};
let
router_config_override
:
Option
<
llm_rs
::
kv_router
::
RouterConfigOverride
>
=
let
router_config_override
:
Option
<
llm_rs
::
kv_router
::
RouterConfigOverride
>
=
if
let
Some
(
obj
)
=
router_config_override
{
if
let
Some
(
obj
)
=
router_config_override
{
Some
(
depythonize
(
obj
.bind
(
py
))
.map_err
(
to_pyerr
)
?
)
Some
(
depythonize
(
obj
.bind
(
py
))
.map_err
(
to_pyerr
)
?
)
}
else
{
}
else
{
None
None
};
};
let
extra_args
:
Option
<
serde_json
::
Value
>
=
if
let
Some
(
obj
)
=
extra_args
{
Some
(
depythonize
(
obj
.bind
(
py
))
.map_err
(
to_pyerr
)
?
)
}
else
{
None
};
Ok
::
<
_
,
PyErr
>
((
let
extra_args
:
Option
<
serde_json
::
Value
>
=
if
let
Some
(
obj
)
=
extra_args
{
stop_conditions
,
Some
(
depythonize
(
obj
.bind
(
py
))
.map_err
(
to_pyerr
)
?
)
sampling_options
,
}
else
{
output_options
,
None
router_config_override
,
};
extra_args
,
))
})
?
;
// Build the PreprocessedRequest
// Build the PreprocessedRequest
let
mut
request_builder
=
let
mut
request_builder
=
...
@@ -1188,7 +1177,7 @@ impl KvPushRouter {
...
@@ -1188,7 +1177,7 @@ impl KvPushRouter {
)
->
PyResult
<
Bound
<
'p
,
PyAny
>>
{
)
->
PyResult
<
Bound
<
'p
,
PyAny
>>
{
// Depythonize the request directly into PreprocessedRequest
// Depythonize the request directly into PreprocessedRequest
let
request
:
llm_rs
::
protocols
::
common
::
preprocessor
::
PreprocessedRequest
=
let
request
:
llm_rs
::
protocols
::
common
::
preprocessor
::
PreprocessedRequest
=
Python
::
with_gil
(|
py
|
depythonize
(
request
.bind
(
py
))
.map_err
(
to_pyerr
)
)
?
;
depythonize
(
request
.bind
(
py
))
.map_err
(
to_pyerr
)
?
;
// Use the helper method to process the request
// Use the helper method to process the request
Self
::
process_request_to_stream
(
py
,
self
.inner
.clone
(),
request
)
Self
::
process_request_to_stream
(
py
,
self
.inner
.clone
(),
request
)
...
@@ -1203,11 +1192,9 @@ impl KvPushRouter {
...
@@ -1203,11 +1192,9 @@ impl KvPushRouter {
request_id
:
Option
<
String
>
,
request_id
:
Option
<
String
>
,
)
->
PyResult
<
Bound
<
'p
,
PyAny
>>
{
)
->
PyResult
<
Bound
<
'p
,
PyAny
>>
{
let
router_config_override
=
if
let
Some
(
obj
)
=
router_config_override
{
let
router_config_override
=
if
let
Some
(
obj
)
=
router_config_override
{
Python
::
with_gil
(|
py
|
{
let
override_config
:
llm_rs
::
kv_router
::
RouterConfigOverride
=
let
override_config
:
llm_rs
::
kv_router
::
RouterConfigOverride
=
depythonize
(
obj
.bind
(
py
))
.map_err
(
to_pyerr
)
?
;
depythonize
(
obj
.bind
(
py
))
.map_err
(
to_pyerr
)
?
;
Some
(
override_config
)
Ok
::
<
_
,
PyErr
>
(
Some
(
override_config
))
})
?
}
else
{
}
else
{
None
None
};
};
...
@@ -1250,11 +1237,9 @@ impl KvPushRouter {
...
@@ -1250,11 +1237,9 @@ impl KvPushRouter {
)
?
;
)
?
;
let
router_config_override
=
if
let
Some
(
obj
)
=
router_config_override
{
let
router_config_override
=
if
let
Some
(
obj
)
=
router_config_override
{
Python
::
with_gil
(|
py
|
{
let
override_config
:
llm_rs
::
kv_router
::
RouterConfigOverride
=
let
override_config
:
llm_rs
::
kv_router
::
RouterConfigOverride
=
depythonize
(
obj
.bind
(
py
))
.map_err
(
to_pyerr
)
?
;
depythonize
(
obj
.bind
(
py
))
.map_err
(
to_pyerr
)
?
;
Some
(
override_config
)
Ok
::
<
_
,
PyErr
>
(
Some
(
override_config
))
})
?
}
else
{
}
else
{
None
None
};
};
...
...
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