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;
25
26#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
28pub struct XiaomiMimoExt;
29
30impl ProviderExtension for XiaomiMimoExt {
31 const PROVIDER: &'static str = super::PROVIDER_NAME;
32 type Options = XiaomiMimoOptions;
33 type Extras = XiaomiMimoExtras;
34}
35
36#[non_exhaustive]
38#[derive(Clone, Debug, Default, PartialEq, Serialize)]
39pub struct XiaomiMimoOptions {}
40
41impl XiaomiMimoOptions {
42 pub fn new() -> Self {
44 Self::default()
45 }
46}
47
48impl ExtensionOptions for XiaomiMimoOptions {
49 type Ext = XiaomiMimoExt;
50}
51
52#[non_exhaustive]
54#[derive(Clone, Debug, Default, PartialEq)]
55pub struct XiaomiMimoExtras {
56 pub annotations: Option<Vec<Value>>,
59 pub stop_reason: Option<String>,
61 pub stop_sequence: Option<String>,
63}
64
65impl ReplyExtras for XiaomiMimoExtras {
66 fn from_reply(api: &Api, raw: &Value) -> Result<Self, serde_json::Error> {
67 if let Some(stop) = MessagesStop::of(api, raw)? {
68 return Ok(Self {
69 stop_reason: stop.stop_reason,
70 stop_sequence: stop.stop_sequence,
71 ..Self::default()
72 });
73 }
74 if api.as_str() != "openai.chat" {
75 return Ok(Self::default());
76 }
77 Ok(Self {
78 annotations: reply_field(raw, "/choices/0/message/annotations")?,
79 ..Self::default()
80 })
81 }
82}
83
84#[cfg(test)]
85mod tests;