molo 0.2.3

A lightweight Rust agent framework
Documentation
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
//! Test helper: a programmable fake Provider.
//!
//! A script is a sequence of per-turn replies ([`FakeReply`]); each `chat` /
//! `stream_chat` call consumes one turn, and the received requests are
//! recorded so tests can assert the Agent loop's process behavior (whether
//! tool results are fed back, whether history is appended in order, etc.).
//!
//! It is positioned as a test helper, not a production component: unit tests
//! of the Agent loop use it to inject deterministic replies without depending
//! on a real API; users testing their own Agent loops can do the same.

use crate::message::{Message, ToolCall};
use crate::provider::{
    ChatRequest, ChatResponse, FinishReason, Provider, ProviderError, StreamEvent, Usage,
};
use futures::stream::BoxStream;
use std::collections::VecDeque;
use std::sync::{Arc, Mutex};

/// The error message returned once the script is exhausted.
const EXHAUSTED_MSG: &str = "fake provider: script exhausted";

/// One turn of reply from the script.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FakeReply {
    /// Plain text reply (`FinishReason::Stop`).
    Text(String),
    /// Text + reasoning (thinking-model scenario; reasoning is carried back
    /// verbatim in the history).
    TextWithReasoning {
        /// Reply text.
        content: String,
        /// Reasoning.
        reasoning: String,
    },
    /// Text + requests to call several tools (multiple requests from the same
    /// turn stay in one message); the text may be empty.
    ToolCalls {
        /// Reply text (may be empty).
        content: String,
        /// Tool calls requested this turn.
        calls: Vec<ToolCall>,
    },
    /// Specifies this turn's usage (default zero); wraps a base reply
    /// variant. Use it when a test needs to assert concrete token counts
    /// (e.g. the Agent's summation); existing script styles keep working
    /// unchanged.
    WithUsage {
        /// The wrapped base reply.
        reply: Box<FakeReply>,
        /// This turn's usage.
        usage: Usage,
    },
    /// This turn fails outright; the error is returned to the caller as-is.
    Error(ProviderError),
}

impl FakeReply {
    /// Convenience constructor: text reply + specified usage.
    pub fn text_with_usage(content: impl Into<String>, usage: Usage) -> Self {
        Self::WithUsage {
            reply: Box::new(Self::Text(content.into())),
            usage,
        }
    }
}

/// A programmable fake [`Provider`] — a script is a sequence of per-turn
/// replies, consumed in order by `chat` / `stream_chat`.
///
/// - Each call consumes one script turn and records the request; **once the
///   script is exhausted, calls return
///   [`ProviderError::Api`](ProviderError::Api)("script exhausted") and do not
///   replay** — an Agent running an extra turn fails explicitly right away in
///   tests;
/// - `chat` and `stream_chat` consume the same script with the same
///   semantics, differing only in how the reply is delivered (an event stream
///   = several increments + one `Done`);
/// - [`requests`](FakeProvider::requests) returns a snapshot of the received
///   request history for tests to assert what the Agent sent to the model —
///   since a fake is lenient (e.g. if the Agent forgets to feed back tool
///   results, a real API would error but the fake would not), this is the
///   only way to catch such process bugs.
///
/// # Examples
///
/// ```rust
/// # #[tokio::main]
/// # async fn main() -> Result<(), molo::ProviderError> {
/// use molo::message::Message;
/// use molo::provider::{ChatRequest, FakeProvider, FakeReply, Provider};
///
/// let fake = FakeProvider::new([
///     FakeReply::Text("hi".into()),
///     FakeReply::Text("bye".into()),
/// ]);
///
/// let r = fake.chat(ChatRequest::default()).await?;
/// assert_eq!(r.message, Message::assistant("hi"));
/// # Ok(())
/// # }
/// ```
#[derive(Debug, Default)]
pub struct FakeProvider {
    /// The script to consume; each call pops from the front of the queue.
    replies: Mutex<VecDeque<FakeReply>>,
    /// Received request history (recorded whether or not the script is
    /// exhausted).
    requests: Mutex<Vec<ChatRequest>>,
}

impl Clone for FakeProvider {
    /// Clones are independent copies: each holds and consumes its own script
    /// queue and request history without affecting the other (script calls
    /// made before the clone still consume from the start in the clone).
    fn clone(&self) -> Self {
        // std Mutex has no Clone: copy the contents under the lock and
        // rebuild (a std Mutex cannot clone two locks at once).
        let replies = self
            .replies
            .lock()
            .expect("FakeProvider internal lock poisoned")
            .clone();
        let requests = self
            .requests
            .lock()
            .expect("FakeProvider internal lock poisoned")
            .clone();
        Self {
            replies: Mutex::new(replies),
            requests: Mutex::new(requests),
        }
    }
}

impl FakeProvider {
    /// Constructs from a script sequence; `chat` / `stream_chat` consume it
    /// in order and error once exhausted.
    pub fn new(replies: impl IntoIterator<Item = FakeReply>) -> Self {
        Self {
            replies: Mutex::new(replies.into_iter().collect()),
            requests: Mutex::new(Vec::new()),
        }
    }

    /// Appends one reply to the end of the script (for staged injection in
    /// tests).
    pub fn push(&self, reply: FakeReply) {
        self.replies
            .lock()
            .expect("FakeProvider internal lock poisoned")
            .push_back(reply);
    }

    /// A snapshot of the received request history, for tests to assert what
    /// the Agent sent to the model.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # #[tokio::main]
    /// # async fn main() -> Result<(), molo::ProviderError> {
    /// use molo::message::Message;
    /// use molo::provider::{ChatRequest, FakeProvider, FakeReply, Provider};
    ///
    /// let fake = FakeProvider::new([FakeReply::Text("hi".into())]);
    /// fake.chat(ChatRequest {
    ///     messages: vec![Message::user("hi")],
    ///     ..Default::default()
    /// })
    /// .await?;
    ///
    /// assert_eq!(fake.requests()[0].messages, vec![Message::user("hi")]);
    /// # Ok(())
    /// # }
    /// ```
    pub fn requests(&self) -> Vec<ChatRequest> {
        self.requests
            .lock()
            .expect("FakeProvider internal lock poisoned")
            .clone()
    }
}

#[async_trait::async_trait]
impl Provider for FakeProvider {
    async fn chat(&self, request: ChatRequest) -> Result<ChatResponse, ProviderError> {
        self.requests
            .lock()
            .expect("FakeProvider internal lock poisoned")
            .push(request);
        match self
            .replies
            .lock()
            .expect("FakeProvider internal lock poisoned")
            .pop_front()
        {
            // Script exhaustion is not a vendor error: status 0 = non-HTTP
            // source, naturally distinct from HTTP errors returned by a
            // vendor (see the field docs on ProviderError::Api).
            None => Err(ProviderError::Api {
                status: 0,
                message: EXHAUSTED_MSG.to_string(),
            }),
            Some(reply) => chat_response(reply),
        }
    }

    async fn stream_chat(
        &self,
        request: ChatRequest,
    ) -> Result<BoxStream<'static, Result<StreamEvent, ProviderError>>, ProviderError> {
        self.requests
            .lock()
            .expect("FakeProvider internal lock poisoned")
            .push(request);
        // Unwrap the usage override recursively first (same as chat:
        // WithUsage only changes this turn's usage, not the reply body;
        // nested WithUsage also unwraps correctly).
        let (reply, usage_override) = match self
            .replies
            .lock()
            .expect("FakeProvider internal lock poisoned")
            .pop_front()
        {
            None => {
                return Err(ProviderError::Api {
                    status: 0,
                    message: EXHAUSTED_MSG.to_string(),
                });
            }
            Some(reply) => unwrap_usage(reply),
        };
        let mut events = stream_events(reply)?;
        if let Some(usage) = usage_override {
            // The last event in the sequence is always Done; replace its
            // usage.
            if let Some(Ok(StreamEvent::Done {
                usage: done_usage, ..
            })) = events.last_mut()
            {
                *done_usage = Some(usage);
            }
        }
        Ok(Box::pin(futures::stream::iter(events)))
    }
}

/// Converts one script reply into a non-streaming response.
///
/// Usage defaults to zero; `WithUsage` wrappers are unwrapped recursively and
/// overridden with the injected value (matching the streaming path).
fn chat_response(reply: FakeReply) -> Result<ChatResponse, ProviderError> {
    match reply {
        // Boundary behavior consistent with chat: this turn's failure is
        // returned as Err directly.
        FakeReply::Error(e) => Err(e),
        FakeReply::WithUsage { reply, usage } => {
            let mut response = chat_response(*reply)?;
            response.usage = usage;
            Ok(response)
        }
        FakeReply::Text(content) => Ok(ChatResponse {
            message: Message::assistant(content),
            finish_reason: FinishReason::Stop,
            usage: Usage::default(),
        }),
        FakeReply::TextWithReasoning { content, reasoning } => Ok(ChatResponse {
            message: Message::assistant_with_reasoning(content, reasoning),
            finish_reason: FinishReason::Stop,
            usage: Usage::default(),
        }),
        FakeReply::ToolCalls { content, calls } => Ok(ChatResponse {
            message: Message::Assistant {
                content,
                reasoning: None,
                tool_calls: calls,
            },
            finish_reason: FinishReason::Stop,
            usage: Usage::default(),
        }),
    }
}

/// Recursively unwraps `WithUsage` (matching the chat path): the outer usage
/// wins, the inner one is the fallback — nested `WithUsage(WithUsage(...))`
/// also unwraps correctly without panicking.
fn unwrap_usage(reply: FakeReply) -> (FakeReply, Option<Usage>) {
    match reply {
        FakeReply::WithUsage { reply, usage } => {
            let (inner, inner_usage) = unwrap_usage(*reply);
            (inner, Some(usage).or(inner_usage))
        }
        other => (other, None),
    }
}

/// Converts one script reply into a stream of events.
///
/// Unwrapped replies always carry zero usage (`Some`) — the fake mimics an
/// endpoint with `include_usage` on, so streaming-summary tests can assert
/// stably; `WithUsage` must be unwrapped by the caller first (this function
/// does not handle it, and its fallback arm returns an error rather than
/// panicking on an unwrapped call).
fn stream_events(
    reply: FakeReply,
) -> Result<Vec<Result<StreamEvent, ProviderError>>, ProviderError> {
    match reply {
        // Boundary behavior consistent with chat: this turn's failure makes
        // the method return Err directly.
        FakeReply::Error(e) => Err(e),
        FakeReply::Text(content) => Ok(vec![
            Ok(StreamEvent::Delta(content)),
            Ok(StreamEvent::Done {
                reason: FinishReason::Stop,
                usage: Some(Usage::default()),
            }),
        ]),
        // Scripted order: the content Delta first, then the Reasoning
        // fragment, then Done.
        FakeReply::TextWithReasoning { content, reasoning } => Ok(vec![
            Ok(StreamEvent::Delta(content)),
            Ok(StreamEvent::Reasoning(reasoning)),
            Ok(StreamEvent::Done {
                reason: FinishReason::Stop,
                usage: Some(Usage::default()),
            }),
        ]),
        FakeReply::ToolCalls { content, calls } => {
            let mut events = Vec::new();
            if !content.is_empty() {
                events.push(Ok(StreamEvent::Delta(content)));
            }
            events.extend(calls.into_iter().map(|c| {
                Ok(StreamEvent::ToolCall {
                    id: c.id,
                    name: c.name,
                    arguments: c.arguments,
                })
            }));
            events.push(Ok(StreamEvent::Done {
                reason: FinishReason::Stop,
                usage: Some(Usage::default()),
            }));
            Ok(events)
        }
        // Defensive fallback: on the normal path the caller (stream_chat) has
        // already unwrapped recursively, so this arm should not be reached;
        // return an error rather than panicking on an unwrapped call.
        FakeReply::WithUsage { .. } => Err(ProviderError::Api {
            status: 0,
            message: "internal error: WithUsage must be unwrapped before stream_events".into(),
        }),
    }
}

/// `Arc<FakeProvider>` is also a Provider: tests share one instance behind an
/// Arc (used when wrapper tests assert internal request counts, such as
/// RetryProvider's attempt count).
#[async_trait::async_trait]
impl Provider for Arc<FakeProvider> {
    async fn chat(&self, request: ChatRequest) -> Result<ChatResponse, ProviderError> {
        self.as_ref().chat(request).await
    }

    async fn stream_chat(
        &self,
        request: ChatRequest,
    ) -> Result<BoxStream<'static, Result<StreamEvent, ProviderError>>, ProviderError> {
        self.as_ref().stream_chat(request).await
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::message::Message;
    use futures::StreamExt;

    #[tokio::test]
    async fn chat_consumes_script_in_order() {
        let fake = FakeProvider::new([FakeReply::Text("a".into()), FakeReply::Text("b".into())]);

        let r1 = fake.chat(ChatRequest::default()).await.unwrap();
        assert_eq!(r1.message, Message::assistant("a"));
        assert_eq!(r1.finish_reason, FinishReason::Stop);

        let r2 = fake.chat(ChatRequest::default()).await.unwrap();
        assert_eq!(r2.message, Message::assistant("b"));
    }

    #[tokio::test]
    async fn chat_returns_error_when_script_exhausted() {
        let fake = FakeProvider::new([FakeReply::Text("only".into())]);
        fake.chat(ChatRequest::default()).await.unwrap();

        let err = fake.chat(ChatRequest::default()).await.unwrap_err();
        assert!(matches!(err, ProviderError::Api { message: m, .. } if m.contains("exhausted")));

        // The exhausted call still records its request, so assertions can
        // still see what the Agent last sent.
        assert_eq!(fake.requests().len(), 2);
    }

    #[tokio::test]
    async fn chat_with_text_and_reasoning() {
        let fake = FakeProvider::new([FakeReply::TextWithReasoning {
            content: "answer".into(),
            reasoning: "think".into(),
        }]);

        let r = fake.chat(ChatRequest::default()).await.unwrap();
        assert_eq!(
            r.message,
            Message::assistant_with_reasoning("answer", "think")
        );
    }

    #[tokio::test]
    async fn chat_with_tool_calls() {
        let calls = vec![ToolCall {
            id: "c1".into(),
            name: "add".into(),
            arguments: r#"{"a":1,"b":2}"#.into(),
        }];
        let fake = FakeProvider::new([FakeReply::ToolCalls {
            content: String::new(),
            calls: calls.clone(),
        }]);

        let r = fake.chat(ChatRequest::default()).await.unwrap();
        match r.message {
            Message::Assistant {
                content,
                reasoning,
                tool_calls,
            } => {
                assert_eq!(content, "");
                assert_eq!(reasoning, None);
                assert_eq!(tool_calls, calls);
            }
            other => panic!("expected assistant, got {other:?}"),
        }
    }

    #[tokio::test]
    async fn chat_with_usage_override() {
        let usage = Usage::new(7, 3);
        let fake = FakeProvider::new([FakeReply::text_with_usage("hi", usage)]);

        let r = fake.chat(ChatRequest::default()).await.unwrap();
        assert_eq!(r.message, Message::assistant("hi"));
        assert_eq!(r.usage, usage);
    }

    #[tokio::test]
    async fn stream_with_usage_override() {
        let usage = Usage::new(7, 3);
        let fake = FakeProvider::new([FakeReply::text_with_usage("hi", usage)]);

        let mut stream = fake.stream_chat(ChatRequest::default()).await.unwrap();
        let events: Vec<StreamEvent> = stream.by_ref().map(|e| e.unwrap()).collect().await;
        // The last event is always Done, with the usage per the injected
        // value.
        assert_eq!(
            events.last(),
            Some(&StreamEvent::Done {
                reason: FinishReason::Stop,
                usage: Some(usage),
            })
        );
    }

    #[tokio::test]
    async fn stream_nested_usage_override_no_panic() {
        // Nested WithUsage(WithUsage(Text)): the streaming path unwraps
        // recursively, the outer usage wins, no panic.
        let usage = Usage::new(7, 3);
        let fake = FakeProvider::new([FakeReply::WithUsage {
            reply: Box::new(FakeReply::WithUsage {
                reply: Box::new(FakeReply::Text("hi".into())),
                usage: Usage::new(1, 1),
            }),
            usage,
        }]);

        let mut stream = fake.stream_chat(ChatRequest::default()).await.unwrap();
        let events: Vec<StreamEvent> = stream.by_ref().map(|e| e.unwrap()).collect().await;
        assert_eq!(events[0], StreamEvent::Delta("hi".into()));
        assert_eq!(
            events.last(),
            Some(&StreamEvent::Done {
                reason: FinishReason::Stop,
                usage: Some(usage),
            })
        );
    }

    #[tokio::test]
    async fn error_reply_passthrough_and_script_continues() {
        let fake = FakeProvider::new([
            FakeReply::Error(ProviderError::Api {
                status: 429,
                message: "rate limited".into(),
            }),
            FakeReply::Text("ok".into()),
        ]);

        // This turn fails: the error is returned as-is.
        let err = fake.chat(ChatRequest::default()).await.unwrap_err();
        assert!(
            matches!(err, ProviderError::Api { status: 429, message: m } if m == "rate limited")
        );

        // The failed turn has been consumed; the next turn continues the
        // script.
        let r = fake.chat(ChatRequest::default()).await.unwrap();
        assert_eq!(r.message, Message::assistant("ok"));
    }

    #[tokio::test]
    async fn stream_chat_text_reply() {
        let fake = FakeProvider::new([FakeReply::TextWithReasoning {
            content: "hi".into(),
            reasoning: "think".into(),
        }]);

        let mut stream = fake.stream_chat(ChatRequest::default()).await.unwrap();
        // Scripted order: the content Delta first, then the Reasoning
        // fragment, then Done.
        assert_eq!(
            stream.next().await.unwrap().unwrap(),
            StreamEvent::Delta("hi".into())
        );
        assert_eq!(
            stream.next().await.unwrap().unwrap(),
            StreamEvent::Reasoning("think".into())
        );
        assert_eq!(
            stream.next().await.unwrap().unwrap(),
            StreamEvent::Done {
                reason: FinishReason::Stop,
                usage: Some(Usage::default()),
            }
        );
        assert!(stream.next().await.is_none());
    }

    #[tokio::test]
    async fn stream_chat_tool_call_reply() {
        let fake = FakeProvider::new([FakeReply::ToolCalls {
            content: "thinking aloud".into(),
            calls: vec![ToolCall {
                id: "c1".into(),
                name: "add".into(),
                arguments: r#"{"a":1}"#.into(),
            }],
        }]);

        let mut stream = fake.stream_chat(ChatRequest::default()).await.unwrap();
        // Non-empty text comes first as a Delta, then the tool-call event and
        // the closing Done.
        assert_eq!(
            stream.next().await.unwrap().unwrap(),
            StreamEvent::Delta("thinking aloud".into())
        );
        assert_eq!(
            stream.next().await.unwrap().unwrap(),
            StreamEvent::ToolCall {
                id: "c1".into(),
                name: "add".into(),
                arguments: r#"{"a":1}"#.into(),
            }
        );
        assert_eq!(
            stream.next().await.unwrap().unwrap(),
            StreamEvent::Done {
                reason: FinishReason::Stop,
                usage: Some(Usage::default()),
            }
        );
        assert!(stream.next().await.is_none());
    }

    #[tokio::test]
    async fn stream_chat_error_reply_returns_err() {
        let fake = FakeProvider::new([FakeReply::Error(ProviderError::Api {
            status: 400,
            message: "boom".into(),
        })]);
        // Boundary behavior consistent with chat: this turn's failure makes
        // the method return Err directly.
        match fake.stream_chat(ChatRequest::default()).await {
            Err(ProviderError::Api {
                status: 400,
                message: m,
            }) => assert_eq!(m, "boom"),
            Ok(_) => panic!("expected error"),
            Err(other) => panic!("expected Api error, got {other:?}"),
        }
    }

    #[tokio::test]
    async fn stream_chat_exhausted_returns_err() {
        let fake = FakeProvider::new([FakeReply::Text("only".into())]);
        // Consume the only script turn first; a stream that is never polled
        // would be pointless, so drop it explicitly here.
        drop(fake.stream_chat(ChatRequest::default()).await.unwrap());

        match fake.stream_chat(ChatRequest::default()).await {
            Err(ProviderError::Api { message: m, .. }) => assert!(m.contains("exhausted")),
            Ok(_) => panic!("expected error"),
            Err(other) => panic!("expected Api error, got {other:?}"),
        }
    }

    #[tokio::test]
    async fn requests_records_messages_passed() {
        let fake = FakeProvider::new([FakeReply::Text("hi".into())]);
        let messages = vec![Message::system("sys"), Message::user("hello")];

        fake.chat(ChatRequest {
            messages: messages.clone(),
            ..Default::default()
        })
        .await
        .unwrap();

        let requests = fake.requests();
        assert_eq!(requests.len(), 1);
        assert_eq!(requests[0].messages, messages);
    }

    #[tokio::test]
    async fn push_appends_to_script() {
        let fake = FakeProvider::new([FakeReply::Text("first".into())]);
        fake.push(FakeReply::Text("second".into()));

        let r1 = fake.chat(ChatRequest::default()).await.unwrap();
        assert_eq!(r1.message, Message::assistant("first"));
        let r2 = fake.chat(ChatRequest::default()).await.unwrap();
        assert_eq!(r2.message, Message::assistant("second"));
    }

    #[tokio::test]
    async fn works_as_boxed_dyn_provider() {
        // The Agent holds providers as Box<dyn Provider>; the fake must
        // satisfy that shape.
        let fake: Box<dyn Provider> = Box::new(FakeProvider::new([FakeReply::Text("hi".into())]));
        let r = fake.chat(ChatRequest::default()).await.unwrap();
        assert_eq!(r.message, Message::assistant("hi"));
    }
}