pub struct Message {
pub role: String,
pub content: Option<String>,
pub name: Option<String>,
pub function_call: Option<FunctionCall>,
}
Fields§
§role: String
§content: Option<String>
§name: Option<String>
§function_call: Option<FunctionCall>
Implementations§
Source§impl Message
impl Message
pub fn new(role: String) -> Message
pub fn new_user_message(content: String) -> Message
pub fn set_content(&mut self, content: String)
pub fn set_name(&mut self, name: String)
pub fn set_function_call(&mut self, function_call: FunctionCall)
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for Message
A message sent by the user or the bot
impl Display for Message
A message sent by the user or the bot
Print valid JSON for Message, no commas if last field Arguments are escaped to avoid issues with quotes and newlines They break the JSON format and the API doesn’t handle them well
§Notes
The API asks for content to be present in the message, even when it’s an assistant message with a function call https://platform.openai.com/docs/api-reference/chat/create
§Examples
use chatgpt_functions::message::{FunctionCall, Message};
let mut message = Message::new("role".to_string());
assert_eq!(message.to_string(), "{\"role\":\"role\",\"content\":\"\"}".to_string());
message.set_content("content".to_string());
assert_eq!(
message.to_string(),
"{\"role\":\"role\",\"content\":\"content\"}".to_string()
);
message.set_name("name".to_string());
assert_eq!(
message.to_string(),
"{\"role\":\"role\",\"content\":\"content\",\"name\":\"name\"}".to_string()
);
message.set_function_call(FunctionCall {
name: "name".to_string(),
arguments: "arguments".to_string(),
});
assert_eq!(
message.to_string(),
"{\"role\":\"role\",\"content\":\"content\",\"name\":\"name\",\"function_call\":{\"name\":\"name\",\"arguments\":\"arguments\"}}".to_string()
);
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
Mutably borrows from an owned value. Read more