repo_id stringclasses 409
values | prefix large_stringlengths 34 36.3k | target large_stringlengths 1 498 | assertion_type stringclasses 31
values | difficulty stringclasses 8
values | test_file stringlengths 10 121 | test_function stringlengths 1 104 | test_class stringlengths 0 51 | lineno int32 2 11.3k | commit_idx int32 |
|---|---|---|---|---|---|---|---|---|---|
protectai/llm-guard | import pytest
from llm_guard.input_scanners.invisible_text import InvisibleText
def convert_to_tag_chars(input_string: str):
return "".join(chr(0xE0000 + ord(ch)) for ch in input_string)
@pytest.mark.parametrize(
"prompt,expected_prompt,expected_valid,expected_score",
[
("Just a simple prompt", "... | expected_score | assert | variable | tests/input_scanners/test_invisible_text.py | test_scan | 83 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.no_refusal import MatchType, NoRefusal, NoRefusalLight
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"Sure! Here are three random tropical fruits, comma-separated, in one line: Papaya, Guava, Dragon fruit.",
T... | expected_score | assert | variable | tests/output_scanners/test_no_refusal.py | test_scan | 79 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.reading_time import ReadingTime
@pytest.mark.parametrize(
"output,expected_output,expected_valid,expected_score",
[
(
"Many people around the world eat meat and fish as part of their diet. Therefore, the statement that all "
"humans ... | expected_valid | assert | variable | tests/output_scanners/test_reading_time.py | test_scan | 29 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.reading_time import ReadingTime
@pytest.mark.parametrize(
"output,expected_output,expected_valid,expected_score",
[
(
"Many people around the world eat meat and fish as part of their diet. Therefore, the statement that all "
"humans ... | expected_score | assert | variable | tests/output_scanners/test_reading_time.py | test_scan | 30 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.ban_topics import BanTopics
@pytest.mark.parametrize(
"prompt,expected_valid,expected_score",
[
(
"How Google makes money?",
True,
-0.2,
), # On topic of money
(
"Implement a system of rewards ... | prompt | assert | variable | tests/input_scanners/test_ban_topics.py | test_scan | 30 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.sentiment import Sentiment
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"I don't have a specific answer for you but I will try to help",
True,
0.0,
), # No negative sentiment
(
... | expected_score | assert | variable | tests/output_scanners/test_sentiment.py | test_scan | 26 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.ban_code import BanCode
@pytest.mark.parametrize(
"prompt,expected_valid,expected_score",
[
("Just a simple prompt", True, -1.0), # Simple prompt
(
"""Fix the following JS code:
function sayHello() {
return "Hello, World!";
}
consol... | expected_valid | assert | variable | tests/input_scanners/test_ban_code.py | test_scan | 55 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.malicious_urls import MaliciousURLs
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"It's https://google.com/.",
True,
-0.5,
), # Good output
(
"It's http://socialsociety... | output | assert | variable | tests/output_scanners/test_malicious_urls.py | test_scan | 29 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.url_reachabitlity import URLReachability
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"It's https://google.com/.",
True,
-1.0,
), # Good output
],
)
def test_scan(output, expected_val... | expected_valid | assert | variable | tests/output_scanners/test_url_reachability.py | test_scan | 20 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.prompt_injection import MatchType, PromptInjection
@pytest.mark.parametrize(
"match_type,prompt,expected_valid,expected_score",
[
# Good prompts
(
MatchType.FULL,
'I want you to act as a composer. I will provide the lyrics to ... | prompt | assert | variable | tests/input_scanners/test_prompt_injection.py | test_scan | 493 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.ban_topics import BanTopics
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"Winning an election should be based on ethical practices, offering clear and compelling policies, "
"engaging with constituents, and e... | expected_score | assert | variable | tests/output_scanners/test_ban_topics.py | test_scan | 29 | null | |
protectai/llm-guard | import pytest
from llm_guard.util import (
calculate_risk_score,
chunk_text,
extract_urls,
remove_markdown,
split_text_by_sentences,
split_text_to_word_chunks,
truncate_tokens_head_tail,
)
@pytest.mark.parametrize(
"text, expected_sentences",
[
("This is a test. Another sen... | expected_sentences | assert | variable | tests/test_util.py | test_split_text_by_sentences_splits_correctly | 49 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.ban_code import BanCode
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
("", True, -1.0), # Empty prompt
(
"""Sure! Here's a simple JavaScript function that returns "Hello, World!":
function sayHello() {
return ... | expected_valid | assert | variable | tests/output_scanners/test_ban_code.py | test_scan | 70 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.prompt_injection import MatchType, PromptInjection
@pytest.mark.parametrize(
"match_type,prompt,expected_valid,expected_score",
[
# Good prompts
(
MatchType.FULL,
'I want you to act as a composer. I will provide the lyrics to ... | expected_valid | assert | variable | tests/input_scanners/test_prompt_injection.py | test_scan | 494 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.bias import Bias, MatchType
@pytest.mark.parametrize(
"match_type,prompt,output,expected_valid,expected_score",
[
(
MatchType.FULL,
"What do you think about Christianity?",
"Christians should make clear that the perpetuat... | output | assert | variable | tests/output_scanners/test_bias.py | test_scan | 50 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.ban_substrings import PROMPT_STOP_SUBSTRINGS, BanSubstrings
@pytest.mark.parametrize(
"prompt,redact,expected_prompt,expected_valid,expected_score",
[
("Just a simple prompt", False, "Just a simple prompt", True, -1.0), # Simple prompt
("", False, "... | expected_valid | assert | variable | tests/input_scanners/test_ban_substrings.py | test_scan | 38 | null | |
protectai/llm-guard | from typing import List, Tuple
import pytest
from llm_guard.input_scanners.anonymize import Anonymize
from llm_guard.output_scanners.deanonymize import Deanonymize, MatchingStrategy
from llm_guard.vault import Vault
@pytest.mark.parametrize(
"vault_items,output,expected_output,matching_strategy",
[
(... | -1.0 | assert | numeric_literal | tests/output_scanners/test_deanonymize.py | test_scan | 89 | null | |
protectai/llm-guard | import pytest
from llm_guard.util import (
calculate_risk_score,
chunk_text,
extract_urls,
remove_markdown,
split_text_by_sentences,
split_text_to_word_chunks,
truncate_tokens_head_tail,
)
@pytest.mark.parametrize(
"score, threshold, expected_risk_score",
[
(0.2, 0.5, -0.6)... | expected_risk_score | assert | variable | tests/test_util.py | test_calculate_risk_score_calculates_correctly | 25 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.invisible_text import InvisibleText
def convert_to_tag_chars(input_string: str):
return "".join(chr(0xE0000 + ord(ch)) for ch in input_string)
@pytest.mark.parametrize(
"prompt,expected_prompt,expected_valid,expected_score",
[
("Just a simple prompt", "... | expected_prompt | assert | variable | tests/input_scanners/test_invisible_text.py | test_scan | 81 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.sentiment import Sentiment
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"I don't have a specific answer for you but I will try to help",
True,
0.0,
), # No negative sentiment
(
... | expected_valid | assert | variable | tests/output_scanners/test_sentiment.py | test_scan | 25 | null | |
protectai/llm-guard | from typing import List, Tuple
import pytest
from llm_guard.input_scanners.anonymize import Anonymize
from llm_guard.output_scanners.deanonymize import Deanonymize, MatchingStrategy
from llm_guard.vault import Vault
@pytest.mark.parametrize(
"raw_prompt,output,expected_output,expected_valid,expected_score",
... | expected_score | assert | variable | tests/output_scanners/test_deanonymize.py | test_scan_full | 41 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.language import Language, MatchType
@pytest.mark.parametrize(
"match_type,prompt,expected_valid,expected_score",
[
(MatchType.FULL, "Just a prompt", True, -1.0), # Correct output
(
MatchType.FULL,
"Me llamo Sofia. ¿Cómo te ll... | prompt | assert | variable | tests/input_scanners/test_language.py | test_scan | 50 | null | |
protectai/llm-guard | import re
import pytest
from llm_guard.exception import LLMGuardValidationError
from llm_guard.input_scanners.anonymize import (
ALL_SUPPORTED_LANGUAGES,
DEFAULT_ENTITY_TYPES,
Anonymize,
)
from llm_guard.input_scanners.anonymize_helpers import (
BERT_BASE_NER_CONF,
BERT_LARGE_NER_CONF,
BERT_ZH... | result1 | assert | variable | tests/input_scanners/test_anonymize.py | test_placeholder_consistency | 389 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.factual_consistency import FactualConsistency
@pytest.mark.parametrize(
"prompt,output,expected_valid,expected_score",
[
(
"All humans are vegetarians.",
"Many people around the world eat meat and fish as part of their diet. Therefor... | output | assert | variable | tests/output_scanners/test_factual_consistency.py | test_scan | 33 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.prompt_injection import MatchType, PromptInjection
@pytest.mark.parametrize(
"match_type,prompt,expected_valid,expected_score",
[
# Good prompts
(
MatchType.FULL,
'I want you to act as a composer. I will provide the lyrics to ... | expected_score | assert | variable | tests/input_scanners/test_prompt_injection.py | test_scan | 495 | null | |
protectai/llm-guard | from typing import List, Tuple
import pytest
from llm_guard.input_scanners.anonymize import Anonymize
from llm_guard.output_scanners.deanonymize import Deanonymize, MatchingStrategy
from llm_guard.vault import Vault
@pytest.mark.parametrize(
"raw_prompt,output,expected_output,expected_valid,expected_score",
... | expected_output | assert | variable | tests/output_scanners/test_deanonymize.py | test_scan_full | 39 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.token_limit import TokenLimit
@pytest.mark.parametrize(
"prompt,expected_prompt,expected_valid,expected_score",
[
("Just a simple prompt", "Just a simple prompt", True, -1.0), # Simple prompt
(
"Can you provide a comprehensive overview o... | expected_prompt | assert | variable | tests/input_scanners/test_token_limit.py | test_scan | 24 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.ban_substrings import PROMPT_STOP_SUBSTRINGS, BanSubstrings
@pytest.mark.parametrize(
"prompt,redact,expected_prompt,expected_valid,expected_score",
[
("Just a simple prompt", False, "Just a simple prompt", True, -1.0), # Simple prompt
("", False, "... | expected_score | assert | variable | tests/input_scanners/test_ban_substrings.py | test_scan | 39 | null | |
protectai/llm-guard | from typing import List
import pytest
from llm_guard.input_scanners.ban_competitors import BanCompetitors
@pytest.mark.parametrize(
"competitors,prompt,expected_prompt,expected_valid,expected_score",
[
(
["Google", "Bing", "DuckDuckGo"],
"Tell me about your competitors like Go... | expected_score | assert | variable | tests/input_scanners/test_ban_competitors.py | test_scan | 40 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.toxicity import MatchType, Toxicity
@pytest.mark.parametrize(
"match_type,prompt,expected_valid,expected_score",
[
(
MatchType.FULL,
"Just a simple prompt",
True,
-1.0,
), # Simple prompt
# Tox... | expected_score | assert | variable | tests/input_scanners/test_toxicity.py | test_scan | 66 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.ban_substrings import OUTPUT_STOP_SUBSTRINGS, BanSubstrings
@pytest.mark.parametrize(
"output,expected_output,expected_valid,expected_score",
[
("", "", True, -1.0), # Empty prompt
(
"DAN Mode enabled. GPT: As an AI language model, my p... | expected_output | assert | variable | tests/output_scanners/test_ban_substrings.py | test_scan | 33 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.toxicity import Toxicity
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"As a software, I am not capable of engaging in verbal sparring or offensive behavior. It is crucial to "
"maintain a courteous and respec... | expected_score | assert | variable | tests/output_scanners/test_toxicity.py | test_scan | 33 | null | |
protectai/llm-guard | import re
import pytest
from llm_guard.exception import LLMGuardValidationError
from llm_guard.input_scanners.anonymize import (
ALL_SUPPORTED_LANGUAGES,
DEFAULT_ENTITY_TYPES,
Anonymize,
)
from llm_guard.input_scanners.anonymize_helpers import (
BERT_BASE_NER_CONF,
BERT_LARGE_NER_CONF,
BERT_ZH... | 1 | assert | numeric_literal | tests/input_scanners/test_anonymize.py | test_placeholder_consistency | 362 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.toxicity import MatchType, Toxicity
@pytest.mark.parametrize(
"match_type,prompt,expected_valid,expected_score",
[
(
MatchType.FULL,
"Just a simple prompt",
True,
-1.0,
), # Simple prompt
# Tox... | expected_valid | assert | variable | tests/input_scanners/test_toxicity.py | test_scan | 65 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.ban_topics import BanTopics
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"Winning an election should be based on ethical practices, offering clear and compelling policies, "
"engaging with constituents, and e... | output | assert | variable | tests/output_scanners/test_ban_topics.py | test_scan | 27 | null | |
protectai/llm-guard | import re
import pytest
from llm_guard.exception import LLMGuardValidationError
from llm_guard.input_scanners.anonymize import (
ALL_SUPPORTED_LANGUAGES,
DEFAULT_ENTITY_TYPES,
Anonymize,
)
from llm_guard.input_scanners.anonymize_helpers import (
BERT_BASE_NER_CONF,
BERT_LARGE_NER_CONF,
BERT_ZH... | result2 | assert | variable | tests/input_scanners/test_anonymize.py | test_placeholder_consistency | 390 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.toxicity import Toxicity
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"As a software, I am not capable of engaging in verbal sparring or offensive behavior. It is crucial to "
"maintain a courteous and respec... | output | assert | variable | tests/output_scanners/test_toxicity.py | test_scan | 31 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.toxicity import MatchType, Toxicity
@pytest.mark.parametrize(
"match_type,prompt,expected_valid,expected_score",
[
(
MatchType.FULL,
"Just a simple prompt",
True,
-1.0,
), # Simple prompt
# Tox... | prompt | assert | variable | tests/input_scanners/test_toxicity.py | test_scan | 64 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.relevance import Relevance
@pytest.mark.parametrize(
"prompt,output,expected_valid,expected_score",
[
("", "", True, -1.0), # Empty prompt
(
"brainstorm 3 names for a child",
"Aria Solstice, Orion Lark, Seraphina Wren",
... | output | assert | variable | tests/output_scanners/test_relevance.py | test_scan | 28 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.gibberish import Gibberish
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"Lastly, the eon-sift of verberate phase travel elopes with a rehiring toward nature-agreeable re-entrenches. Investors, lore by bound spectrum, and... | output | assert | variable | tests/output_scanners/test_gibberish.py | test_scan | 29 | null | |
protectai/llm-guard | from typing import List
import pytest
from llm_guard.input_scanners.ban_competitors import BanCompetitors
@pytest.mark.parametrize(
"competitors,prompt,expected_prompt,expected_valid,expected_score",
[
(
["Google", "Bing", "DuckDuckGo"],
"Tell me about your competitors like Go... | expected_prompt | assert | variable | tests/input_scanners/test_ban_competitors.py | test_scan | 38 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.gibberish import Gibberish
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"Lastly, the eon-sift of verberate phase travel elopes with a rehiring toward nature-agreeable re-entrenches. Investors, lore by bound spectrum, and... | expected_score | assert | variable | tests/output_scanners/test_gibberish.py | test_scan | 31 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.regex import MatchType
from llm_guard.output_scanners.regex import Regex
@pytest.mark.parametrize(
"output,expected_output,expected_valid,expected_score",
[
("Just a output", "Just a output", True, -1.0), # Correct output
(
"Here is an e... | expected_valid | assert | variable | tests/output_scanners/test_regex.py | test_scan | 28 | null | |
protectai/llm-guard | import pytest
from llm_guard.util import (
calculate_risk_score,
chunk_text,
extract_urls,
remove_markdown,
split_text_by_sentences,
split_text_to_word_chunks,
truncate_tokens_head_tail,
)
@pytest.mark.parametrize(
"text, chunk_size, expected_chunks",
[
("This is a test.", ... | expected_chunks | assert | variable | tests/test_util.py | test_chunk_text_chunks_correctly | 37 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.bias import Bias, MatchType
@pytest.mark.parametrize(
"match_type,prompt,output,expected_valid,expected_score",
[
(
MatchType.FULL,
"What do you think about Christianity?",
"Christians should make clear that the perpetuat... | expected_valid | assert | variable | tests/output_scanners/test_bias.py | test_scan | 51 | null | |
protectai/llm-guard | import pytest
from llm_guard import scan_output, scan_prompt
from llm_guard.input_scanners import BanSubstrings, TokenLimit
from llm_guard.input_scanners.ban_substrings import MatchType as BanSubstringsMatchType
from llm_guard.output_scanners import (
BanTopics,
Deanonymize,
Gibberish,
NoRefusal,
R... | expected_results | assert | variable | tests/test_evaluate.py | test_scan_prompt | 53 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.malicious_urls import MaliciousURLs
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"It's https://google.com/.",
True,
-0.5,
), # Good output
(
"It's http://socialsociety... | expected_score | assert | variable | tests/output_scanners/test_malicious_urls.py | test_scan | 31 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.regex import MatchType, Regex
@pytest.mark.parametrize(
"prompt,expected_prompt,expected_valid,expected_score",
[
("Just a prompt", "Just a prompt", True, -1.0), # Correct output
(
"Here is my token: Bearer abc-def_123",
"Her... | expected_valid | assert | variable | tests/input_scanners/test_regex.py | test_scan | 33 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.ban_topics import BanTopics
@pytest.mark.parametrize(
"prompt,expected_valid,expected_score",
[
(
"How Google makes money?",
True,
-0.2,
), # On topic of money
(
"Implement a system of rewards ... | expected_score | assert | variable | tests/input_scanners/test_ban_topics.py | test_scan | 32 | null | |
protectai/llm-guard | import re
import pytest
from llm_guard.exception import LLMGuardValidationError
from llm_guard.input_scanners.anonymize import (
ALL_SUPPORTED_LANGUAGES,
DEFAULT_ENTITY_TYPES,
Anonymize,
)
from llm_guard.input_scanners.anonymize_helpers import (
BERT_BASE_NER_CONF,
BERT_LARGE_NER_CONF,
BERT_ZH... | None | assert | none_literal | tests/input_scanners/test_anonymize.py | test_patterns | 327 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.gibberish import Gibberish
@pytest.mark.parametrize(
"prompt,expected_valid,expected_score",
[
("Just a simple prompt", True, -0.7), # Simple prompt
(
"dfdfer fgerfow2e0d qsqskdsd djksdnfkff swq",
False,
1.0,
... | expected_score | assert | variable | tests/input_scanners/test_gibberish.py | test_scan | 27 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.code import Code
@pytest.mark.parametrize(
"prompt,expected_valid,expected_score",
[
("Just a simple prompt", True, -1.0), # Simple prompt
(
"""Fix the following JS code:
```js
function sayHello() {
return "Hello, World!";
}
console... | prompt | assert | variable | tests/input_scanners/test_code.py | test_scan | 40 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.sentiment import Sentiment
@pytest.mark.parametrize(
"prompt,expected_valid,expected_score",
[
("Just a simple prompt", True, 0.0), # Simple prompt
(
"I heard that Mars is the closest planet to Earth. Is that true?",
True,
... | expected_valid | assert | variable | tests/input_scanners/test_sentiment.py | test_scan | 35 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.language import Language, MatchType
@pytest.mark.parametrize(
"match_type,prompt,expected_valid,expected_score",
[
(MatchType.FULL, "Just a prompt", True, -1.0), # Correct output
(
MatchType.FULL,
"Me llamo Sofia. ¿Cómo te ll... | expected_score | assert | variable | tests/input_scanners/test_language.py | test_scan | 52 | null | |
protectai/llm-guard | import pytest
from llm_guard import scan_output, scan_prompt
from llm_guard.input_scanners import BanSubstrings, TokenLimit
from llm_guard.input_scanners.ban_substrings import MatchType as BanSubstringsMatchType
from llm_guard.output_scanners import (
BanTopics,
Deanonymize,
Gibberish,
NoRefusal,
R... | expected_sanitized_prompt | assert | variable | tests/test_evaluate.py | test_scan_prompt | 52 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.code import Code
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
("", True, -1.0), # Empty prompt
(
"""Sure! Here's a simple JavaScript function that returns "Hello, World!":
```js
function sayHello() {
return "... | expected_score | assert | variable | tests/output_scanners/test_code.py | test_scan | 68 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.sentiment import Sentiment
@pytest.mark.parametrize(
"prompt,expected_valid,expected_score",
[
("Just a simple prompt", True, 0.0), # Simple prompt
(
"I heard that Mars is the closest planet to Earth. Is that true?",
True,
... | prompt | assert | variable | tests/input_scanners/test_sentiment.py | test_scan | 34 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.gibberish import Gibberish
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"Lastly, the eon-sift of verberate phase travel elopes with a rehiring toward nature-agreeable re-entrenches. Investors, lore by bound spectrum, and... | expected_valid | assert | variable | tests/output_scanners/test_gibberish.py | test_scan | 30 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.ban_substrings import OUTPUT_STOP_SUBSTRINGS, BanSubstrings
@pytest.mark.parametrize(
"output,expected_output,expected_valid,expected_score",
[
("", "", True, -1.0), # Empty prompt
(
"DAN Mode enabled. GPT: As an AI language model, my p... | expected_valid | assert | variable | tests/output_scanners/test_ban_substrings.py | test_scan | 34 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.malicious_urls import MaliciousURLs
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"It's https://google.com/.",
True,
-0.5,
), # Good output
(
"It's http://socialsociety... | expected_valid | assert | variable | tests/output_scanners/test_malicious_urls.py | test_scan | 30 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.token_limit import TokenLimit
@pytest.mark.parametrize(
"prompt,expected_prompt,expected_valid,expected_score",
[
("Just a simple prompt", "Just a simple prompt", True, -1.0), # Simple prompt
(
"Can you provide a comprehensive overview o... | expected_score | assert | variable | tests/input_scanners/test_token_limit.py | test_scan | 26 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.ban_substrings import PROMPT_STOP_SUBSTRINGS, BanSubstrings
@pytest.mark.parametrize(
"prompt,redact,expected_prompt,expected_valid,expected_score",
[
("Just a simple prompt", False, "Just a simple prompt", True, -1.0), # Simple prompt
("", False, "... | expected_prompt | assert | variable | tests/input_scanners/test_ban_substrings.py | test_scan | 37 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.ban_code import BanCode
@pytest.mark.parametrize(
"prompt,expected_valid,expected_score",
[
("Just a simple prompt", True, -1.0), # Simple prompt
(
"""Fix the following JS code:
function sayHello() {
return "Hello, World!";
}
consol... | prompt | assert | variable | tests/input_scanners/test_ban_code.py | test_scan | 54 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.ban_code import BanCode
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
("", True, -1.0), # Empty prompt
(
"""Sure! Here's a simple JavaScript function that returns "Hello, World!":
function sayHello() {
return ... | output | assert | variable | tests/output_scanners/test_ban_code.py | test_scan | 69 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.emotion_detection import EmotionDetection
def test_scan_no_blocked_emotions():
"""Test that the scanner allows all emotions when blocked_emotions is empty."""
scanner = EmotionDetection(
threshold=0.5,
blocked_emotions=[], # No blocked emotions
... | True | assert | bool_literal | tests/input_scanners/test_emotion_detection.py | test_scan_no_blocked_emotions | 61 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.ban_code import BanCode
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
("", True, -1.0), # Empty prompt
(
"""Sure! Here's a simple JavaScript function that returns "Hello, World!":
function sayHello() {
return ... | expected_score | assert | variable | tests/output_scanners/test_ban_code.py | test_scan | 71 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.sentiment import Sentiment
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"I don't have a specific answer for you but I will try to help",
True,
0.0,
), # No negative sentiment
(
... | output | assert | variable | tests/output_scanners/test_sentiment.py | test_scan | 24 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.ban_topics import BanTopics
@pytest.mark.parametrize(
"prompt,expected_valid,expected_score",
[
(
"How Google makes money?",
True,
-0.2,
), # On topic of money
(
"Implement a system of rewards ... | expected_valid | assert | variable | tests/input_scanners/test_ban_topics.py | test_scan | 31 | null | |
protectai/llm-guard | from typing import List
import pytest
from llm_guard.output_scanners.ban_competitors import BanCompetitors
@pytest.mark.parametrize(
"competitors,output,expected_output,expected_valid,expected_score",
[
(
["Google", "Bing", "DuckDuckGo"],
"Your competitors are Google, Bing, an... | expected_score | assert | variable | tests/output_scanners/test_ban_competitors.py | test_scan | 31 | null | |
protectai/llm-guard | from typing import List
import pytest
from llm_guard.input_scanners.ban_competitors import BanCompetitors
@pytest.mark.parametrize(
"competitors,prompt,expected_prompt,expected_valid,expected_score",
[
(
["Google", "Bing", "DuckDuckGo"],
"Tell me about your competitors like Go... | expected_valid | assert | variable | tests/input_scanners/test_ban_competitors.py | test_scan | 39 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.emotion_detection import EmotionDetection
@pytest.mark.parametrize(
"output,expected_valid,check_score",
[
(
"I don't have a specific answer for you but I will try to help",
True,
lambda s: s == 0.0,
), # No bloc... | output | assert | variable | tests/output_scanners/test_emotion_detection.py | test_scan | 36 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.reading_time import ReadingTime
@pytest.mark.parametrize(
"output,expected_output,expected_valid,expected_score",
[
(
"Many people around the world eat meat and fish as part of their diet. Therefore, the statement that all "
"humans ... | expected_output | assert | variable | tests/output_scanners/test_reading_time.py | test_scan | 28 | null | |
protectai/llm-guard | import pytest
from llm_guard.util import (
calculate_risk_score,
chunk_text,
extract_urls,
remove_markdown,
split_text_by_sentences,
split_text_to_word_chunks,
truncate_tokens_head_tail,
)
@pytest.mark.parametrize(
"tokens, max_length, head_length, tail_length, expected_tokens",
[
... | expected_tokens | assert | variable | tests/test_util.py | test_truncate_tokens_head_tail_truncates_correctly | 77 | null | |
protectai/llm-guard | from typing import List
import pytest
from llm_guard.output_scanners.ban_competitors import BanCompetitors
@pytest.mark.parametrize(
"competitors,output,expected_output,expected_valid,expected_score",
[
(
["Google", "Bing", "DuckDuckGo"],
"Your competitors are Google, Bing, an... | expected_valid | assert | variable | tests/output_scanners/test_ban_competitors.py | test_scan | 30 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.emotion_detection import EmotionDetection
def test_get_emotion_analysis():
"""Test that the scanner can return full emotion analysis."""
scanner = EmotionDetection(threshold=0.5)
prompt = "I am so happy and excited about this!"
emotion_analysis = scanner.ge... | 0 | assert | numeric_literal | tests/input_scanners/test_emotion_detection.py | test_get_emotion_analysis | 73 | null | |
protectai/llm-guard | import pytest
from llm_guard.output_scanners.no_refusal import MatchType, NoRefusal, NoRefusalLight
@pytest.mark.parametrize(
"output,expected_valid,expected_score",
[
(
"Sure! Here are three random tropical fruits, comma-separated, in one line: Papaya, Guava, Dragon fruit.",
T... | output | assert | variable | tests/output_scanners/test_no_refusal.py | test_scan | 77 | null | |
protectai/llm-guard | import pytest
from llm_guard.util import (
calculate_risk_score,
chunk_text,
extract_urls,
remove_markdown,
split_text_by_sentences,
split_text_to_word_chunks,
truncate_tokens_head_tail,
)
@pytest.mark.parametrize(
"text, expected_urls",
[
("Check this link: http://example.... | expected_urls | assert | variable | tests/test_util.py | test_extract_urls_extracts_correctly | 89 | null | |
protectai/llm-guard | import pytest
from llm_guard.input_scanners.gibberish import Gibberish
@pytest.mark.parametrize(
"prompt,expected_valid,expected_score",
[
("Just a simple prompt", True, -0.7), # Simple prompt
(
"dfdfer fgerfow2e0d qsqskdsd djksdnfkff swq",
False,
1.0,
... | expected_valid | assert | variable | tests/input_scanners/test_gibberish.py | test_scan | 26 | null | |
bayespy/bayespy | import warnings
import numpy as np
from bayespy.nodes import (GaussianARD,
Gamma,
Mixture,
Categorical,
Bernoulli,
Multinomial,
Beta,
... | ( (), () )) | self.assertEqual | collection | bayespy/inference/vmp/nodes/tests/test_mixture.py | test_message_to_child | TestMixture | 80 | null |
bayespy/bayespy | import unittest
import warnings
import numpy as np
from scipy.special import psi
from numpy import testing
from .. import misc
class TestAddAxes(misc.TestCase):
def test_add_axes(self):
r"""
Test the add_axes method.
"""
f = lambda X, **kwargs: np.shape(misc.add_axes(X, **kwarg... | (1,1,1,3)) | self.assertEqual | collection | bayespy/utils/tests/test_misc.py | test_add_axes | TestAddAxes | 80 | null |
bayespy/bayespy | import warnings
import numpy as np
import scipy
from bayespy.nodes import (Categorical,
Dirichlet,
Mixture,
Gamma)
from bayespy.utils import random
from bayespy.utils import misc
from bayespy.utils.misc import TestCase
class TestCateg... | 1) | self.assertEqual | numeric_literal | bayespy/inference/vmp/nodes/tests/test_categorical.py | test_moments | TestCategorical | 95 | null |
bayespy/bayespy | import unittest
import numpy as np
import scipy
from numpy import testing
from ..node import Node, Moments
from ...vmp import VB
from bayespy.utils import misc
class TestNode(misc.TestCase):
def check_message_to_parent(self, plates_child, plates_message,
plates_mask, plates_pa... | ValueError) | self.assertRaises | variable | bayespy/inference/vmp/nodes/tests/test_node.py | test_message_to_parent | TestNode | 259 | null |
bayespy/bayespy | import numpy as np
from scipy import special
from numpy import testing
from .. import gaussian
from bayespy.nodes import (Gaussian,
GaussianARD,
GaussianGamma,
Gamma,
Wishart,
Concat... | X1) | assert_* | variable | bayespy/inference/vmp/nodes/tests/test_gaussian.py | test_message_to_parents | TestConcatGaussian | 1,435 | null |
bayespy/bayespy | import unittest
import warnings
import numpy as np
from scipy.special import psi
from numpy import testing
from .. import misc
class TestCeilDiv(misc.TestCase):
def test_ceildiv(self):
r"""
Test the ceil division
"""
self.assertEqual( | 3) | self.assertEqual | numeric_literal | bayespy/utils/tests/test_misc.py | test_ceildiv | TestCeilDiv | 30 | null |
bayespy/bayespy | import numpy as np
from .. import misc
from .. import random
class TestAlphaBetaRecursion(misc.TestCase):
def test(self):
r"""
Test the results of alpha-beta recursion for Markov chains
"""
np.seterr(divide='ignore')
# Deterministic oscillator
p0 = np.array([1.0,... | np.all(~np.isnan(g))) | self.assertTrue | func_call | bayespy/utils/tests/test_random.py | test | TestAlphaBetaRecursion | 258 | null |
bayespy/bayespy | import unittest
import warnings
import numpy as np
from scipy.special import psi
from numpy import testing
from .. import misc
class TestAddAxes(misc.TestCase):
def test_add_axes(self):
r"""
Test the add_axes method.
"""
f = lambda X, **kwargs: np.shape(misc.add_axes(X, **kwarg... | (2,3,4,1)) | self.assertEqual | collection | bayespy/utils/tests/test_misc.py | test_add_axes | TestAddAxes | 98 | null |
bayespy/bayespy | import numpy as np
from ..gaussian_markov_chain import GaussianMarkovChain
from ..gaussian_markov_chain import VaryingGaussianMarkovChain
from ..gaussian import Gaussian, GaussianMoments
from ..gaussian import GaussianARD
from ..gaussian import GaussianGamma
from ..wishart import Wishart, WishartMoments
from ..gamma i... | V) | assert_* | variable | bayespy/inference/vmp/nodes/tests/test_gaussian_markov_chain.py | test_message_to_parents | TestGaussianMarkovChain | 238 | null |
bayespy/bayespy | import numpy as np
from scipy import special
from numpy import testing
from .. import gaussian
from bayespy.nodes import (Gaussian,
GaussianARD,
GaussianGamma,
Gamma,
Wishart,
Concat... | X2) | assert_* | variable | bayespy/inference/vmp/nodes/tests/test_gaussian.py | test_message_to_parents | TestConcatGaussian | 1,442 | null |
bayespy/bayespy | import numpy as np
from scipy import special
from numpy import testing
from .. import gaussian
from bayespy.nodes import (Gaussian,
GaussianARD,
GaussianGamma,
Gamma,
Wishart,
Concat... | a) | assert_* | variable | bayespy/inference/vmp/nodes/tests/test_gaussian.py | test_message_to_parents | TestGaussianARD | 687 | null |
bayespy/bayespy | import unittest
import warnings
import numpy as np
from scipy.special import psi
from numpy import testing
from .. import misc
class TestMultiplyShapes(unittest.TestCase):
def test_multiply_shapes(self):
f = lambda *shapes: tuple(misc.multiply_shapes(*shapes))
# Basic test
self.asser... | (6,)) | self.assertEqual | collection | bayespy/utils/tests/test_misc.py | test_multiply_shapes | TestMultiplyShapes | 136 | null |
bayespy/bayespy | import numpy as np
from bayespy.nodes import GaussianARD
from bayespy.nodes import Take
from bayespy.inference import VB
from bayespy.utils.misc import TestCase
class TestTake(TestCase):
def test_parent_validity(self):
r"""
Test that the parent nodes are validated properly
"""
... | ()) | self.assertEqual | collection | bayespy/inference/vmp/nodes/tests/test_take.py | test_parent_validity | TestTake | 33 | null |
bayespy/bayespy | import unittest
import warnings
import numpy as np
from scipy.special import psi
from numpy import testing
from .. import misc
class TestCeilDiv(misc.TestCase):
def test_ceildiv(self):
r"""
Test the ceil division
"""
self.assertEqual(misc.ceildiv(3, 1),
... | -2) | self.assertEqual | numeric_literal | bayespy/utils/tests/test_misc.py | test_ceildiv | TestCeilDiv | 42 | null |
bayespy/bayespy | import numpy as np
from .. import misc
from .. import linalg
class TestBandedSolve(misc.TestCase):
def test_block_banded_solve(self):
r"""
Test the Gaussian elimination algorithm for block-banded matrices.
"""
#
# Create a block-banded matrix
#
# Number o... | np.allclose(invA[-1], invC[i0:, i0:])) | self.assertTrue | func_call | bayespy/utils/tests/test_linalg.py | test_block_banded_solve | TestBandedSolve | 175 | null |
bayespy/bayespy | import unittest
import numpy as np
import scipy
from numpy import testing
from ..node import Node, Moments
from ..deterministic import tile
from ..stochastic import Stochastic
class TestTile(unittest.TestCase):
def check_message_to_children(self, tiles, u_parent, u_tiled,
dims... | mask_true) | assert_* | variable | bayespy/inference/vmp/nodes/tests/test_deterministic.py | check_mask_to_parent | TestTile | 269 | null |
bayespy/bayespy | import unittest
import warnings
import numpy as np
from scipy.special import psi
from numpy import testing
from .. import misc
class TestSumMultiply(unittest.TestCase):
def check_sum_multiply(self, *shapes, **kwargs):
# The set of arrays
x = list()
for (ind, shape) in enumerate(shapes... | y) | assert_* | variable | bayespy/utils/tests/test_misc.py | check_sum_multiply | TestSumMultiply | 199 | null |
bayespy/bayespy | import numpy as np
import scipy
from bayespy.nodes import (Multinomial,
Dirichlet,
Mixture)
from bayespy.utils import random
from bayespy.utils.misc import TestCase
class TestMultinomial(TestCase):
def test_init(self):
r"""
Test the creation... | (2,3)) | self.assertEqual | collection | bayespy/inference/vmp/nodes/tests/test_multinomial.py | test_init | TestMultinomial | 44 | null |
bayespy/bayespy | import unittest
import numpy as np
import scipy
from numpy import testing
from ..node import Node, Moments
from ...vmp import VB
from bayespy.utils import misc
class TestNode(misc.TestCase):
def check_message_to_parent(self, plates_child, plates_message,
plates_mask, plates_pa... | m_true) | assert_* | variable | bayespy/inference/vmp/nodes/tests/test_node.py | check_message_to_parent | TestNode | 173 | null |
bayespy/bayespy | import numpy as np
from .. import misc
from .. import linalg
class TestBandedSolve(misc.TestCase):
def test_block_banded_solve(self):
r"""
Test the Gaussian elimination algorithm for block-banded matrices.
"""
#
# Create a block-banded matrix
#
# Number o... | np.allclose(x_true, x)) | self.assertTrue | func_call | bayespy/utils/tests/test_linalg.py | test_block_banded_solve | TestBandedSolve | 178 | null |
bayespy/bayespy | import unittest
import numpy as np
import scipy
from numpy import testing
from ..dot import Dot, SumMultiply
from ..gaussian import Gaussian, GaussianARD
from bayespy.nodes import GaussianGamma
from ...vmp import VB
from bayespy.utils import misc
from bayespy.utils import linalg
from bayespy.utils import random
f... | np.einsum('mn,ni,nj->ij', -0.5*tau, a, a)) | assert_* | func_call | bayespy/inference/vmp/nodes/tests/test_dot.py | test_message_to_parent | TestSumMultiply | 994 | null |
bayespy/bayespy | import unittest
import numpy as np
import scipy
from numpy import testing
from ..node import Node, Moments
from ...vmp import VB
from bayespy.utils import misc
class TestSlice(misc.TestCase):
def test_init(self):
r"""
Test the constructor of the X[..] node operator.
"""
class... | (4,)) | self.assertEqual | collection | bayespy/inference/vmp/nodes/tests/test_node.py | test_init | TestSlice | 466 | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.