Skip to main content

PartEnum

Enum PartEnum 

Source
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

Source

pub fn function_call(&self) -> Option<FunctionCall>

Source

pub fn function_response(&self) -> Option<FunctionResponse>

Source

pub fn text(&self) -> Option<Text>

Source

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"));
Source

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));
Source

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"})));
Source

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));
Source

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"),
}
Source

pub fn from_text(s: impl Into<String>) -> PartEnum

Source

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(_));
Source

pub fn from_function_response(fr: FunctionResponse) -> PartEnum

Wraps a FunctionResponse in a PartEnum::FunctionResponse.

§Parameters
  • fr: the FunctionResponse to wrap.
§Returns

A PartEnum::FunctionResponse containing the provided FunctionResponse.

Source

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!(),
}
Source

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"),
}
Source

pub fn from_file(file: File) -> PartEnum

Creates a PartEnum::File variant containing the provided File.

§Examples
let file: File = /* obtain or construct a File */ unimplemented!();
let part = PartEnum::from_file(file);
match part {
    PartEnum::File(f) => { /* use f */ },
    _ => unreachable!(),
}

Trait Implementations§

Source§

impl Clone for PartEnum

Source§

fn clone(&self) -> PartEnum

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PartEnum

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for PartEnum

Source§

fn default() -> PartEnum

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for PartEnum

Source§

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

Source§

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.
  • Reasoning and Text: the contained text is printed.
  • FunctionCall and FunctionResponse: the function name is printed.
  • File: prints the URL and MIME type for File::Url, or the MIME type for File::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 PartialEq for PartEnum

Source§

fn eq(&self, other: &PartEnum) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for PartEnum

Source§

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
Source§

impl StructuralPartialEq for PartEnum

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,