gemini_ai/
lib.rs

1use serde::{Deserialize, Serialize};
2
3// pub mod cloud;
4pub mod content_gen;
5// pub mod file;
6// pub mod error;
7pub mod format;
8// pub mod pulse;
9pub mod schema;
10// pub mod tunemodel;
11
12#[derive(Debug, Clone)]
13pub struct GeminiContentGen<'gemini> {
14    env_variable: &'gemini str,
15    model: &'gemini str,
16    max_len: u64,
17    instruction: &'gemini str,
18    text: &'gemini str,
19    config: Config<'gemini>,
20    memory: MemoryType,
21}
22
23#[derive(Debug)]
24pub enum TokenLen {
25    Default,
26    Custome(u64),
27}
28#[derive(Debug, Clone)]
29pub struct Config<'config> {
30    pub response: Kind<'config>,
31}
32
33#[derive(Debug, Clone)]
34pub enum Kind<'response> {
35    Json(&'response str),
36    Text,
37    Audio(&'response Vec<u8>),
38    Transcribe(&'response Vec<u8>),
39    Image(&'response Vec<u8>),
40    Video(&'response Vec<u8>),
41    Pdf(&'response Vec<u8>),
42    Csv(&'response Vec<u8>),
43    Rag(&'response [&'response str]),
44}
45
46#[derive(Debug)]
47pub struct Gemini<
48    'gemini,
49    EnvState,
50    ModelState,
51    ConfigState,
52    InstructionState,
53    TextState,
54    MaxState,
55    PropertiesState,
56    MemoryState,
57> {
58    env_variable: &'gemini str,
59    model: &'gemini str,
60    instruction: &'gemini str,
61    max_len: u64,
62    text: &'gemini str,
63    memory: MemoryType,
64    config: ConfigBuilder<'gemini, PropertiesState>,
65    envstate: std::marker::PhantomData<EnvState>,
66    modelstate: std::marker::PhantomData<ModelState>,
67    configstate: std::marker::PhantomData<ConfigState>,
68    maxstate: std::marker::PhantomData<MaxState>,
69    instructionstate: std::marker::PhantomData<InstructionState>,
70    textstate: std::marker::PhantomData<TextState>,
71    memorystate: std::marker::PhantomData<MemoryState>,
72}
73
74#[derive(Debug)]
75pub struct ConfigBuilder<'config, PropertiesState> {
76    r#type: Kind<'config>,
77    propertiesstate: std::marker::PhantomData<PropertiesState>,
78}
79
80#[derive(Debug)]
81pub struct Properties {
82    pub key: String,
83    pub r#type: String,
84    pub nested: Option<Vec<Properties>>,
85}
86
87#[derive(Debug)]
88pub enum Models<'model> {
89    GEMINI_1_5_FLASH,
90    GEMINI_1_5_PRO_002,
91    GEMINI_1_5_PRO,
92    GEMINI_1_5_FLASH_002,
93    GEMINI_1_5_FLASH_8B,
94    GEMINI_1_0_PRO,
95    Custom(&'model str),
96}
97
98#[derive(Debug)]
99pub struct ModelPresent;
100pub struct ModelNotPresent;
101
102#[derive(Debug)]
103pub struct EnvVariablePresent;
104pub struct EnvVariableNotPresent;
105
106#[derive(Debug)]
107
108pub struct TextPresent;
109pub struct TextNotPresent;
110
111#[derive(Debug)]
112pub struct ConfigPresent;
113pub struct ConfigNotPresent;
114
115#[derive(Debug)]
116pub struct PropertiesPresent;
117pub struct PropertiesNotPresent;
118
119pub struct Memory;
120
121pub struct Default;
122
123#[derive(Debug, Clone)]
124pub enum MemoryType {
125    Memory(Memorys),
126    NoMemory,
127}
128
129#[derive(Debug, Clone, Copy)]
130pub enum Memorys {
131    File,
132    Json,
133    // Database,
134}
135
136#[derive(Serialize, Deserialize, Debug)]
137pub struct Candidate {
138    pub content: Content,
139    finishReason: String,
140    avgLogprobs: f64,
141}
142
143#[derive(Serialize, Deserialize, Debug)]
144pub struct Content {
145    pub parts: Vec<Part>,
146}
147
148#[derive(Serialize, Deserialize, Debug)]
149pub struct Part {
150    pub text: String,
151}
152
153#[derive(Serialize, Deserialize, Debug)]
154pub struct UsageMetadata {
155    promptTokenCount: u32,
156    candidatesTokenCount: u32,
157    totalTokenCount: u32,
158}
159
160#[derive(Serialize, Deserialize, Debug)]
161pub struct Responses {
162    pub candidates: Vec<Candidate>,
163    usageMetadata: UsageMetadata,
164    modelVersion: String,
165}
166
167pub fn decode_gemini(response: &str) -> Result<Responses, serde_json::Error> {
168    let response = serde_json::from_str::<Responses>(response);
169    response
170}
171
172pub struct Pair<'key> {
173    pub key: &'key str,
174    pub r#type: &'key str,
175}
176
177pub struct TrainPresent;
178pub struct TrainNotPresent;
179
180pub struct InstructionPresent;
181pub struct InstructionNotPresent;
182
183pub struct TellPresent;
184pub struct TellNotPresent;
185
186pub struct MaxLenPresent;
187pub struct MaxLenNotPresent;
188
189pub struct MemoryOK;
190pub struct MemoryNot;