Skip to content

Commit

Permalink
Merge pull request rellfy#24 from rellfy/fix-tests
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
rellfy authored Feb 22, 2024
2 parents 4e7aba9 + 4cff91b commit ded51d1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Cargo
# will have compiled files and executables
/target/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Expand Down
2 changes: 1 addition & 1 deletion examples/completions_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn main() {

stdin().read_line(&mut prompt).unwrap();

let completion = Completion::builder("text-davinci-003")
let completion = Completion::builder("gpt-3.5-turbo-instruct")
.prompt(&prompt)
.max_tokens(1024)
.create()
Expand Down
5 changes: 3 additions & 2 deletions src/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,14 @@ mod tests {
use crate::set_key;
use dotenvy::dotenv;
use std::env;
use crate::tests::DEFAULT_LEGACY_MODEL;

#[tokio::test]
async fn completion() {
dotenv().ok();
set_key(env::var("OPENAI_KEY").unwrap());

let completion = Completion::builder("text-davinci-003")
let completion = Completion::builder(DEFAULT_LEGACY_MODEL)
.prompt("Say this is a test")
.max_tokens(7)
.temperature(0.0)
Expand All @@ -185,7 +186,7 @@ mod tests {

assert_eq!(
completion.choices.first().unwrap().text,
"\n\nThis is indeed a test"
"\n\nThis is a test."
);
}
}
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,11 @@ fn get_base_url() -> &'static Mutex<String> {
}

#[cfg(test)]
mod tests {
pub mod tests {
use super::*;

pub const DEFAULT_LEGACY_MODEL: &str = "gpt-3.5-turbo-instruct";

#[test]
fn test_get_base_url_default() {
assert_eq!(
Expand Down
11 changes: 4 additions & 7 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ use serde::Deserialize;
#[derive(Deserialize, Clone)]
pub struct Model {
pub id: String,
pub object: String,
pub created: u32,
pub owned_by: String,
pub permission: Vec<ModelPermission>,
pub root: String,
pub parent: Option<String>,
}

#[derive(Deserialize, Clone)]
Expand Down Expand Up @@ -44,14 +42,13 @@ mod tests {
use crate::set_key;
use dotenvy::dotenv;
use std::env;
use crate::tests::DEFAULT_LEGACY_MODEL;

#[tokio::test]
async fn model() {
dotenv().ok();
set_key(env::var("OPENAI_KEY").unwrap());

let model = Model::from("text-davinci-003").await.unwrap();

assert_eq!(model.id, "text-davinci-003");
let model = Model::from(DEFAULT_LEGACY_MODEL).await.unwrap();
assert_eq!(model.id, DEFAULT_LEGACY_MODEL);
}
}

0 comments on commit ded51d1

Please sign in to comment.