Skip to main content

Warning

Struct Warning 

Source
#[non_exhaustive]
pub struct Warning { pub kind: WarningKind, pub subject: Subject, pub provider: Option<Cow<'static, str>>, pub code: Option<Cow<'static, str>>, pub message: String, pub cause: Option<WarningCause>, /* private fields */ }
Expand description

A non-fatal issue reported alongside a successful response.

§Emission

A warning remembers whether it was already emitted as a warning event (emit), so a wrapper that passes it on emits it no second time. The mark is not serialized and is ignored by ==. A clone keeps it: a warning copied into another response and passed through Prepared::finish again is not logged again. A deserialized warning is unmarked, so it is emitted again by the next layer that finishes a call with it (see the module docs on response caches).

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§kind: WarningKind

What kind of degradation happened.

§subject: Subject

What the warning is about.

§provider: Option<Cow<'static, str>>

Provider that produced the warning, when known.

§code: Option<Cow<'static, str>>

A stable code for the condition (unsupported.seed), when the producer gives one.

A code says the warning describes the shape of a request or of the configuration, so it recurs on every call that has that shape: its warning event goes out at WARN once per provider, model, kind and code, then at DEBUG (see the module docs). A warning without a code is about this call alone (a failover, content the application sent) and its event is WARN every time. A limitation about content that history repeats on every turn is coded all the same (approximated.tool_result_error, see Degradations::coded_approximated). Degradations gives a warning about a request field or a system prompt the code <kind>.<field> (unsupported.seed, dropped.system) when it has none.

§message: String

Human-readable explanation.

§cause: Option<WarningCause>

The failure behind the warning, for a warning a failure caused: the error a FallbackProvider failed over on. Structured, so failovers can be counted by cause.

Implementations§

Source§

impl Warning

Source

pub fn new( kind: WarningKind, subject: Subject, message: impl Into<String>, ) -> Self

Create a warning.

Source

pub fn unsupported(field: RequestField, message: impl Into<String>) -> Self

An unsupported-field warning.

Source

pub fn with_provider(self, provider: impl Into<Cow<'static, str>>) -> Self

Set the provider identity.

Source

pub fn with_code(self, code: &'static str) -> Self

Set a stable code for the condition (see code).

Give one to a warning that recurs on every call with the same request shape or configuration, such as a hint the model never takes; leave it out for a warning about this call alone.

Source

pub fn recurs(&self) -> bool

Whether the warning recurs on every call with the same request shape or configuration: whether it has a code.

A recurring warning says the same thing on the next call, so an application shows it once, with SeenWarnings. A warning that does not recur is about this call alone (a failover, content the application sent) and is worth showing every time.

use allama::{RequestField, Subject, Warning, WarningKind};

let seed = Warning::unsupported(RequestField::Seed, "demo has no seed; `seed` was not sent")
    .with_code("unsupported.seed");
assert!(seed.recurs());

let failover = Warning::new(
    WarningKind::Fallback,
    Subject::Response,
    "failed with `overloaded`; served by `b`",
);
assert!(!failover.recurs());
Source

pub fn replay_state(&self) -> Option<ReplayState>

The replay state the warning reports as dropped: a Dropped warning coded with a ReplayState::code, as Degradations::dropped_replay_state records it.

Match on it, rather than on the message, to tell the user about replay state in your own words:

use allama::adapter::Degradations;
use allama::{ReplayState, Subject, UnsupportedPolicy};

let mut d = Degradations::new("demo", UnsupportedPolicy::Warn);
d.dropped_replay_state(
    ReplayState::ForeignReasoning,
    Subject::Content { message: 1, block: Some(0) },
    "reasoning from `openai` can be replayed only to its origin; it was dropped",
);
let state = d.warnings()[0].replay_state();
assert_eq!(state, Some(ReplayState::ForeignReasoning));
assert!(state.is_some_and(ReplayState::is_foreign));
Source

pub fn with_cause(self, cause: WarningCause) -> Self

Set the failure behind the warning (see cause).

Trait Implementations§

Source§

impl Clone for Warning

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Warning

Source§

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

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

impl<'de> Deserialize<'de> for Warning

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Warning

The provider in brackets, then where the warning applies for a warning about content, then the message: [ollama] message 3, block 0: ….

The location is shown for Subject::Content (message 3, block 0) and Subject::EmbeddingInput (embedding input 2, part 1), whose message cannot say which block it is about. Indices are zero-based and those of the caller’s request: message indexes ChatRequest::messages, so system prompts, which are ChatRequest::system, do not count. Other subjects are named by the message itself ( `seed` was not sent), so nothing is added.

use allama::{Subject, Warning, WarningKind};

let content = Subject::Content { message: 3, block: Some(0) };
let warning = Warning::new(WarningKind::Dropped, content, "`ollama` takes no reasoning back; it was dropped")
    .with_provider("ollama");
assert_eq!(
    warning.to_string(),
    "[ollama] message 3, block 0: `ollama` takes no reasoning back; it was dropped"
);
Source§

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

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

impl Eq for Warning

Source§

impl Extend<Warning> for Degradations

Source§

fn extend<I: IntoIterator<Item = Warning>>(&mut self, warnings: I)

Record warnings collected elsewhere, such as an encoder’s, as warn does.

Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl PartialEq for Warning

Source§

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

Compares everything but whether the warning was emitted.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Warning

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more