MCPcopy Create free account
hub / github.com/BerriAI/litellm / begin

Method begin

litellm-rust/crates/python-bridge/src/cache/python/host.rs:45–90  ·  view source on GitHub ↗
(&mut self, py: Python<'_>, call: CacheCall)

Source from the content-addressed store, hash-verified

43 }
44
45 pub fn begin(&mut self, py: Python<'_>, call: CacheCall) -> PyResult<Option<Py<PyAny>>> {
46 let Some(cache) = self.cache.as_ref() else {
47 return Err(HandleError::Unconfigured.into());
48 };
49 let arguments = self
50 .arguments
51 .as_ref()
52 .ok_or(HandleError::MissingArguments)?
53 .bind(py)
54 .copy()?;
55 let (method, result) = match call {
56 CacheCall::Lookup { reply } => {
57 self.pending = Some(Pending::Lookup(reply));
58 (
59 if self.asynchronous {
60 "async_get_cache"
61 } else {
62 "get_cache"
63 },
64 None,
65 )
66 }
67 CacheCall::Store { value, reply } => {
68 self.pending = Some(Pending::Store(reply));
69 (
70 if self.asynchronous {
71 "async_add_cache"
72 } else {
73 "add_cache"
74 },
75 Some(to_py(py, &value)?),
76 )
77 }
78 };
79 let result = match result {
80 Some(value) => cache
81 .bind(py)
82 .call_method(method, (value,), Some(&arguments)),
83 None => cache.bind(py).call_method(method, (), Some(&arguments)),
84 }
85 .map(Bound::unbind);
86 if self.asynchronous && result.is_ok() {
87 return result.map(Some);
88 }
89 self.resume(py, result)
90 }
91
92 pub fn resume(
93 &mut self,

Calls 8

to_pyFunction · 0.85
LookupClass · 0.50
StoreClass · 0.50
copyMethod · 0.45
bindMethod · 0.45
mapMethod · 0.45
is_okMethod · 0.45
resumeMethod · 0.45