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>
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
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
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
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>,
Deserialize this value from the given Serde deserializer. Read more
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");Source§impl Serialize for PartEnum
impl Serialize for PartEnum
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl StructuralPartialEq for PartEnum
Auto Trait Implementations§
impl Freeze for PartEnum
impl RefUnwindSafe for PartEnum
impl Send for PartEnum
impl Sync for PartEnum
impl Unpin for PartEnum
impl UnsafeUnpin for PartEnum
impl UnwindSafe for PartEnum
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more