-
Notifications
You must be signed in to change notification settings - Fork 30
Integration tests for /api/v2/chat/completions-detection
#360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration tests for /api/v2/chat/completions-detection
#360
Conversation
Signed-off-by: Paulo Caldeira <[email protected]>
/api/v2/chat/completions-detection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the tests. I've left a few suggestions.
@@ -55,6 +55,8 @@ pub const ORCHESTRATOR_STREAM_CONTENT_DETECTION_ENDPOINT: &str = | |||
pub const ORCHESTRATOR_DETECTION_ON_GENERATION_ENDPOINT: &str = "/api/v2/text/detection/generated"; | |||
pub const ORCHESTRATOR_CONTEXT_DOCS_DETECTION_ENDPOINT: &str = "/api/v2/text/detection/context"; | |||
pub const ORCHESTRATOR_CHAT_DETECTION_ENDPOINT: &str = "/api/v2/text/detection/chat"; | |||
pub const ORCHESTRATOR_CHAT_COMPLETIONS_DETECTION_ENDPOINT: &str = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Line break, so it lines up with the endpoints grouping in the public API.
pub const ORCHESTRATOR_CHAT_COMPLETIONS_DETECTION_ENDPOINT: &str = | |
pub const ORCHESTRATOR_CHAT_COMPLETIONS_DETECTION_ENDPOINT: &str = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applying suggestion
tests/chat_completions_detection.rs
Outdated
// Constants | ||
const CHUNKER_NAME_SENTENCE: &str = "sentence_chunker"; | ||
const MODEL_ID: &str = "my-super-model-8B"; | ||
const CHAT_COMPLETIONS_ENDPOINT: &str = "/v1/chat/completions"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm understanding this is the chat_generation server endpoint. If so, I'd recommend moving anything related to this server into a new file tests/orchestrator/chat_generation.rs
to line up with the current test code architecture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it is, I'll add the chat endpoint /v1/chat/completions
under tests/common/chat_completions.rs
to keep inline with architecture.
tests/chat_completions_detection.rs
Outdated
stream: false, | ||
..Default::default() | ||
}); | ||
then.json(chat_completions_response.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mocktail method also accepts references so you can avoid the unnecessary clone.
then.json(chat_completions_response.clone()); | |
then.json(&chat_completions_response); |
tests/chat_completions_detection.rs
Outdated
assert_eq!(results.choices[0], chat_completions_response.choices[0]); | ||
assert_eq!(results.choices[1], chat_completions_response.choices[1]); | ||
assert_eq!(results.warnings, vec![]); | ||
assert_eq!(results.detections, expected_detections.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unneeded clone as expected_detections
will not be used after this line.
assert_eq!(results.detections, expected_detections.clone()); | |
assert_eq!(results.detections, expected_detections); |
tests/chat_completions_detection.rs
Outdated
// Validates that requests with input detector configured returns detections | ||
#[test(tokio::test)] | ||
async fn input_detections() -> Result<(), anyhow::Error> { | ||
let detector_name = DETECTOR_NAME_ANGLE_BRACKETS_WHOLE_DOC; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend using a detector with a different chunker in this test to make sure chunker calls are working as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to sentence_chunker
for both input and output detection
tests/chat_completions_detection.rs
Outdated
stream: false, | ||
..Default::default() | ||
}); | ||
then.json(chat_completions_response.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then.json(chat_completions_response.clone()); | |
then.json(&chat_completions_response); |
tests/chat_completions_detection.rs
Outdated
// Validates that requests with output detector configured returns detections | ||
#[test(tokio::test)] | ||
async fn output_detections() -> Result<(), anyhow::Error> { | ||
let detector_name = DETECTOR_NAME_ANGLE_BRACKETS_WHOLE_DOC; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend using a different chunker to make sure chunker calls are working as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to sentence_chunker
for both input and output detection
tests/chat_completions_detection.rs
Outdated
contents: vec![output_text.into()], | ||
detector_params: DetectorParams::new(), | ||
}); | ||
then.json(vec![expected_detections.clone()]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then.json(vec![expected_detections.clone()]); | |
then.json(vec![&expected_detections]); |
tests/chat_completions_detection.rs
Outdated
stream: false, | ||
..Default::default() | ||
}); | ||
then.json(chat_completions_response.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then.json(chat_completions_response.clone()); | |
then.json(&chat_completions_response); |
|
||
// Validate that invalid orchestrator requests returns 422 error | ||
#[test(tokio::test)] | ||
async fn orchestrator_validation_error() -> Result<(), anyhow::Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add more scenarios for this tests, such as making sure missing mandatory fields return 422, but I believe this could be done in a future PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we are validating unknown extra fields here but surely we could add more scenarios for this test, such as suggested missing mandatory fields.
Signed-off-by: Paulo Caldeira <[email protected]>
This PR addresses #341.
/api/v2/chat/completions-detection
endpoint #341 (comment) and were implemented ontests/chat_completions_detection.rs
.