Skip to content

Commit

Permalink
added maxtokenlimit
Browse files Browse the repository at this point in the history
  • Loading branch information
HashiramaSenjuhari committed Nov 21, 2024
1 parent 8af5f1c commit 76ad5cd
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gemini-ai"
version = "0.1.13"
version = "0.1.14"
edition = "2021"
authors = ["hariprasath"]
license = "MIT"
Expand Down
12 changes: 8 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Welcome to the **Rust Gemini AI**! This crate provides a Rust interface to inter

## New Feature Added

- **MaxTokenLimit Based Response**

## Previous New Feature Added

- **Instruction Based Response**

## Features
Expand All @@ -22,7 +26,7 @@ To add this crate to your project, include it in your `Cargo.toml`:
```toml

[dependencies]
gemini-ai = "0.1"
gemini-ai = "0.1.14"

```

Expand All @@ -31,14 +35,14 @@ To add this crate to your project, include it in your `Cargo.toml`:
let builder = GeminiContentGenBuilder::new()
.env("GEMINI_API_KEY")
.model(gemini_ai::Models::GEMINI_1_5_PRO_002)
.kind(gemini_ai::Kind::Image("OIP.jpeg"))
.kind(gemini_ai::Kind::Image("statics/OIP.jpeg"))
.instruction(
"you are great image analyzer and tell the image design accuratly and how it can be made great",
"you are great image analyzer and tell the image design accuratly and how it can be made great",
)
.text("image")
.max_token(gemini_ai::TokenLen::Default)
.build()
.output();
println!("{}", builder);

let string = decode_gemini(&builder); // optional to decode the output if it sends the reponse else error

Expand Down
88 changes: 82 additions & 6 deletions src/content_gen/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::{
format::{image, json, pdf, text, transcribe},
Config, ConfigBuilder, ConfigNotPresent, ConfigPresent, EnvVariableNotPresent,
EnvVariablePresent, GeminiContentGen, GeminiContentGenBuilder, InstructionNotPresent,
InstructionPresent, Kind, ModelNotPresent, ModelPresent, Models, PropertiesNotPresent,
PropertiesPresent, TextNotPresent, TextPresent,
InstructionPresent, Kind, MaxLenNotPresent, MaxLenPresent, ModelNotPresent, ModelPresent,
Models, PropertiesNotPresent, PropertiesPresent, TextNotPresent, TextPresent, TokenLen,
};

impl<'gemini>
Expand All @@ -28,6 +28,7 @@ impl<'gemini>
ModelNotPresent,
ConfigNotPresent,
TextNotPresent,
MaxLenNotPresent,
InstructionNotPresent,
PropertiesNotPresent,
>
Expand All @@ -38,12 +39,14 @@ impl<'gemini>
env_variable: "",
text: "",
instruction: "",
max_len: 8192,
config: ConfigBuilder {
// schema_type: String::new(),
r#type: Kind::Text,
propertiesstate: std::marker::PhantomData,
},
envstate: std::marker::PhantomData,
maxstate: std::marker::PhantomData,
instructionstate: std::marker::PhantomData,
modelstate: std::marker::PhantomData,
configstate: std::marker::PhantomData,
Expand All @@ -59,6 +62,7 @@ impl<'gemini>
ModelNotPresent,
ConfigNotPresent,
TextNotPresent,
MaxLenNotPresent,
InstructionNotPresent,
PropertiesNotPresent,
>
Expand All @@ -72,6 +76,7 @@ impl<'gemini>
ModelNotPresent,
ConfigNotPresent,
TextNotPresent,
MaxLenNotPresent,
InstructionNotPresent,
PropertiesNotPresent,
> {
Expand All @@ -81,13 +86,15 @@ impl<'gemini>
model: &self.model,
text: self.text,
instruction: &self.instruction,
max_len: self.max_len,
config: ConfigBuilder {
// schema_type: String::new(),
r#type: self.config.r#type,
propertiesstate: std::marker::PhantomData,
},
envstate: std::marker::PhantomData,
instructionstate: std::marker::PhantomData,
maxstate: std::marker::PhantomData,
modelstate: std::marker::PhantomData,
configstate: std::marker::PhantomData,
textstate: std::marker::PhantomData,
Expand All @@ -102,6 +109,7 @@ impl<'gemini>
ModelNotPresent,
ConfigNotPresent,
TextNotPresent,
MaxLenNotPresent,
InstructionNotPresent,
PropertiesNotPresent,
>
Expand All @@ -115,6 +123,7 @@ impl<'gemini>
ModelPresent,
ConfigNotPresent,
TextNotPresent,
MaxLenNotPresent,
InstructionNotPresent,
PropertiesNotPresent,
> {
Expand All @@ -131,6 +140,7 @@ impl<'gemini>
model: &self.model,
text: self.text,
instruction: self.instruction,
max_len: self.max_len,
config: ConfigBuilder {
// schema_type: String::new(),
r#type: self.config.r#type,
Expand All @@ -141,6 +151,7 @@ impl<'gemini>
modelstate: std::marker::PhantomData,
configstate: std::marker::PhantomData,
textstate: std::marker::PhantomData,
maxstate: std::marker::PhantomData,
}
}
}
Expand All @@ -152,6 +163,7 @@ impl<'properties>
ModelPresent,
ConfigNotPresent,
TextNotPresent,
MaxLenNotPresent,
InstructionNotPresent,
PropertiesNotPresent,
>
Expand All @@ -164,6 +176,7 @@ impl<'properties>
EnvVariablePresent,
ModelPresent,
ConfigPresent,
MaxLenNotPresent,
TextNotPresent,
InstructionNotPresent,
PropertiesPresent,
Expand All @@ -174,6 +187,7 @@ impl<'properties>
model: &self.model,
text: self.text,
instruction: self.instruction,
max_len: self.max_len,
config: ConfigBuilder {
// schema_type: String::new(),
r#type: self.config.r#type,
Expand All @@ -184,6 +198,7 @@ impl<'properties>
modelstate: std::marker::PhantomData,
configstate: std::marker::PhantomData,
textstate: std::marker::PhantomData,
maxstate: std::marker::PhantomData,
}
}
}
Expand All @@ -194,6 +209,7 @@ impl<'instruction>
EnvVariablePresent,
ModelPresent,
ConfigPresent,
MaxLenNotPresent,
TextNotPresent,
InstructionNotPresent,
PropertiesPresent,
Expand All @@ -208,6 +224,7 @@ impl<'instruction>
ModelPresent,
ConfigPresent,
TextNotPresent,
MaxLenNotPresent,
InstructionPresent,
PropertiesPresent,
> {
Expand All @@ -217,16 +234,18 @@ impl<'instruction>
model: &self.model,
text: self.text,
instruction: self.instruction,
max_len: self.max_len,
config: ConfigBuilder {
// schema_type: String::new(),
r#type: self.config.r#type,
propertiesstate: std::marker::PhantomData,
},
envstate: std::marker::PhantomData,
instructionstate: std::marker::PhantomData,
modelstate: std::marker::PhantomData,
configstate: std::marker::PhantomData,
instructionstate: std::marker::PhantomData,
textstate: std::marker::PhantomData,
maxstate: std::marker::PhantomData,
}
}
}
Expand All @@ -238,6 +257,7 @@ impl<'text>
ModelPresent,
ConfigPresent,
TextNotPresent,
MaxLenNotPresent,
InstructionPresent,
PropertiesPresent,
>
Expand All @@ -251,6 +271,7 @@ impl<'text>
ModelPresent,
ConfigPresent,
TextPresent,
MaxLenNotPresent,
InstructionPresent,
PropertiesPresent,
> {
Expand All @@ -260,6 +281,7 @@ impl<'text>
model: &self.model,
text: self.text,
instruction: self.instruction,
max_len: self.max_len,
config: ConfigBuilder {
// schema_type: String::new(),
r#type: self.config.r#type,
Expand All @@ -270,17 +292,70 @@ impl<'text>
modelstate: std::marker::PhantomData,
configstate: std::marker::PhantomData,
textstate: std::marker::PhantomData,
maxstate: std::marker::PhantomData,
}
}
}

impl<'max_len>
GeminiContentGenBuilder<
'max_len,
EnvVariablePresent,
ModelPresent,
ConfigPresent,
TextPresent,
MaxLenNotPresent,
InstructionPresent,
PropertiesPresent,
>
{
pub fn max_token(
mut self,
max: TokenLen,
) -> GeminiContentGenBuilder<
'max_len,
EnvVariablePresent,
ModelPresent,
ConfigPresent,
TextPresent,
MaxLenPresent,
InstructionPresent,
PropertiesPresent,
> {
match max {
TokenLen::Custome(values) => {
self.max_len = values;
}
TokenLen::Default => self.max_len = 8192,
}
GeminiContentGenBuilder {
env_variable: self.env_variable,
model: &self.model,
text: self.text,
instruction: self.instruction,
max_len: self.max_len,
config: ConfigBuilder {
// schema_type: String::new(),
r#type: self.config.r#type,
propertiesstate: std::marker::PhantomData,
},
envstate: std::marker::PhantomData,
instructionstate: std::marker::PhantomData,
modelstate: std::marker::PhantomData,
configstate: std::marker::PhantomData,
textstate: std::marker::PhantomData,
maxstate: std::marker::PhantomData,
}
}
}
impl<'build>
GeminiContentGenBuilder<
'build,
EnvVariablePresent,
ModelPresent,
ConfigPresent,
TextPresent,
MaxLenPresent,
InstructionPresent,
PropertiesPresent,
>
Expand All @@ -289,6 +364,7 @@ impl<'build>
GeminiContentGen {
model: &self.model,
env_variable: &self.env_variable,
max_len: self.max_len,
text: self.text,
instruction: &self.instruction,
config: Config {
Expand All @@ -305,14 +381,14 @@ impl<'output> GeminiContentGen<'output> {

match self.config.response {
Kind::Text => {
let response = text(&self.instruction, &self.text);
let response = text(&self.instruction, &self.text, self.max_len);
// println!("{:?}", response);
let response = Self::gemini(response, &self.env_variable, self.model);
response
// String::new()
}
Kind::Json(jsons) => {
let response = json(self.instruction, self.text, &jsons);
let response = json(self.instruction, self.text, &jsons, self.max_len);
// println!("{}", response);
let json = Self::gemini(response, &self.env_variable, self.model);

Expand All @@ -326,7 +402,7 @@ impl<'output> GeminiContentGen<'output> {
// let mut image = Vec::new();
// images.read_to_end(&mut image);
let encode = encode(images);
let response = image(self.instruction, self.text, &encode);
let response = image(self.instruction, self.text, &encode, self.max_len);
Self::gemini(response, &self.env_variable, self.model)
// String::new()
} // Kind::Video(video_path) => {
Expand Down
Loading

0 comments on commit 76ad5cd

Please sign in to comment.