Skip to content

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

Merged

Conversation

pmcjr
Copy link
Collaborator

@pmcjr pmcjr commented Apr 4, 2025

This PR addresses #341.

@pmcjr pmcjr changed the title ✅ Adding integration test cases for unary chat compl… Integration tests for /api/v2/chat/completions-detection Apr 4, 2025
@pmcjr pmcjr requested a review from mdevino April 4, 2025 13:10
Copy link
Collaborator

@mdevino mdevino left a 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 =
Copy link
Collaborator

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.

Suggested change
pub const ORCHESTRATOR_CHAT_COMPLETIONS_DETECTION_ENDPOINT: &str =
pub const ORCHESTRATOR_CHAT_COMPLETIONS_DETECTION_ENDPOINT: &str =

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applying suggestion

// Constants
const CHUNKER_NAME_SENTENCE: &str = "sentence_chunker";
const MODEL_ID: &str = "my-super-model-8B";
const CHAT_COMPLETIONS_ENDPOINT: &str = "/v1/chat/completions";
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

stream: false,
..Default::default()
});
then.json(chat_completions_response.clone());
Copy link
Collaborator

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.

Suggested change
then.json(chat_completions_response.clone());
then.json(&chat_completions_response);

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());
Copy link
Collaborator

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.

Suggested change
assert_eq!(results.detections, expected_detections.clone());
assert_eq!(results.detections, expected_detections);

// 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;
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

stream: false,
..Default::default()
});
then.json(chat_completions_response.clone());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
then.json(chat_completions_response.clone());
then.json(&chat_completions_response);

// 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;
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

contents: vec![output_text.into()],
detector_params: DetectorParams::new(),
});
then.json(vec![expected_detections.clone()]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
then.json(vec![expected_detections.clone()]);
then.json(vec![&expected_detections]);

stream: false,
..Default::default()
});
then.json(chat_completions_response.clone());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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> {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

@declark1 declark1 merged commit 49af6ea into foundation-model-stack:main Apr 4, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants