pub enum PartEnum {
Reasoning(Reasoning),
Text(Text),
FunctionCall(FunctionCall),
FunctionResponse(FunctionResponse),
Structured(Value),
File(File),
Embeddings(Embeddings),
}Variants§
Reasoning(Reasoning)
Text(Text)
FunctionCall(FunctionCall)
FunctionResponse(FunctionResponse)
Structured(Value)
File(File)
Embeddings(Embeddings)
Implementations§
Source§impl PartEnum
impl PartEnum
pub fn function_call(&self) -> Option<FunctionCall>
pub fn function_response(&self) -> Option<FunctionResponse>
pub fn text(&self) -> Option<Text>
Sourcepub fn reasoning(&self) -> Option<Reasoning>
pub fn reasoning(&self) -> Option<Reasoning>
Retrieve the reasoning text if this part is the Reasoning variant.
§Returns
Some(Text) containing the reasoning text if this is a Reasoning variant, None otherwise.
§Examples
let part = PartEnum::from_reasoning("because it's correct");
let text = part.reasoning().unwrap();
assert_eq!(text, Text::new("because it's correct"));Sourcepub fn embeddings(&self) -> Option<Embeddings>
pub fn embeddings(&self) -> Option<Embeddings>
Get the contained embeddings when the variant is Embeddings.
§Returns
Some(Embeddings) with a cloned value when the part is PartEnum::Embeddings, None otherwise.
§Examples
use crate::messages::parts::PartEnum;
use crate::messages::embeddings::Embeddings;
let emb = Embeddings { content: vec![0.1_f32, 0.2, 0.3] };
let part = PartEnum::from_embeddings(emb.clone());
assert_eq!(part.embeddings(), Some(emb));Sourcepub fn structured(&self) -> Option<Value>
pub fn structured(&self) -> Option<Value>
Returns the contained JSON value if this part is a Structured variant.
§Examples
use serde_json::json;
use crate::core::messages::parts::PartEnum;
let part = PartEnum::Structured(json!({"key": "value"}));
assert_eq!(part.structured(), Some(json!({"key": "value"})));Sourcepub fn file(&self) -> Option<File>
pub fn file(&self) -> Option<File>
Accesses the contained File when this enum is the File variant.
§Returns
Some(File) containing the file when the variant is PartEnum::File, None otherwise.
§Examples
use crate::core::messages::parts::PartEnum;
use crate::messages::file::File;
let file = File::default();
let part = PartEnum::from_file(file.clone());
assert_eq!(part.file(), Some(file));Sourcepub fn from_reasoning(s: impl Into<String>) -> PartEnum
pub fn from_reasoning(s: impl Into<String>) -> PartEnum
Creates a PartEnum::Reasoning from the provided string.
§Examples
let part = PartEnum::from_reasoning("inference detail");
match part {
PartEnum::Reasoning(text) => assert_eq!(text.as_str(), "inference detail"),
_ => panic!("expected Reasoning variant"),
}pub fn from_text(s: impl Into<String>) -> PartEnum
Sourcepub fn from_function_call(fc: FunctionCall) -> PartEnum
pub fn from_function_call(fc: FunctionCall) -> PartEnum
Creates a PartEnum containing the given FunctionCall.
Returns the PartEnum::FunctionCall variant wrapping fc.
§Examples
let fc = FunctionCall::default(); // construct a FunctionCall as appropriate
let part = PartEnum::from_function_call(fc);
matches!(part, PartEnum::FunctionCall(_));Sourcepub fn from_function_response(fr: FunctionResponse) -> PartEnum
pub fn from_function_response(fr: FunctionResponse) -> PartEnum
Sourcepub fn from_embeddings(embeddings: Embeddings) -> PartEnum
pub fn from_embeddings(embeddings: Embeddings) -> PartEnum
Creates a PartEnum that wraps the provided Embeddings.
§Examples
let embeddings = /* obtain an Embeddings value */ unimplemented!();
let part = from_embeddings(embeddings);
match part {
PartEnum::Embeddings(e) => { /* use `e` */ }
_ => unreachable!(),
}Sourcepub fn from_structured(value: Value) -> PartEnum
pub fn from_structured(value: Value) -> PartEnum
Creates a PartEnum::Structured variant containing the given JSON value.
§Examples
use serde_json::json;
let value = json!({ "key": "value" });
let part = PartEnum::from_structured(value.clone());
match part {
PartEnum::Structured(v) => assert_eq!(v, value),
_ => panic!("expected Structured variant"),
}Trait Implementations§
Source§impl<'de> Deserialize<'de> for PartEnum
impl<'de> Deserialize<'de> for PartEnum
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<PartEnum, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<PartEnum, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for PartEnum
impl Display for PartEnum
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Render a PartEnum as a concise, human-readable string.
Each variant is represented as:
Structured: the JSON value is printed.ReasoningandText: the contained text is printed.FunctionCallandFunctionResponse: the function name is printed.File: prints the URL and MIME type forFile::Url, or the MIME type forFile::Bytes.Embeddings: if the embedding vector is empty prints[]; if it has 1–3 elements prints the debug representation of the full vector; if it has more than 3 elements prints a truncated preview formatted as[first, second, ..., last]with 4-decimal precision for the shown values.
§Examples
let p = PartEnum::from_text("hello");
assert_eq!(format!("{}", p), "hello");