-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new module, utils, to openai crate; add chat session name comment and session argument to function in b crate; reorganize message creation, update model and logic for setting stop words, and remove HashMap creation in chats file of b crate; remove two error types and add five new ones, and add file and directory existence checking and HOME directory retrieval functions to error and utils modules in openai crate respectively; add cloning and optional session attributes, new_with_session and store_session methods, get_sessions_file, deserialize_sessions_file, and serialize_sessions_file methods, and imports to chats file in openai crate. --- Changes to file crates/openai/src/lib.rs: - Added a new module called "utils". Changes to file crates/b/src/lib.rs: - Added a comment about chat session name and its use - Added an argument 'session' with Option<String> type to the function definition using the #[arg(long)] attribute. Changes to file crates/b/src/chats.rs: - Updated ChatsApi initialization - Reorganized message creation - Updated ChatsApi model, max_tokens, n, user, and stream - Added check for system message - Added logic for setting stop words - Removed HashMap creation and used logit_bias attribute Changes to file crates/openai/src/error.rs: - Removed two error types: NoChoices and InvalidBestOf - Added five new error types: DeserializationError, FileError, InvalidFrequencyPenalty, InvalidPresencePenalty, and NoSession - Changed the error message of InvalidStop and InvalidLogProbs Changes to file crates/openai/src/utils.rs: - Added imports for std::env, std::fs, and std::path::Path - Added three new functions for checking if a file or directory exists and getting the HOME directory - The `file_exists` function checks if a file exists and returns a boolean - The `directory_exists` function checks if a directory exists and returns a boolean - The `get_home_directory` function returns the HOME directory as a string, appending "/.b/sessions" if available or returning "/tmp/.b/sessions" if not Changes to file crates/openai/src/chats.rs: - Added imports for std::fs, std::io, crate::utils - Added 'Clone' and 'Option' attributes to the session field of ChatsApi struct - Added new_with_session method to ChatsApi struct for creating new instances of the struct with a given session key - Added store_session method to ChatsApi struct for storing the current session to a file - Modified create_message method of ChatsApi struct to update session info in file - Added get_sessions_file method for obtaining the path to the sessions file - Added deserialize_sessions_file method for deserializing the sessions file - Added serialize_sessions_file method for serializing the sessions file
- Loading branch information
1 parent
444dd40
commit af65fca
Showing
6 changed files
with
213 additions
and
42 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
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 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,19 +1,22 @@ | ||
use custom_error::custom_error; | ||
|
||
custom_error! {pub OpenAi | ||
NoChoices = "no chat choices", | ||
InvalidStop{stop: String} = "stop value ({stop}) must be either 'left' or 'right'", | ||
RequestError{body: String} = "request error: {body}", | ||
ModelNotFound{model_name: String} = "model not found: {model_name}", | ||
SerializationError{body: String} = "serialization error: {body}", | ||
ClientError{body: String} = "client error:\n{body}", | ||
InvalidLogProbs{logprobs: f32} = "logprob value ({logprobs}) must be between 0 and 5", | ||
DeserializationError{body: String} = "deserialization error: {body}", | ||
FileError{body: String} = "file error: {body}", | ||
InvalidBestOf = "'best_of' cannot be used with 'stream'", | ||
InvalidEcho = "'echo' cannot be used with 'suffix'", | ||
InvalidFrequencyPenalty{frequency_penalty: f32} = "frequency_penalty ({frequency_penalty}) must be between -2.0 and 2.0", | ||
InvalidLogProbs{logprobs: f32} = "logprob value ({logprobs}) must be between 0 and 5", | ||
InvalidPresencePenalty{presence_penalty: f32} = "presence_penalty value ({presence_penalty}) must be between -2.0 and 2.0", | ||
InvalidStop{stop: String} = "stop value ({stop}) must be either 'left' or 'right'", | ||
InvalidStream = "'stream' cannot be used with 'best_of'", | ||
InvalidSuffix = "'suffix' cannot be used with 'echo'", | ||
InvalidBestOf = "'best_of' cannot be used with 'stream'", | ||
InvalidTemperature{temperature: f32} = "temperature value ({temperature}) must be between 0.0 and 2.0", | ||
InvalidTopP{top_p: f32} = "top_p value ({top_p}) must be between 0 and 1", | ||
InvalidPresencePenalty{presence_penalty: f32} = "presence_penalty value ({presence_penalty}) must be between -2.0 and 2.0", | ||
InvalidFrequencyPenalty{frequency_penalty: f32} = "frequency_penalty ({frequency_penalty}) must be between -2.0 and 2.0", | ||
ModelNotFound{model_name: String} = "model not found: {model_name}", | ||
NoChoices = "no chat choices", | ||
NoSession = "no session", | ||
RequestError{body: String} = "request error: {body}", | ||
SerializationError{body: String} = "serialization error: {body}", | ||
} |
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ pub mod completions; | |
pub mod edits; | ||
pub mod error; | ||
pub mod models; | ||
pub mod utils; |
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,22 @@ | ||
use std::env; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
/// Checks if a file exists. | ||
pub fn file_exists(filename: &str) -> bool { | ||
fs::metadata(filename).is_ok() | ||
} | ||
|
||
/// Chacks if a directory exists. | ||
pub fn directory_exists(dir_name: &str) -> bool { | ||
let path = Path::new(dir_name); | ||
path.exists() && path.is_dir() | ||
} | ||
|
||
/// Get HOME directory. | ||
pub fn get_home_directory() -> String { | ||
match env::var("HOME") { | ||
Ok(val) => val + "/.b/sessions", | ||
Err(_) => String::from("/tmp/.b/sessions"), | ||
} | ||
} |