gemini_ai/content_gen/
forgetful.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use std::fs;

use base64::encode;
use rusty_scrap::Scrap;

use crate::{
    format::{json, schema, text},
    GeminiContentGen, Kind,
};

use super::content::gemini;

pub fn forgetFul(forgetful: &GeminiContentGen) -> String {
    let instruction = forgetful.instruction;
    let t = forgetful.text;
    let model = forgetful.model;
    let max_len = forgetful.max_len;
    match forgetful.config.response {
        Kind::Text => {
            let response = text(&forgetful.instruction, &forgetful.text, forgetful.max_len);
            // println!("{:?}", response);
            let response = gemini(
                response,
                &forgetful.env_variable,
                forgetful.model,
                "application/json",
            );
            response
            // String::new()
        }
        Kind::Json(jsons) => {
            let response = json(
                forgetful.instruction,
                forgetful.text,
                &jsons,
                forgetful.max_len,
            );
            // println!("{}", response);
            let json = gemini(
                response,
                &forgetful.env_variable,
                forgetful.model,
                "application/json",
            );

            // let response = serde_json::from_str::<JsonResponse>(&json).unwrap();
            // println!("{}", json);
            // String::new()
            json
        }
        Kind::Image(path) => {
            let images = fs::read(path).unwrap();
            // let mut image = Vec::new();
            // images.read_to_end(&mut image);
            let encode = encode(images);
            let response = schema(instruction, t, "image/jpeg", &encode, max_len);
            gemini(
                response,
                &forgetful.env_variable,
                forgetful.model,
                "image/jpeg",
            )
            // String::new()
        }
        Kind::Audio(path) => {
            let audioo = fs::read(path).unwrap();
            let audioo = encode(audioo);
            // let c = encode(path);
            let auth = schema(instruction, t, "audio/mpeg", &audioo, max_len);
            // println!("{}", auth);
            // let response = upload_uri(path.len(), path, 0, "audio/mpeg");
            gemini(auth, forgetful.env_variable, forgetful.model, "audio/mpeg");

            String::new()
        }
        Kind::Pdf(path) => {
            let path = fs::read(path).unwrap();

            let encode = encode(path);
            let pdf = schema(instruction, t, "application/pdf", &encode, max_len);
            gemini(
                pdf,
                forgetful.env_variable,
                forgetful.model,
                "application/pdf",
            )
            // println!("{}", pdf);

            // String::new()
        }
        Kind::Video(path) => {
            let videoo = fs::read(path).unwrap();
            let videoo = encode(videoo);

            let video = schema(instruction, t, "video/mp4", &videoo, max_len);
            gemini(video, &forgetful.env_variable, forgetful.model, "video/mp4")
        }
        Kind::Transcribe(path) => {
            let videoo = fs::read(path).unwrap();
            let videoo = encode(videoo);

            let video = schema(instruction, t, "video/mp4", &videoo, max_len);
            gemini(video, &forgetful.env_variable, forgetful.model, "video/mp4")
        }
        Kind::Csv(path) => {
            let path = fs::read(path).unwrap();
            let csv_file = encode(path);

            let send = schema(instruction, t, "text/plain", &csv_file, max_len);
            gemini(
                send,
                forgetful.env_variable,
                forgetful.model,
                "application/json",
            )
        }
        Kind::Rag(data) => {
            let ask = Scrap::new()
                .urls(data)
                .build()
                .element_values()
                .replace("\"", "");
            // println!("{}", ask);
            let encode = encode(ask);
            let response = schema(instruction, t, "text/plain", &encode, max_len);
            gemini(
                response,
                forgetful.env_variable,
                forgetful.model,
                "application/json",
            )
        }
    }
}