[bugfix] fix llama guard parsing ContentDelta (#772)

# What does this PR do?

Fix this error
<img width="1183" alt="image"
src="https://github.com/user-attachments/assets/a4d48832-a9b9-4fc9-b8b6-79326a13c03e"
/>



## 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.
This commit is contained in:
Xi Yan 2025-01-15 11:20:23 -08:00 committed by GitHub
parent 32d3abe964
commit d0a25dd453
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)