panda_guard.cli package
Submodules
panda_guard.cli.attack module
- panda_guard.cli.attack.apply_env_vars_to_config(config_dict: Dict[str, Any], model_type: str) Dict[str, Any][source]
Apply environment variables to the config if needed.
- panda_guard.cli.attack.display_judge_results(results)[source]
Display judge evaluation results in a less intrusive format.
- panda_guard.cli.attack.display_token_info(usage, response_time=None)[source]
Display token usage information in a less intrusive format.
- panda_guard.cli.attack.get_package_config_path(model_type: str) Path[source]
Get the path to a default config file within the package.
- panda_guard.cli.attack.is_iterator(obj)[source]
Check if an object is an iterator but not a list or other sequence.
- panda_guard.cli.attack.start(config: str | None = <typer.models.ArgumentInfo object>, attacker: ~pathlib.Path | None = <typer.models.OptionInfo object>, endpoint: ~pathlib.Path | None = <typer.models.OptionInfo object>, model: ~pathlib.Path | None = <typer.models.OptionInfo object>, device: str | None = <typer.models.OptionInfo object>, log_level: str = <typer.models.OptionInfo object>, output: ~pathlib.Path | None = <typer.models.OptionInfo object>, stream: bool = <typer.models.OptionInfo object>, verbose: bool = <typer.models.OptionInfo object>)[source]
Start an interactive attack session using configuration from a YAML file or a predefined model type.
If config is a file path ending with .yaml, it will load configuration from that file. If config is one of ‘openai’, ‘gemini’, or ‘claude’, it will load a default configuration and apply relevant environment variables.
panda_guard.cli.chat module
- panda_guard.cli.chat.apply_env_vars_to_config(config_dict: Dict[str, Any], model_type: str) Dict[str, Any][source]
Apply environment variables to the config if needed.
- panda_guard.cli.chat.display_judge_results(results)[source]
Display judge evaluation results in a less intrusive format.
- panda_guard.cli.chat.display_token_info(usage, response_time=None)[source]
Display token usage information in a less intrusive format.
- panda_guard.cli.chat.get_package_config_path(model_type: str) Path[source]
Get the path to a default config file within the package.
- panda_guard.cli.chat.is_iterator(obj)[source]
Check if an object is an iterator but not a list or other sequence.
- panda_guard.cli.chat.start(config: str | None = <typer.models.ArgumentInfo object>, defense: ~pathlib.Path | None = <typer.models.OptionInfo object>, judge: str | None = <typer.models.OptionInfo object>, endpoint: ~pathlib.Path | None = <typer.models.OptionInfo object>, model: ~pathlib.Path | None = <typer.models.OptionInfo object>, temperature: float | None = <typer.models.OptionInfo object>, device: str | None = <typer.models.OptionInfo object>, log_level: str = <typer.models.OptionInfo object>, output: ~pathlib.Path | None = <typer.models.OptionInfo object>, stream: bool = <typer.models.OptionInfo object>, verbose: bool = <typer.models.OptionInfo object>)[source]
Start an interactive chat session using configuration from a YAML file or a predefined model type.
If config is a file path ending with .yaml, it will load configuration from that file. If config is one of ‘openai’, ‘gemini’, or ‘claude’, it will load a default configuration and apply relevant environment variables.
panda_guard.cli.eval module
- panda_guard.cli.eval.get_package_config_path(model_type: str) Path[source]
Get the path to a default config file within the package.
- panda_guard.cli.eval.is_iterator(obj)[source]
Check if an object is an iterator but not a list or other sequence.
- panda_guard.cli.eval.process_file(json_file, input_dir, output_dir, attacker_config, defender_config, judge_configs, config_dict)[source]
- panda_guard.cli.eval.start(config: str | None = <typer.models.ArgumentInfo object>, input_dir: str = <typer.models.OptionInfo object>, output_dir: str = <typer.models.OptionInfo object>, log_level: str = <typer.models.OptionInfo object>, num_workers: int = <typer.models.OptionInfo object>)[source]
Start an eval using configuration from a YAML file or a predefined model type.
If config is a file path ending with .yaml, it will load configuration from that file. If config is one of ‘openai’, ‘gemini’, or ‘claude’, it will load a default configuration and apply relevant environment variables.
panda_guard.cli.inference module
- panda_guard.cli.inference.apply_env_vars_to_config(config_dict: Dict[str, Any], model_type: str) Dict[str, Any][source]
Apply environment variables to the config if needed.
- panda_guard.cli.inference.display_judge_results(results)[source]
Display judge evaluation results in a less intrusive format.
- panda_guard.cli.inference.display_token_info(usage, response_time=None)[source]
Display token usage information in a less intrusive format.
- panda_guard.cli.inference.get_package_config_path(model_type: str) Path[source]
Get the path to a default config file within the package.
- panda_guard.cli.inference.is_iterator(obj)[source]
Check if an object is an iterator but not a list or other sequence.
- panda_guard.cli.inference.start(config: str | None = <typer.models.ArgumentInfo object>, input_file: str | None = <typer.models.OptionInfo object>, attack: ~pathlib.Path | None = <typer.models.OptionInfo object>, defense: ~pathlib.Path | None = <typer.models.OptionInfo object>, endpoint: ~pathlib.Path | None = <typer.models.OptionInfo object>, model: ~pathlib.Path | None = <typer.models.OptionInfo object>, device: str | None = <typer.models.OptionInfo object>, log_level: str = <typer.models.OptionInfo object>, output_dir: str = <typer.models.OptionInfo object>, verbose: bool = <typer.models.OptionInfo object>)[source]
Start an inference session using configuration from a YAML file or a predefined model type.
If config is a file path ending with .yaml, it will load configuration from that file. If config is one of ‘openai’, ‘gemini’, or ‘claude’, it will load a default configuration and apply relevant environment variables.
panda_guard.cli.main module
panda_guard.cli.serve module
- class panda_guard.cli.serve.ChatCompletionRequest(*, model: str, messages: List[Dict[str, str]], temperature: float | None = 1.0, top_p: float | None = 1.0, n: int | None = 1, stream: bool | None = False, max_tokens: int | None = None, presence_penalty: float | None = 0.0, frequency_penalty: float | None = 0.0, user: str | None = None)[source]
Bases:
BaseModel- frequency_penalty: float | None
- max_tokens: int | None
- messages: List[Dict[str, str]]
- model: str
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- n: int | None
- presence_penalty: float | None
- stream: bool | None
- temperature: float | None
- top_p: float | None
- user: str | None
- class panda_guard.cli.serve.ChatCompletionResponse(*, id: str, object: str = 'chat.completion', created: int, model: str, choices: List[Choice], usage: Dict[str, int])[source]
Bases:
BaseModel- created: int
- id: str
- model: str
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- object: str
- usage: Dict[str, int]
- class panda_guard.cli.serve.Choice(*, index: int, message: Dict[str, str], finish_reason: str)[source]
Bases:
BaseModel- finish_reason: str
- index: int
- message: Dict[str, str]
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class panda_guard.cli.serve.ModelData(*, id: str, object: str = 'model', created: int, owned_by: str = 'panda-guard')[source]
Bases:
BaseModel- created: int
- id: str
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- object: str
- owned_by: str
- class panda_guard.cli.serve.ModelsResponse(*, object: str = 'list', data: List[ModelData])[source]
Bases:
BaseModel- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- object: str
- panda_guard.cli.serve.apply_env_vars_to_config(config_dict: Dict[str, Any], model_type: str) Dict[str, Any][source]
Apply environment variables to the config if needed.
- panda_guard.cli.serve.create_fastapi_app(pipeline_instance)[source]
Create a FastAPI application with OpenAI-compatible endpoints.
- panda_guard.cli.serve.get_package_config_path(model_type: str) Path[source]
Get the path to a default config file within the package.
- panda_guard.cli.serve.start(config: str | None = <typer.models.ArgumentInfo object>, defense: ~pathlib.Path | None = <typer.models.OptionInfo object>, judge: str | None = <typer.models.OptionInfo object>, endpoint: ~pathlib.Path | None = <typer.models.OptionInfo object>, model: ~pathlib.Path | None = <typer.models.OptionInfo object>, temperature: float | None = <typer.models.OptionInfo object>, device: str | None = <typer.models.OptionInfo object>, log_level: str = <typer.models.OptionInfo object>, port: int = <typer.models.OptionInfo object>, host: str = <typer.models.OptionInfo object>, verbose: bool = <typer.models.OptionInfo object>)[source]
Start an API server compatible with OpenAI API format.
Accepts the same configuration options as the chat interface, plus host and port settings.