-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pepperoni21
committed
Feb 7, 2024
1 parent
bda42c9
commit 715b2c2
Showing
5 changed files
with
66 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
pub mod chat; | ||
pub mod completion; | ||
pub mod embeddings; | ||
pub mod format; | ||
pub mod images; | ||
pub mod options; | ||
pub mod parameters; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// The format to return a response in. Currently the only accepted value is `json` | ||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
#[serde(rename_all = "lowercase")] | ||
pub enum FormatType { | ||
Json, | ||
} | ||
|
||
/// Used to control how long a model stays loaded in memory, by default models are unloaded after 5 minutes of inactivity | ||
#[derive(Debug, Clone)] | ||
pub enum KeepAlive { | ||
Indefinitely, | ||
UnloadOnCompletion, | ||
Until { time: u64, unit: TimeUnit }, | ||
} | ||
|
||
impl Serialize for KeepAlive { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
match self { | ||
KeepAlive::Indefinitely => serializer.serialize_i8(-1), | ||
KeepAlive::UnloadOnCompletion => serializer.serialize_i8(0), | ||
KeepAlive::Until { time, unit } => { | ||
let mut s = String::new(); | ||
s.push_str(&time.to_string()); | ||
s.push_str(unit.to_symbol()); | ||
serializer.serialize_str(&s) | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum TimeUnit { | ||
Seconds, | ||
Minutes, | ||
Hours, | ||
} | ||
|
||
impl TimeUnit { | ||
pub fn to_symbol(&self) -> &'static str { | ||
match self { | ||
TimeUnit::Seconds => "s", | ||
TimeUnit::Minutes => "m", | ||
TimeUnit::Hours => "hr", | ||
} | ||
} | ||
} |