@@ -76,11 +76,14 @@ fn build_client() -> switchyard_llm_client::Result<TranslatingLlmClient> {
7676
7777``` rust
7878use switchyard_llm_client :: {LlmClientError , TranslatingLlmClient };
79- use switchyard_protocol :: {completion_text, text_request, Context , LlmResponse , Request };
79+ use switchyard_protocol :: {ContentBlock , Context , LlmRequest , LlmResponse , Message , Request , Role };
8080
8181async fn ask (client : & TranslatingLlmClient ) -> switchyard_llm_client :: Result <String > {
8282 let request = Request {
83- llm_request : text_request (None , " Say hello in five words." ),
83+ llm_request : LlmRequest {
84+ messages : vec! [Message :: text (Role :: User , " Say hello in five words." )],
85+ .. LlmRequest :: default ()
86+ },
8487 raw_request : None ,
8588 metadata : None ,
8689 };
@@ -91,7 +94,15 @@ async fn ask(client: &TranslatingLlmClient) -> switchyard_llm_client::Result<Str
9194 . await ? ;
9295
9396 match response . llm_response {
94- LlmResponse :: Agg (agg ) => Ok (completion_text (& agg )),
97+ LlmResponse :: Agg (agg ) => Ok (agg
98+ . outputs
99+ . first ()
100+ . and_then (| output | output . content. first ())
101+ . and_then (| block | match block {
102+ ContentBlock :: Text { text } => Some (text . clone ()),
103+ _ => None ,
104+ })
105+ . unwrap_or_default ()),
95106 LlmResponse :: Stream (_ ) => Err (LlmClientError :: InvalidResponse {
96107 source : " expected a buffered response" . into (),
97108 }),
@@ -106,13 +117,16 @@ Set `stream` on the IR request and drive the returned chunk stream:
106117``` rust
107118use futures_util :: StreamExt ;
108119use switchyard_llm_client :: TranslatingLlmClient ;
109- use switchyard_protocol :: {text_request, Context , LlmResponse , LlmResponseChunk , Request };
120+ use switchyard_protocol :: {Context , LlmRequest , LlmResponse , LlmResponseChunk , Message , Request , Role };
110121
111122async fn stream (
112123 client : & TranslatingLlmClient ,
113124) -> Result <(), Box <dyn std :: error :: Error + Send + Sync >> {
114- let mut llm_request = text_request (None , " Count to five." );
115- llm_request . stream = true ;
125+ let llm_request = LlmRequest {
126+ messages : vec! [Message :: text (Role :: User , " Count to five." )],
127+ stream : true ,
128+ .. LlmRequest :: default ()
129+ };
116130 let request = Request { llm_request , raw_request : None , metadata : None };
117131
118132 let response = client
0 commit comments