From d0a25dd453b55dbf70dcb4ae666683e4ef055b4d Mon Sep 17 00:00:00 2001 From: Xi Yan Date: Wed, 15 Jan 2025 11:20:23 -0800 Subject: [PATCH] [bugfix] fix llama guard parsing ContentDelta (#772) # What does this PR do? Fix this error image ## Test Plan ``` LLAMA_STACK_BASE_URL="http://localhost:5000" pytest -v tests/client-sdk/inference/test_inference.py ``` ## Sources Please link relevant resources if necessary. ## Before submitting - [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case). - [ ] Ran pre-commit to handle lint / formatting issues. - [ ] Read the [contributor guideline](https://github.com/meta-llama/llama-stack/blob/main/CONTRIBUTING.md), Pull Request section? - [ ] Updated relevant documentation. - [ ] Wrote necessary unit or integration tests. --- .../providers/inline/safety/llama_guard/llama_guard.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/llama_stack/providers/inline/safety/llama_guard/llama_guard.py b/llama_stack/providers/inline/safety/llama_guard/llama_guard.py index 00213ac83..bc4d9640c 100644 --- a/llama_stack/providers/inline/safety/llama_guard/llama_guard.py +++ b/llama_stack/providers/inline/safety/llama_guard/llama_guard.py @@ -263,9 +263,11 @@ class LlamaGuardShield: stream=True, ): event = chunk.event - if event.event_type == ChatCompletionResponseEventType.progress: - assert isinstance(event.delta, str) - content += event.delta + if ( + event.event_type == ChatCompletionResponseEventType.progress + and event.delta.type == "text" + ): + content += event.delta.text content = content.strip() return self.get_shield_response(content)