Skip to content
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

Add error handling for unknown fields for chat completion detection request #296

Conversation

swith004
Copy link
Collaborator

@swith004 swith004 commented Feb 5, 2025

What does your PR do?

This PR adds a container attribute from the serde framework to handle unknown fields passed into to a request for the chat completion detection (including the message and the detection section). Unit tests are also added asserting the case used for the scenario used in the git issue.

How this was tested

In addition to new validation unit tests, the request was modified to have an additional field in parts of the request, and was compared with an current orchestrator version deployed on openshift, versus the locally updated version.

Example:

curl -X 'POST' \
>   'http://localhost:8033/api/v2/chat/completions-detection' \
>   -H 'accept: application/json' \
>   -H 'Content-Type: application/json' \
>   -d '{
>   "messages": [
>     {
>       "content": "this is a nice sentence",
>       "role": "user",
>       "name": "string",
>       "additional": "test"
>     }
>   ],
>   "model": "/llama_3_storage/hf/8b_instruction_tuned",
>   "n": 1,
>   "temperature": 1,
>   "top_p": 1,
>   "user": "user-1234",
>   "detectors": {
>     "input": {
>       "en_syntax_slate.38m.hap": {},
>       "en_syntax_rbr_pii": {}
>     }
>   }
> }'
{"code":422,"details":"messages[0].additional: unknown field `additional`, expected one of `role`, `content`, `name`, `refusal`, `tool_calls`, `tool_call_id` at line 7 column 18"}
curl -X 'POST' \
>   'http://localhost:8033/api/v2/chat/completions-detection' \
>   -H 'accept: application/json' \
>   -H 'Content-Type: application/json' \
>   -d '{
>   "messages": [
>     {
>       "content": "this is a nice sentence",
>       "role": "user",
>       "name": "string"
>     }
>   ],
>   "model": "/llama_3_storage/hf/8b_instruction_tuned",
>   "additional_field": "test",
>   "n": 1,
>   "temperature": 1,
>   "top_p": 1,
>   "user": "user-1234",
>   "detectors": {
>     "input": {
>       "en_syntax_slate.38m.hap": {},
>       "en_syntax_rbr_pii": {}
>     }
>   }
> }'
{"code":422,"details":"additional_field: unknown field `additional_field`, expected one of `messages`, `model`, `store`, `metadata`, `frequency_penalty`, `logit_bias`, `logprobs`, `top_logprobs`, `max_tokens`, `max_completion_tokens`, `n`, `presence_penalty`, `response_format`, `seed`, `service_tier`, `stop`, `stream`, `stream_options`, `temperature`, `top_p`, `tools`, `tool_choice`, `parallel_tool_calls`, `user`, `best_of`, `use_beam_search`, `top_k`, `min_p`, `repetition_penalty`, `length_penalty`, `early_stopping`, `ignore_eos`, `min_tokens`, `stop_token_ids`, `skip_special_tokens`, `spaces_between_special_tokens`, `detectors` at line 10 column 20"}
curl -X 'POST' \
>   'http://localhost:8033/api/v2/chat/completions-detection' \
>   -H 'accept: application/json' \
>   -H 'Content-Type: application/json' \
>   -d '{
>   "messages": [
>     {
>       "content": "this is a nice sentence",
>       "role": "user",
>       "name": "string"
>     }
>   ],
>   "model": "/llama_3_storage/hf/8b_instruction_tuned",
>   "n": 1,
>   "temperature": 1,
>   "top_p": 1,
>   "user": "user-1234",
>   "detectors": {
>     "input": {
>       "en_syntax_slate.38m.hap": {},
>       "en_syntax_rbr_pii": {}
>     },
>    "additional_detector_field": "test"
>   }
> }'
{"code":422,"details":"detectors.additional_detector_field: unknown field `additional_detector_field`, expected `input` or `output` at line 19 column 30"}

… request

Signed-off-by: Shonda-Adena-Witherspoon <shonda.adena.witherspoon@ibm.com>
Shonda-Adena-Witherspoon added 2 commits February 5, 2025 15:12
Signed-off-by: Shonda-Adena-Witherspoon <shonda.adena.witherspoon@ibm.com>
…tests

Signed-off-by: Shonda-Adena-Witherspoon <shonda.adena.witherspoon@ibm.com>
@evaline-ju evaline-ju linked an issue Feb 6, 2025 that may be closed by this pull request
Copy link
Collaborator

@declark1 declark1 left a comment

Choose a reason for hiding this comment

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

LGTM. I noticed that the new and existing tests in chat_completions_detection.rs are async fn but actually don't need to be async. Can you drop the async and change #[tokio::test] attribute to #[test]?

@swith004
Copy link
Collaborator Author

swith004 commented Feb 6, 2025

LGTM. I noticed that the new and existing tests in chat_completions_detection.rs are async fn but actually don't need to be async. Can you drop the async and change #[tokio::test] attribute to #[test]?

Will do! - thanks for the review!

Signed-off-by: Shonda-Adena-Witherspoon <shonda.adena.witherspoon@ibm.com>
Copy link
Collaborator

@evaline-ju evaline-ju left a comment

Choose a reason for hiding this comment

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

LGTM

@evaline-ju evaline-ju merged commit c202774 into foundation-model-stack:main Feb 6, 2025
2 checks passed
@swith004 swith004 deleted the error_handling_chat_completion_1588 branch February 6, 2025 18:48
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.

500 when additional field added to chat/completions-detection
3 participants