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 detector_id in response for orchestrator apis #278

Merged
merged 18 commits into from
Jan 21, 2025

Conversation

swith004
Copy link
Collaborator

@swith004 swith004 commented Jan 15, 2025

Story: foundation-model-stack/fms-guardrails-orchestrator#203

What does your PR do?

This PR changes the models for DetectionResponse, TokenClassificationResponse, and ContentAnalysisResponse to include a detector_id along with the results, so that users can identify which detector provided the results (for instance, if there are multiple hap models, such as the cpu optimized version).

How this was tested

This was tested locally, by modifying the config yaml to account for local certs, port-forwarding of os-detectors deployed on openshift, and locally run detectors (for hap). The following are the curl commands used to verify the changes to the orchestrator:

api/v2/text/generation-detection

curl --request POST   --url 'http://localhost:8033/api/v2/text/generation-detection'  --header 'Content-Type: application/json'  --data '{"model_id": "my_LLM",    "prompt": "All people from Kish are cruel and evil.","detectors": {       "my-text-generation-detector-v1": {}},"text_gen_parameters": {"preserve_input_text": true,"max_new_tokens": 99,"min_new_tokens": 1,"truncate_input_tokens": 500,"decoding_method": "SAMPLING","top_k": 2,"top_p": 0.9,"typical_p": 0.5,"temperature": 0.8,"seed": 42,"repetition_penalty": 2,"max_time": 0,"stop_sequences": ["42"]}}'

{"generated_text":"All people from Kish are cruel and evil. They have no respect for human life, they hate the innocent.\nI am a man who has been in this world to help others but I do not want anyone else suffering because of my actions or words that hurt them more than me\nThe only thing you can say is “you can’t be so bad” as if it were true! You shouldn’t even try!\nYou don’t need any kind support when you’re alone with your problems…just let yourself go through whatever it’s like without thinking about what’s","detections":[{"detection_type":"answer_relevance","detection":"relevant","detector_id":"my-text-generation-detector-v1","score":xxx],"input_token_count":9}

api/v2/text/detection/generated

curl -k --url http://localhost:8033/api/v2/text/detection/generated  --header 'Content-Type: application/json' --data '{ "prompt": "What is the name of the solar powered car race held every two years?", "generated_text": "The name of the solar powered car race held every two years is The World Solar Challenge.", "detectors": {  "my-text-generation-detector-v1": {} }}'

{"detections":[{"detection_type":"answer_relevance","detection":"relevant","detector_id":"my-text-generation-detector-v1","score":xxx}]}

api/v2/text/detection/context

curl --request 'POST'   --url 'http://localhost:8033/api/v2/text/detection/context'   --header 'Content-Type: application/json'   --data '{      "detectors": {        "my-context-dectector-v1": {}      },      "content": "What is the name of the solar powered car race held every two years?",      "context_type": "url",      "context": [        "https://en.wikipedia.org/wiki/IBM",        "https://research.ibm.com/"      ]}'

{"detections":[{"detection_type":"context_relevance","detection":"relevant","detector_id":"my-context-dectector-v1","score":xxx,"evidence":[{"name":"context","score":xxx,"evidence":[{"name":"context_chunk","value":"https://en.wikipedia.org/wiki/IBM","score":xxx}]},{"name":"context","score":xxx,"evidence":[{"name":"context_chunk","value":"https://research.ibm.com/","score":xxx}]}]}]}

api/v2/text/detection/content

curl --request POST     --url 'http://localhost:8033/api/v2/text/detection/content'     --header 'accept: application/json'     --header 'Content-Type: application/json'     --data '{
      "detectors": {
        "my-hap-detector-v1": {}
      },
      "content": "All people from Kish are stupid and ignorant."
}'

{"detections":[{"start":0,"end":45,"text":"All people from Kish are stupid and ignorant.","detection":"has_HAP","detection_type":"hap","detector_id":"my-hap-detector-v1","score":xxx}]}

api/v1/task/classification-with-text-generation

curl --request POST   --url 'http://localhost:8033/api/v1/task/classification-with-text-generation'  --header 'Content-Type: application/json'  --data '{"inputs": "All people from Kish are cruel and evil.","model_id": "my_LLM","guardrail_config": {"input": {"models": {"my-hap-detector-v1": {}}},"output": {"models": {"my-hap-detector-v1": {}}}},"text_gen_parameters": {"preserve_input_text": true,"max_new_tokens": 99,"min_new_tokens": 1,"truncate_input_tokens": 500,"decoding_method": "SAMPLING","top_k": 2,"top_p": 0.9,"typical_p": 0.5,"temperature": 0.8,"seed": 42,"repetition_penalty": 2,"max_time": 0,"stop_sequences": ["42"]}}'

{"token_classification_results":{"input":[{"start":0,"end":40,"word":"All people from Kish are cruel and evil.","entity":"has_HAP","entity_group":"hap","detector_id":"my-hap-detector-v1","score":xxx}]},"input_token_count":9,"warnings":[{"id":"UNSUITABLE_INPUT","message":"Unsuitable input detected. Please check the detected entities on your input and try again with the unsuitable input removed."}]}

api/v1/task/server-streaming-classification-with-text-generation

curl --request POST   --url 'http://localhost:8033/api/v1/task/server-streaming-classification-with-text-generation'  --header 'Content-Type: application/json'  --data '{"inputs": "All people from Kish are cruel and evil.","model_id": "my_LLM","guardrail_config": {"input": {"models": {"my-hap-detector-v1": {}}},"output": {"models": {"my-hap-detector-v1": {}}}},"text_gen_parameters": {"preserve_input_text": true,"max_new_tokens": 99,"min_new_tokens": 1,"truncate_input_tokens": 500,"decoding_method": "SAMPLING","top_k": 2,"top_p": 0.9,"typical_p": 0.5,"temperature": 0.8,"seed": 42,"repetition_penalty": 2,"max_time": 0,"stop_sequences": ["42"]}}'

data: {"token_classification_results":{"input":[{"start":0,"end":40,"word":"All people from Kish are cruel and evil.","entity":"has_HAP","entity_group":"hap","detector_id":"my-hap-detector-v1","score":xxx}]},"input_token_count":9,"warnings":[{"id":"UNSUITABLE_INPUT","message":"Unsuitable input detected. Please check the detected entities on your input and try again with the unsuitable input removed."}]}

Shonda-Adena-Witherspoon added 5 commits January 15, 2025 13:21
@evaline-ju evaline-ju linked an issue Jan 15, 2025 that may be closed by this pull request
2 tasks
Shonda-Adena-Witherspoon added 2 commits January 15, 2025 15:58
Signed-off-by: Shonda-Adena-Witherspoon <[email protected]>
protos/caikit_data_model_nlp.proto Outdated Show resolved Hide resolved
src/orchestrator/unary.rs Outdated Show resolved Hide resolved
Signed-off-by: Shonda-Adena-Witherspoon <[email protected]>
…reverted nlp proto

Signed-off-by: Shonda-Adena-Witherspoon <[email protected]>
src/orchestrator/unary.rs Outdated Show resolved Hide resolved
swith004 and others added 2 commits January 17, 2025 13:56
Update setting the detector_id in the  TokenClassificationResult.

Co-authored-by: Dan Clark <[email protected]>
Signed-off-by: swith004 <[email protected]>
src/orchestrator/unary.rs Outdated Show resolved Hide resolved
Signed-off-by: Shonda-Adena-Witherspoon <[email protected]>
@swith004 swith004 requested a review from declark1 January 17, 2025 20:50
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.

mostly LGTM, I think some of the comment consistency was noted earlier but not applied throughout

src/clients/detector/text_contents.rs Outdated Show resolved Hide resolved
src/models.rs Outdated Show resolved Hide resolved
src/models.rs Outdated Show resolved Hide resolved
src/orchestrator/unary.rs Outdated Show resolved Hide resolved
src/orchestrator/unary.rs Outdated Show resolved Hide resolved
swith004 and others added 4 commits January 21, 2025 10:19
Co-authored-by: Evaline Ju <[email protected]>
Signed-off-by: swith004 <[email protected]>
Co-authored-by: Evaline Ju <[email protected]>
Signed-off-by: swith004 <[email protected]>
Co-authored-by: Evaline Ju <[email protected]>
Signed-off-by: swith004 <[email protected]>
Co-authored-by: Evaline Ju <[email protected]>
Signed-off-by: swith004 <[email protected]>
Co-authored-by: Evaline Ju <[email protected]>
Signed-off-by: swith004 <[email protected]>
@swith004 swith004 requested a review from evaline-ju January 21, 2025 15:21
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

@evaline-ju evaline-ju merged commit 1dd51fb into foundation-model-stack:main Jan 21, 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.

Provide detector_id in responses
3 participants