rig_core/providers/xiaomimimo/
extension.rs1use serde::Serialize;
19use serde_json::Value;
20
21use crate::completion::provider_options::reply_field;
22use crate::completion::{ExtensionOptions, ProviderExtension, ReplyExtras};
23use crate::message::Api;
24use crate::providers::anthropic::extension::MessagesStop;
25use crate::providers::anthropic::wire::MESSAGES_API;
26
27#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
29pub struct XiaomiMimoExt;
30
31impl ProviderExtension for XiaomiMimoExt {
32 const PROVIDER: &'static str = super::PROVIDER_NAME;
33 type Options = XiaomiMimoOptions;
34 type Extras = XiaomiMimoExtras;
35}
36
37#[non_exhaustive]
39#[derive(Clone, Debug, Default, PartialEq, Serialize)]
40pub struct XiaomiMimoOptions {}
41
42impl XiaomiMimoOptions {
43 pub fn new() -> Self {
45 Self::default()
46 }
47}
48
49impl ExtensionOptions for XiaomiMimoOptions {
50 type Ext = XiaomiMimoExt;
51}
52
53#[non_exhaustive]
55#[derive(Clone, Debug, Default, PartialEq)]
56pub struct XiaomiMimoExtras {
57 pub annotations: Option<Vec<Value>>,
60 pub stop_reason: Option<String>,
62 pub stop_sequence: Option<String>,
64}
65
66impl ReplyExtras for XiaomiMimoExtras {
67 fn from_reply(api: &Api, raw: &Value) -> Result<Self, serde_json::Error> {
68 if api.as_str() == MESSAGES_API {
69 let MessagesStop {
70 stop_reason,
71 stop_sequence,
72 } = MessagesStop::read("Xiaomi MiMo", api, raw)?;
73 return Ok(Self {
74 stop_reason,
75 stop_sequence,
76 ..Self::default()
77 });
78 }
79 if api.as_str() != "openai.chat" {
80 return Ok(Self::default());
81 }
82 Ok(Self {
83 annotations: reply_field(raw, "/choices/0/message/annotations")?,
84 ..Self::default()
85 })
86 }
87}
88
89#[cfg(test)]
90mod tests;