Skip to content

feat: Code scanner Provider impl for moderations api#3100

Merged
slekkala1 merged 14 commits into
ogx-ai:mainfrom
slekkala1:code-scanner-moderations-impl
Aug 18, 2025
Merged

feat: Code scanner Provider impl for moderations api#3100
slekkala1 merged 14 commits into
ogx-ai:mainfrom
slekkala1:code-scanner-moderations-impl

Conversation

@slekkala1

@slekkala1 slekkala1 commented Aug 11, 2025

Copy link
Copy Markdown
Contributor

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
import uuid
from typing import Any

from codeshield.cs import CodeShield, CodeShieldScanResult

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
Contributor Author

@skamenan7 Can you take a look? I have updated

@slekkala1 slekkala1 merged commit 7519ab4 into ogx-ai:main Aug 18, 2025
44 checks passed
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