pub struct OpenAiFormatter;Expand description
Formatter for the OpenAI chat completions wire format.
Handles conversion between pe-core types and the JSON structure expected by OpenAI and OpenAI-compatible APIs.
§Example
use pe_core::openai_formatter::OpenAiFormatter;
use pe_core::formatter::MessageFormatter;
use pe_core::Message;
let fmt = OpenAiFormatter;
let wire = fmt.format_messages(&[Message::human("Hi")]).unwrap();
assert_eq!(wire[0]["role"], "user");
assert_eq!(wire[0]["content"], "Hi");Trait Implementations§
Source§impl MessageFormatter for OpenAiFormatter
impl MessageFormatter for OpenAiFormatter
Source§fn format_messages(&self, messages: &[Message]) -> Result<Value, PeError>
fn format_messages(&self, messages: &[Message]) -> Result<Value, PeError>
Convert library messages to the provider’s wire format (as JSON Value). Read more
Source§fn format_tools(&self, tools: &[ToolSchema]) -> Result<Value, PeError>
fn format_tools(&self, tools: &[ToolSchema]) -> Result<Value, PeError>
Convert tool schemas to the provider’s tool format (as JSON Value). Read more
Source§fn parse_response(&self, raw: &Value) -> Result<LlmResponse, PeError>
fn parse_response(&self, raw: &Value) -> Result<LlmResponse, PeError>
Parse a provider response back into library types. Read more
Auto Trait Implementations§
impl Freeze for OpenAiFormatter
impl RefUnwindSafe for OpenAiFormatter
impl Send for OpenAiFormatter
impl Sync for OpenAiFormatter
impl Unpin for OpenAiFormatter
impl UnsafeUnpin for OpenAiFormatter
impl UnwindSafe for OpenAiFormatter
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