garak.generators.nim
NVIDIA NIM Microservice LLM Interface
- class NVMultimodal(name='', config_root=<module 'garak._config' from '/home/docs/checkouts/readthedocs.org/user_builds/garak/checkouts/latest/garak/_config.py'>)Source
Bases:
NVOpenAIChatWrapper for text and image / audio to text NVIDIA NIM microservices hosted on build.nvidia.com and self-hosted.
You must set the NIM_API_KEY environment variable even if you connect to a self-hosted NIM.
Expects prompt
Messageobjects to be havetext(required), anddata(optional) in eitherimageoraudioformat.By default the
embed_dataparameter is disabled, message preparation is deferred to OpenAICompatible for multimodal format.When the
embed_dataparameter is enabled, message is sent withroleandcontentwherecontentis structured as text followed by<img>and/or<audio>tags. Refer to https://build.nvidia.com/microsoft/phi-4-multimodal-instruct for an example.To get started with this generator:
Visit https://build.nvidia.com/explore/reasoning and find the LLM you’d like to use.
On the page for the LLM you want to use (such as phi-4-multimodal-instruct), click Get API key above the code snippet.
You might need to create an account if you don’t have one yet. Copy this key.
In your console, set the
NIM_API_KEYvariable to this API key.On Linux, this might look like
export NIM_API_KEY="nvapi-xXxXxXx".Run garak, setting
--target_type 'nim.NVMultimodal'and--target_nameto the name of the model on build.nvidia.com, such as--target_name 'microsoft/phi-4-multimodal-instruct-v0.1'.
Configurable parameters:
DEFAULT_PARAMScontents:max_tokens=150temperature=0.1top_k=0context_len=Noneskip_seq_start=Noneskip_seq_end=Nonetop_p=0.7uri='https://integrate.api.nvidia.com/v1/'frequency_penalty=0.0presence_penalty=0.0seed=Nonestop=['#', ';']suppressed_params={'frequency_penalty', 'stop', 'presence_penalty', 'n'}retry_json=Trueextra_params={}vary_seed_each_call=Truevary_temp_each_call=Truemax_input_len=180000embed_data=False
Default values are listed
See also Configuring garak for how to set these values.
Other attributes:
- class NVOpenAIChat(name='', config_root=<module 'garak._config' from '/home/docs/checkouts/readthedocs.org/user_builds/garak/checkouts/latest/garak/_config.py'>)Source
Bases:
OpenAICompatibleWrapper for NVIDIA NIM microservices hosted on build.nvidia.com and self-hosted.
Connects to the v1/chat/completions endpoint. You must set the NIM_API_KEY environment variable even if you connect to a self-hosted NIM.
To get started with this generator:
Visit https://build.nvidia.com/explore/reasoning and find the LLM you’d like to use.
On the page for the LLM you want to use (such as mixtral-8x7b-instruct), click Get API key above the code snippet.
You might need to create an account if you don’t have one yet. Copy this key.
In your console, set the
NIM_API_KEYvariable to this API key.On Linux, this might look like
export NIM_API_KEY="nvapi-xXxXxXx".Run garak, setting
--target_type 'nim.NVIDIAOpenAIChat'and--target_nameto the name of the model on build.nvidia.com, such as--target_name 'mistralai/mixtral-8x7b-instruct-v0.1'.
Configurable parameters:
DEFAULT_PARAMScontents:max_tokens=150temperature=0.1top_k=0context_len=Noneskip_seq_start=Noneskip_seq_end=Nonetop_p=0.7uri='https://integrate.api.nvidia.com/v1/'frequency_penalty=0.0presence_penalty=0.0seed=Nonestop=['#', ';']suppressed_params={'frequency_penalty', 'presence_penalty', 'timeout', 'n'}retry_json=Trueextra_params={}vary_seed_each_call=Truevary_temp_each_call=True
Default values are listed
See also Configuring garak for how to set these values.
Other attributes:
- ENV_VAR = 'NIM_API_KEY'
- active = True
- generator_family_name = 'NIM'
- supports_multiple_generations = False
- timeout = 60
- class NVOpenAICompletion(name='', config_root=<module 'garak._config' from '/home/docs/checkouts/readthedocs.org/user_builds/garak/checkouts/latest/garak/_config.py'>)Source
Bases:
NVOpenAIChatWrapper for NVIDIA NIM microservices hosted on build.nvidia.com and self-hosted.
Connects to the v1/completions endpoint. You must set the NIM_API_KEY environment variable even if you connect to a self-hosted NIM.
To get started with this generator:
Visit https://build.nvidia.com/explore/reasoning and find the LLM you’d like to use.
On the page for the LLM you want to use (such as mixtral-8x7b-instruct), click Get API key above the code snippet.
You might need to create an account if you don’t have one yet. Copy this key.
In your console, set the
NIM_API_KEYvariable to this API key.On Linux, this might look like
export NIM_API_KEY="nvapi-xXxXxXx".Run garak, setting
--target_type 'nim.NVIDIAOpenAIChat'and--target_nameto the name of the model on build.nvidia.com, such as--target_name 'mistralai/mixtral-8x7b-instruct-v0.1'.
- class Vision(name='', config_root=<module 'garak._config' from '/home/docs/checkouts/readthedocs.org/user_builds/garak/checkouts/latest/garak/_config.py'>)Source
Bases:
NVMultimodalWrapper for text and image to text NVIDIA NIM microservices hosted on build.nvidia.com and self-hosted.
You must set the NIM_API_KEY environment variable even if you connect to a self-hosted NIM.
Following generators.huggingface.LLaVa, expects prompts to be a
Messagewith keystextanddata(optional) inimagemimetype format. Thetextkey specifies the text prompt, and theimagekey specifies the path to the image.