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

backend - handle openai errors gracefully #91

Open
yevkim opened this issue Dec 11, 2024 · 0 comments
Open

backend - handle openai errors gracefully #91

yevkim opened this issue Dec 11, 2024 · 0 comments

Comments

@yevkim
Copy link
Collaborator

yevkim commented Dec 11, 2024

Openai might return content moderation related query if user asks something explicit

explore this code
try:
# Call your LLM chain
for chunk in chain_with_history.stream({"query": input_text}, config=config):
if hasattr(chunk, 'content'):
yield chunk.content
full_response.append(chunk.content)
except ValueError as e:
# Check if the error message indicates content filtering
if "content filter being triggered" in str(e).lower():
yield "I’m sorry, but I cannot provide an answer to that request."
return
else:
raise

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

No branches or pull requests

1 participant