pub struct Message {
pub role: Role,
pub content: String,
pub name: Option<String>,
pub function_call: Option<FunctionCall>,
}Expand description
Definition of the message structure
as metioned in https://cloud.baidu.com/doc/WENXINWORKSHOP/s/jlil56u11, The “messages” member must not be empty. One member represents a single round of conversation, while multiple members represent multiple rounds of conversation. For example: (1) Example with one member: “messages”: [ {“role”: “user”, “content”: “Hello”}]
use erniebot_rs::chat::{Message, Role};
let message1 = Message {
role: Role::User,
content: "hello, I'm a user".to_string(),
..Default::default()
};
let messages = vec![message1];(2) Example with three members:
let message1 = Message {
role: Role::User,
content: "hello, I'm a user".to_string(),
..Default::default()
};
let message2 = Message {
role: Role::Assistant,
content: "hello, I'm a AI LLM model".to_string(),
..Default::default()
};
let message3 = Message {
role: Role::User,
content: "hello, I want you to help me".to_string(),
..Default::default()
};
let messages = vec![message1, message2, message3];The last message is the current request information, while the previous messages are historical conversation information.
The number of members must be odd. The role values of the messages in the members are explained as follows: The role value of the message at odd positions must be either “user” or “function”, while the role value of the message at even positions must be “assistant”. The role of the first message cannot be “function”. For example:
In the example, the role values of the messages are “user”, “assistant”, “user”, “assistant”, and “user” respectively. The role values of the messages at odd positions are “user”, which means the role values of the 1st, 3rd, and 5th messages are “user”. The role values at even positions are “assistant”, which means the role values of the 2nd and 4th messages are “assistant”.
Fields§
§role: RoleThe role of the message. The value can be “user”, “assistant”, or “function”(for some specific model).
content: StringThe content of the message. The value is a string.
name: Option<String>The “author” of the message. the This member is required when the role value is “function”, and in this case is should be the name in the function_call in the response content
function_call: Option<FunctionCall>this is function calling result of last round of function call, serving as chat history.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
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>,
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().