1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! Message formatter trait -- decouples wire format from LLM provider.
//!
//! Each LLM provider (OpenAI, Anthropic, custom) has its own message format.
//! The `MessageFormatter` trait handles translation so providers only deal
//! with their native format.
//!
//! # Example
//!
//! ```
//! use pe_core::formatter::MessageFormatter;
//! use pe_core::openai_formatter::OpenAiFormatter;
//! use pe_core::{Message, ToolSchema, LlmResponse};
//!
//! let formatter = OpenAiFormatter;
//! let messages = vec![Message::human("Hello"), Message::system("Be helpful")];
//! let wire = formatter.format_messages(&messages).unwrap();
//! assert!(wire.is_array());
//! ```
use cratePeError;
use crate;
use crateMessage;
/// Trait for converting between library Message types and provider-specific wire formats.
///
/// Each LLM provider has its own message format. The formatter handles
/// the translation so providers only deal with their native format.
///
/// Implementors produce `serde_json::Value` so the provider HTTP layer can
/// embed the result directly into request bodies without further conversion.