gemini_ai/content_gen/
memory_ok.rs

1use crate::{
2    Config, ConfigBuilder, ConfigNotPresent, EnvVariablePresent, Gemini, GeminiContentGen,
3    InstructionNotPresent, InstructionPresent, Kind, MaxLenNotPresent, MaxLenPresent, Memory,
4    MemoryOK, ModelPresent, PropertiesNotPresent, PropertiesPresent, TextNotPresent, TextPresent,
5    TokenLen,
6};
7
8impl<'instruction>
9    Gemini<
10        'instruction,
11        EnvVariablePresent,
12        ModelPresent,
13        ConfigNotPresent,
14        TextNotPresent,
15        MaxLenNotPresent,
16        InstructionNotPresent,
17        PropertiesNotPresent,
18        MemoryOK,
19    >
20{
21    pub fn instruction(
22        mut self,
23        instruction: &'instruction str,
24    ) -> Gemini<
25        'instruction,
26        EnvVariablePresent,
27        ModelPresent,
28        ConfigNotPresent,
29        TextNotPresent,
30        MaxLenNotPresent,
31        InstructionPresent,
32        PropertiesNotPresent,
33        MemoryOK,
34    > {
35        self.instruction = instruction;
36        Gemini {
37            env_variable: self.env_variable,
38            model: &self.model,
39            text: self.text,
40            instruction: &self.instruction,
41            max_len: self.max_len,
42            memory: self.memory,
43            config: ConfigBuilder {
44                // schema_type: String::new(),
45                r#type: self.config.r#type,
46                propertiesstate: std::marker::PhantomData,
47            },
48            envstate: std::marker::PhantomData,
49            instructionstate: std::marker::PhantomData,
50            maxstate: std::marker::PhantomData,
51            modelstate: std::marker::PhantomData,
52            configstate: std::marker::PhantomData,
53            textstate: std::marker::PhantomData,
54            memorystate: std::marker::PhantomData,
55        }
56    }
57}
58
59impl<'text>
60    Gemini<
61        'text,
62        EnvVariablePresent,
63        ModelPresent,
64        ConfigNotPresent,
65        TextNotPresent,
66        MaxLenNotPresent,
67        InstructionPresent,
68        PropertiesNotPresent,
69        MemoryOK,
70    >
71{
72    pub fn text(
73        mut self,
74        text: &'text str,
75    ) -> Gemini<
76        'text,
77        EnvVariablePresent,
78        ModelPresent,
79        ConfigNotPresent,
80        TextPresent,
81        MaxLenNotPresent,
82        InstructionPresent,
83        PropertiesPresent,
84        MemoryOK,
85    > {
86        self.text = text;
87        Gemini {
88            env_variable: self.env_variable,
89            model: &self.model,
90            text: self.text,
91            instruction: &self.instruction,
92            max_len: self.max_len,
93            memory: self.memory,
94            config: ConfigBuilder {
95                // schema_type: String::new(),
96                r#type: self.config.r#type,
97                propertiesstate: std::marker::PhantomData,
98            },
99            envstate: std::marker::PhantomData,
100            instructionstate: std::marker::PhantomData,
101            maxstate: std::marker::PhantomData,
102            modelstate: std::marker::PhantomData,
103            configstate: std::marker::PhantomData,
104            textstate: std::marker::PhantomData,
105            memorystate: std::marker::PhantomData,
106        }
107    }
108}
109
110impl<'max_len>
111    Gemini<
112        'max_len,
113        EnvVariablePresent,
114        ModelPresent,
115        ConfigNotPresent,
116        TextPresent,
117        MaxLenNotPresent,
118        InstructionPresent,
119        PropertiesPresent,
120        MemoryOK,
121    >
122{
123    pub fn max_token(
124        mut self,
125        max: TokenLen,
126    ) -> Gemini<
127        'max_len,
128        EnvVariablePresent,
129        ModelPresent,
130        ConfigNotPresent,
131        TextPresent,
132        MaxLenPresent,
133        InstructionPresent,
134        PropertiesPresent,
135        MemoryOK,
136    > {
137        match max {
138            TokenLen::Custome(values) => {
139                self.max_len = values;
140            }
141            TokenLen::Default => self.max_len = 8192,
142        }
143        Gemini {
144            env_variable: self.env_variable,
145            model: &self.model,
146            text: self.text,
147            instruction: &self.instruction,
148            max_len: self.max_len,
149            memory: self.memory,
150            config: ConfigBuilder {
151                // schema_type: String::new(),
152                r#type: self.config.r#type,
153                propertiesstate: std::marker::PhantomData,
154            },
155            envstate: std::marker::PhantomData,
156            instructionstate: std::marker::PhantomData,
157            maxstate: std::marker::PhantomData,
158            modelstate: std::marker::PhantomData,
159            configstate: std::marker::PhantomData,
160            textstate: std::marker::PhantomData,
161            memorystate: std::marker::PhantomData,
162        }
163    }
164}
165
166impl<'build>
167    Gemini<
168        'build,
169        EnvVariablePresent,
170        ModelPresent,
171        ConfigNotPresent,
172        TextPresent,
173        MaxLenPresent,
174        InstructionPresent,
175        PropertiesPresent,
176        MemoryOK,
177    >
178{
179    pub fn build(self) -> GeminiContentGen<'build> {
180        GeminiContentGen {
181            model: &self.model,
182            env_variable: &self.env_variable,
183            max_len: self.max_len,
184            text: self.text,
185            instruction: &self.instruction,
186            config: Config {
187                response: self.config.r#type,
188            },
189            memory: self.memory,
190        }
191    }
192}