MCPcopy Index your code
hub / github.com/AI45Lab/Code / py_attachments_to_rust

Function py_attachments_to_rust

sdk/python/src/lib.rs:6386–6403  ·  view source on GitHub ↗

Convert Python attachment dicts to Rust Attachment vec.

(
    attachments: &[Bound<'_, PyDict>],
)

Source from the content-addressed store, hash-verified

6384
6385/// Convert Python attachment dicts to Rust Attachment vec.
6386fn py_attachments_to_rust(
6387 attachments: &[Bound<'_, PyDict>],
6388) -> PyResult<Vec<a3s_code_core::llm::Attachment>> {
6389 attachments
6390 .iter()
6391 .map(|dict| {
6392 let data: Vec<u8> = dict
6393 .get_item("data")?
6394 .ok_or_else(|| PyValueError::new_err("Attachment missing 'data' field"))?
6395 .extract()?;
6396 let media_type: String = dict
6397 .get_item("media_type")?
6398 .ok_or_else(|| PyValueError::new_err("Attachment missing 'media_type' field"))?
6399 .extract()?;
6400 Ok(a3s_code_core::llm::Attachment::new(data, media_type))
6401 })
6402 .collect()
6403}
6404
6405fn py_attachment_list_to_rust(
6406 attachments: &Bound<'_, PyList>,

Callers 2

send_with_attachmentsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected