Skip to content

feat: Code scanner Provider impl for moderations api #3100

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

slekkala1
Copy link
Contributor

@slekkala1 slekkala1 commented Aug 11, 2025

What does this PR do?

Add CodeScanner implementations

Test Plan

SAFETY_MODEL=CodeScanner LLAMA_STACK_CONFIG=starter uv run pytest -v tests/integration/safety/test_safety.py --text-model=llama3.2:3b-instruct-fp16 --embedding-model=all-MiniLM-L6-v2 --safety-shield=ollama

This PR need to land after this #3098

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 11, 2025
@slekkala1 slekkala1 force-pushed the code-scanner-moderations-impl branch from 62f4e61 to aee47f0 Compare August 13, 2025 17:31
from typing import Any

from codeshield.cs import CodeShield, CodeShieldScanResult
Copy link
Contributor

Choose a reason for hiding this comment

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

you should add a if TYPE_CHECKING: since you need the import only for that. this is a really bad import and pulls in random stuff so that's why we had relegated it to within the method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


for text_input in inputs:
log.info(f"Running CodeScannerShield moderation on input: {text_input[:100]}...")
scan_result = await CodeShield.scan_code(text_input)
Copy link
Contributor

Choose a reason for hiding this comment

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

some error handling around CodeShield.scan_code(text) would be a good idea, right? Especially when input is not validated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@slekkala1 slekkala1 force-pushed the code-scanner-moderations-impl branch 3 times, most recently from 6da7303 to 900424e Compare August 14, 2025 19:01
@slekkala1 slekkala1 force-pushed the code-scanner-moderations-impl branch from 4e720dc to dfe4ac0 Compare August 15, 2025 17:21
@slekkala1
Copy link
Contributor Author

@skamenan7 Can you take a look? I have updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants