chore: no need for explicit Python::with_gil (#4075)
Signed-off-by: PeaBrane <yanrpei@gmail.com>
This commit is contained in:
parent
17af7a0fef
commit
427ca9aba4
|
|
@ -1115,47 +1115,36 @@ impl KvPushRouter {
|
|||
extra_args: Option<PyObject>,
|
||||
) -> PyResult<Bound<'p, PyAny>> {
|
||||
// Depythonize the options with defaults
|
||||
let (stop_conditions, sampling_options, output_options, router_config_override, extra_args) =
|
||||
Python::with_gil(|py| {
|
||||
let stop_conditions: StopConditions = if let Some(obj) = stop_conditions {
|
||||
depythonize(obj.bind(py)).map_err(to_pyerr)?
|
||||
} else {
|
||||
StopConditions::default()
|
||||
};
|
||||
let stop_conditions: StopConditions = if let Some(obj) = stop_conditions {
|
||||
depythonize(obj.bind(py)).map_err(to_pyerr)?
|
||||
} else {
|
||||
StopConditions::default()
|
||||
};
|
||||
|
||||
let sampling_options: SamplingOptions = if let Some(obj) = sampling_options {
|
||||
depythonize(obj.bind(py)).map_err(to_pyerr)?
|
||||
} else {
|
||||
SamplingOptions::default()
|
||||
};
|
||||
let sampling_options: SamplingOptions = if let Some(obj) = sampling_options {
|
||||
depythonize(obj.bind(py)).map_err(to_pyerr)?
|
||||
} else {
|
||||
SamplingOptions::default()
|
||||
};
|
||||
|
||||
let output_options: OutputOptions = if let Some(obj) = output_options {
|
||||
depythonize(obj.bind(py)).map_err(to_pyerr)?
|
||||
} else {
|
||||
OutputOptions::default()
|
||||
};
|
||||
let output_options: OutputOptions = if let Some(obj) = output_options {
|
||||
depythonize(obj.bind(py)).map_err(to_pyerr)?
|
||||
} else {
|
||||
OutputOptions::default()
|
||||
};
|
||||
|
||||
let router_config_override: Option<llm_rs::kv_router::RouterConfigOverride> =
|
||||
if let Some(obj) = router_config_override {
|
||||
Some(depythonize(obj.bind(py)).map_err(to_pyerr)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let router_config_override: Option<llm_rs::kv_router::RouterConfigOverride> =
|
||||
if let Some(obj) = router_config_override {
|
||||
Some(depythonize(obj.bind(py)).map_err(to_pyerr)?)
|
||||
} else {
|
||||
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>((
|
||||
stop_conditions,
|
||||
sampling_options,
|
||||
output_options,
|
||||
router_config_override,
|
||||
extra_args,
|
||||
))
|
||||
})?;
|
||||
let extra_args: Option<serde_json::Value> = if let Some(obj) = extra_args {
|
||||
Some(depythonize(obj.bind(py)).map_err(to_pyerr)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Build the PreprocessedRequest
|
||||
let mut request_builder =
|
||||
|
|
@ -1188,7 +1177,7 @@ impl KvPushRouter {
|
|||
) -> PyResult<Bound<'p, PyAny>> {
|
||||
// Depythonize the request directly into 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
|
||||
Self::process_request_to_stream(py, self.inner.clone(), request)
|
||||
|
|
@ -1203,11 +1192,9 @@ impl KvPushRouter {
|
|||
request_id: Option<String>,
|
||||
) -> PyResult<Bound<'p, PyAny>> {
|
||||
let router_config_override = if let Some(obj) = router_config_override {
|
||||
Python::with_gil(|py| {
|
||||
let override_config: llm_rs::kv_router::RouterConfigOverride =
|
||||
depythonize(obj.bind(py)).map_err(to_pyerr)?;
|
||||
Ok::<_, PyErr>(Some(override_config))
|
||||
})?
|
||||
let override_config: llm_rs::kv_router::RouterConfigOverride =
|
||||
depythonize(obj.bind(py)).map_err(to_pyerr)?;
|
||||
Some(override_config)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
|
@ -1250,11 +1237,9 @@ impl KvPushRouter {
|
|||
)?;
|
||||
|
||||
let router_config_override = if let Some(obj) = router_config_override {
|
||||
Python::with_gil(|py| {
|
||||
let override_config: llm_rs::kv_router::RouterConfigOverride =
|
||||
depythonize(obj.bind(py)).map_err(to_pyerr)?;
|
||||
Ok::<_, PyErr>(Some(override_config))
|
||||
})?
|
||||
let override_config: llm_rs::kv_router::RouterConfigOverride =
|
||||
depythonize(obj.bind(py)).map_err(to_pyerr)?;
|
||||
Some(override_config)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue