garak.generators.cohere
Cohere AI model support
Support for Cohere’s text generation API. Uses the command model by default, but just supply the name of another either on the command line or as the constructor param if you want to use that. You’ll need to set an environment variable called COHERE_API_KEY to your Cohere API key, for this generator.
NOTE: As of Cohere v5.0.0+, the generate API is legacy and chat API is recommended. This implementation follows Cohere’s official migration guide:
For v1 API: Uses cohere.Client() to maintain full backward compatibility
For v2 API: Uses cohere.ClientV2() for the recommended chat interface
- class CohereGenerator(name='command', config_root=<module 'garak._config' from '/home/docs/checkouts/readthedocs.org/user_builds/garak/checkouts/stable/garak/_config.py'>)Source
Bases:
GeneratorInterface to Cohere’s python library for their text2text model.
Expects API key in COHERE_API_KEY environment variable.
Following Cohere’s migration guide, this implementation: - For api_version=”v1”: Uses cohere.Client() with generate() API (supports multiple generations) - For api_version=”v2”: Uses cohere.ClientV2() with chat() API (recommended, requires multiple API calls)
Configurable parameters:
DEFAULT_PARAMScontents:max_tokens=150temperature=0.75top_k=Nonecontext_len=Noneskip_seq_start=Noneskip_seq_end=Nonek=0p=0.75frequency_penalty=0.0presence_penalty=0.0stop=[]preset=Noneapi_version='v2'
Default values are listed
See also Configuring garak for how to set these values.
Other attributes:
- ENV_VAR = 'COHERE_API_KEY'
- extra_dependency_names = ['cohere']
- generator_family_name = 'Cohere'