firebase_rs_sdk/ai/
backend.rs1use std::fmt;
2
3use crate::ai::constants::DEFAULT_LOCATION;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
9pub enum BackendType {
10 VertexAi,
11 GoogleAi,
12}
13
14impl fmt::Display for BackendType {
15 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16 match self {
17 BackendType::VertexAi => write!(f, "VERTEX_AI"),
18 BackendType::GoogleAi => write!(f, "GOOGLE_AI"),
19 }
20 }
21}
22
23#[derive(Clone, Debug, PartialEq, Eq, Default)]
27pub struct GoogleAiBackend;
28
29impl GoogleAiBackend {
30 pub fn new() -> Self {
32 Self
33 }
34
35 pub fn backend_type(&self) -> BackendType {
37 BackendType::GoogleAi
38 }
39}
40
41#[derive(Clone, Debug, PartialEq, Eq)]
45pub struct VertexAiBackend {
46 location: String,
47}
48
49impl VertexAiBackend {
50 pub fn new<S: Into<String>>(location: S) -> Self {
55 let location = location.into();
56 let location = if location.trim().is_empty() {
57 DEFAULT_LOCATION.to_string()
58 } else {
59 location
60 };
61 Self { location }
62 }
63
64 pub fn location(&self) -> &str {
66 &self.location
67 }
68
69 pub fn backend_type(&self) -> BackendType {
71 BackendType::VertexAi
72 }
73}
74
75impl Default for VertexAiBackend {
76 fn default() -> Self {
77 Self::new(DEFAULT_LOCATION)
78 }
79}
80
81#[derive(Clone, Debug, PartialEq, Eq)]
86pub enum Backend {
87 GoogleAi(GoogleAiBackend),
88 VertexAi(VertexAiBackend),
89}
90
91impl Backend {
92 pub fn google_ai() -> Self {
94 Self::GoogleAi(GoogleAiBackend::new())
95 }
96
97 pub fn vertex_ai<S: Into<String>>(location: S) -> Self {
99 Self::VertexAi(VertexAiBackend::new(location))
100 }
101
102 pub fn backend_type(&self) -> BackendType {
104 match self {
105 Backend::GoogleAi(inner) => inner.backend_type(),
106 Backend::VertexAi(inner) => inner.backend_type(),
107 }
108 }
109
110 pub fn as_vertex_ai(&self) -> Option<&VertexAiBackend> {
112 match self {
113 Backend::VertexAi(inner) => Some(inner),
114 _ => None,
115 }
116 }
117}
118
119impl Default for Backend {
120 fn default() -> Self {
121 Backend::google_ai()
122 }
123}