pub enum UserContent {
Text {
text: String,
},
ImageUrl {
image_url: ImageUrl,
},
File {
file: FileContent,
},
}Expand description
User content types supported by OpenRouter.
OpenRouter uses different content type structures than OpenAI’s Chat Completions API, particularly for file/document content. This enum matches OpenRouter’s API specification.
§Supported Content Types
- Text: Plain text content
- ImageUrl: Images via URL or base64 data URI
- File: PDF documents and other files via URL or base64 data URI
§Example
use rig::providers::openrouter::UserContent;
// Text content
let text = UserContent::text("Hello, world!");
// Image from URL
let image = UserContent::image_url("https://example.com/image.png");
// PDF from URL
let pdf = UserContent::file_url("https://example.com/document.pdf", Some("document.pdf".to_string()));Variants§
Text
Plain text content
ImageUrl
Image content (URL or base64 data URI)
Supports: image/png, image/jpeg, image/webp, image/gif
File
File content (for PDFs and other documents)
Uses file_data field which accepts either a publicly accessible URL
or base64-encoded content as a data URI.
Fields
§
file: FileContentImplementations§
Source§impl UserContent
impl UserContent
Sourcepub fn image_url_with_detail(
url: impl Into<String>,
detail: ImageDetail,
) -> Self
pub fn image_url_with_detail( url: impl Into<String>, detail: ImageDetail, ) -> Self
Create image content from URL with detail level
Sourcepub fn image_base64(
data: impl Into<String>,
mime_type: &str,
detail: Option<ImageDetail>,
) -> Self
pub fn image_base64( data: impl Into<String>, mime_type: &str, detail: Option<ImageDetail>, ) -> Self
Create image content from base64 data
§Arguments
data- Base64-encoded image datamime_type- MIME type (e.g., “image/png”, “image/jpeg”)detail- Optional detail level for image processing
Trait Implementations§
Source§impl Clone for UserContent
impl Clone for UserContent
Source§fn clone(&self) -> UserContent
fn clone(&self) -> UserContent
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UserContent
impl Debug for UserContent
Source§impl<'de> Deserialize<'de> for UserContent
impl<'de> Deserialize<'de> for UserContent
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 From<&str> for UserContent
impl From<&str> for UserContent
Source§impl From<String> for UserContent
impl From<String> for UserContent
Source§impl From<UserContent> for UserContent
Convert OpenAI’s UserContent to OpenRouter’s UserContent
impl From<UserContent> for UserContent
Convert OpenAI’s UserContent to OpenRouter’s UserContent
Source§fn from(value: UserContent) -> Self
fn from(value: UserContent) -> Self
Converts to this type from the input type.
Source§impl FromStr for UserContent
impl FromStr for UserContent
Source§impl PartialEq for UserContent
impl PartialEq for UserContent
Source§impl Serialize for UserContent
impl Serialize for UserContent
Source§impl TryFrom<UserContent> for UserContent
impl TryFrom<UserContent> for UserContent
Source§type Error = MessageError
type Error = MessageError
The type returned in the event of a conversion error.
impl StructuralPartialEq for UserContent
Auto Trait Implementations§
impl Freeze for UserContent
impl RefUnwindSafe for UserContent
impl Send for UserContent
impl Sync for UserContent
impl Unpin for UserContent
impl UnsafeUnpin for UserContent
impl UnwindSafe for UserContent
Blanket Implementations§
Source§impl<T> ArgumentConvert for Twhere
T: FromStr,
impl<T> ArgumentConvert for Twhere
T: FromStr,
Source§fn convert<'life0, 'async_trait>(
__arg0: impl CacheHttp + 'async_trait,
__arg1: Option<GuildId>,
__arg2: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<T, <T as ArgumentConvert>::Err>> + Send + 'async_trait>>where
'life0: 'async_trait,
T: 'async_trait,
fn convert<'life0, 'async_trait>(
__arg0: impl CacheHttp + 'async_trait,
__arg1: Option<GuildId>,
__arg2: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<T, <T as ArgumentConvert>::Err>> + Send + 'async_trait>>where
'life0: 'async_trait,
T: 'async_trait,
Parses a string
s as a command parameter of this type.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
Source§impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more