-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from theoforger/feature/unit-testing
Add unit testing
- Loading branch information
Showing
12 changed files
with
279 additions
and
18 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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
music 2 - sound, bee | ||
film 2 - bond, tokyo | ||
free 2 - park, penny | ||
dive 2 - scuba diver, hospital | ||
large 2 - walrus, scuba diver |
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,13 @@ | ||
distil-whisper-large-v3-en | ||
gemma-7b-it | ||
gemma2-9b-it | ||
llama-3.1-70b-versatile | ||
llama-3.1-8b-instant | ||
llama-guard-3-8b | ||
llama3-70b-8192 | ||
llama3-8b-8192 | ||
llama3-groq-70b-8192-tool-use-preview | ||
llama3-groq-8b-8192-tool-use-preview | ||
llava-v1.5-7b-4096-preview | ||
mixtral-8x7b-32768 | ||
whisper-large-v3 |
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,30 @@ | ||
{ | ||
"id": "chatcmpl-869ede85-2f46-4834-a039-28d757e958a5", | ||
"object": "chat.completion", | ||
"created": 1726870549, | ||
"model": "llama-3.1-70b-versatile", | ||
"choices": [ | ||
{ | ||
"index": 0, | ||
"message": { | ||
"role": "assistant", | ||
"content": "music, 2, sound, bee\nfilm, 2, bond, tokyo\nfree, 2, park, penny\ndive, 2, scuba diver, hospital\nlarge, 2, walrus, scuba diver" | ||
}, | ||
"logprobs": null, | ||
"finish_reason": "stop" | ||
} | ||
], | ||
"usage": { | ||
"queue_time": 0.005669406999999987, | ||
"prompt_tokens": 222, | ||
"prompt_time": 0.068204384, | ||
"completion_tokens": 53, | ||
"completion_time": 0.214023764, | ||
"total_tokens": 275, | ||
"total_time": 0.282228148 | ||
}, | ||
"system_fingerprint": "fp_b6828be2c9", | ||
"x_groq": { | ||
"id": "req_01j88r2wfmecr9zgpjn2zmnprb" | ||
} | ||
} |
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,122 @@ | ||
{ | ||
"object": "list", | ||
"data": [ | ||
{ | ||
"id": "llava-v1.5-7b-4096-preview", | ||
"object": "model", | ||
"created": 1725402373, | ||
"owned_by": "Other", | ||
"active": true, | ||
"context_window": 4096, | ||
"public_apps": null | ||
}, | ||
{ | ||
"id": "gemma-7b-it", | ||
"object": "model", | ||
"created": 1693721698, | ||
"owned_by": "Google", | ||
"active": true, | ||
"context_window": 8192, | ||
"public_apps": null | ||
}, | ||
{ | ||
"id": "llama-3.1-8b-instant", | ||
"object": "model", | ||
"created": 1693721698, | ||
"owned_by": "Meta", | ||
"active": true, | ||
"context_window": 131072, | ||
"public_apps": null | ||
}, | ||
{ | ||
"id": "whisper-large-v3", | ||
"object": "model", | ||
"created": 1693721698, | ||
"owned_by": "OpenAI", | ||
"active": true, | ||
"context_window": 448, | ||
"public_apps": null | ||
}, | ||
{ | ||
"id": "mixtral-8x7b-32768", | ||
"object": "model", | ||
"created": 1693721698, | ||
"owned_by": "Mistral AI", | ||
"active": true, | ||
"context_window": 32768, | ||
"public_apps": null | ||
}, | ||
{ | ||
"id": "llama3-8b-8192", | ||
"object": "model", | ||
"created": 1693721698, | ||
"owned_by": "Meta", | ||
"active": true, | ||
"context_window": 8192, | ||
"public_apps": null | ||
}, | ||
{ | ||
"id": "distil-whisper-large-v3-en", | ||
"object": "model", | ||
"created": 1693721698, | ||
"owned_by": "Hugging Face", | ||
"active": true, | ||
"context_window": 448, | ||
"public_apps": null | ||
}, | ||
{ | ||
"id": "llama-guard-3-8b", | ||
"object": "model", | ||
"created": 1693721698, | ||
"owned_by": "Meta", | ||
"active": true, | ||
"context_window": 8192, | ||
"public_apps": null | ||
}, | ||
{ | ||
"id": "gemma2-9b-it", | ||
"object": "model", | ||
"created": 1693721698, | ||
"owned_by": "Google", | ||
"active": true, | ||
"context_window": 8192, | ||
"public_apps": null | ||
}, | ||
{ | ||
"id": "llama3-70b-8192", | ||
"object": "model", | ||
"created": 1693721698, | ||
"owned_by": "Meta", | ||
"active": true, | ||
"context_window": 8192, | ||
"public_apps": null | ||
}, | ||
{ | ||
"id": "llama3-groq-70b-8192-tool-use-preview", | ||
"object": "model", | ||
"created": 1693721698, | ||
"owned_by": "Groq", | ||
"active": true, | ||
"context_window": 8192, | ||
"public_apps": null | ||
}, | ||
{ | ||
"id": "llama-3.1-70b-versatile", | ||
"object": "model", | ||
"created": 1693721698, | ||
"owned_by": "Meta", | ||
"active": true, | ||
"context_window": 131072, | ||
"public_apps": null | ||
}, | ||
{ | ||
"id": "llama3-groq-8b-8192-tool-use-preview", | ||
"object": "model", | ||
"created": 1693721698, | ||
"owned_by": "Groq", | ||
"active": true, | ||
"context_window": 8192, | ||
"public_apps": null | ||
} | ||
] | ||
} |
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,75 @@ | ||
use super::*; | ||
use crate::api::Instance; | ||
use httpmock::prelude::*; | ||
|
||
#[test] | ||
fn test_api_instance() { | ||
let api_instance = api::Instance::new(); | ||
assert!(api_instance.is_ok()); | ||
} | ||
|
||
#[test] | ||
fn test_read_words_from_file() { | ||
let to_link = read_words_from_file(PathBuf::from("examples/link.txt")); | ||
assert!(to_link.is_ok()); | ||
let to_avoid = read_words_from_file(PathBuf::from("examples/avoid.txt")); | ||
assert!(to_avoid.is_ok()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_fetch_language_models() { | ||
// Start a lightweight mock server. | ||
let server = MockServer::start_async().await; | ||
|
||
// Create a mock on the server. | ||
let mock = server.mock(|when, then| { | ||
when.method(GET).path("/models"); | ||
then.status(200) | ||
.header("content-type", "application/json") | ||
.body_from_file("src/tests/mock_responses/language_models.json"); | ||
}); | ||
|
||
// Create an API instance and set the base url to mock server url | ||
let mut api_instance = Instance::new().unwrap(); | ||
api_instance.set_base_url(server.url("/")); | ||
|
||
// Get response from mock server | ||
let response = api_instance.fetch_language_model_ids().await.unwrap(); | ||
mock.assert(); | ||
|
||
// Compare outputs | ||
let output = response.join("\n"); | ||
let expected_output = fs::read_to_string("src/tests/expected_outputs/language_models.txt").unwrap(); | ||
assert_eq!(output, expected_output); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_fetch_clue_collection() { | ||
// Start a lightweight mock server. | ||
let server = MockServer::start_async().await; | ||
|
||
// Create a mock on the server. | ||
let mock = server.mock(|when, then| { | ||
when.method(POST).path("/chat/completions"); | ||
then.status(200) | ||
.header("content-type", "application/json") | ||
.body_from_file("src/tests/mock_responses/chat_completions.json"); | ||
}); | ||
|
||
// Create an API instance and set the base url to mock server url | ||
let mut api_instance = Instance::new().unwrap(); | ||
api_instance.set_base_url(server.url("/")); | ||
|
||
// Get response from mock server | ||
let response = api_instance | ||
.fetch_clue_collection(vec![], vec![]) | ||
.await | ||
.unwrap(); | ||
mock.assert(); | ||
|
||
// Compare outputs | ||
let output = response.generate_raw_list(); | ||
let expected_output = | ||
fs::read_to_string("src/tests/expected_outputs/chat_completions.txt").unwrap(); | ||
assert_eq!(output, expected_output); | ||
} |