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: Generator

Interface 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_PARAMS contents:

  • max_tokens = 150

  • temperature = 0.75

  • top_k = None

  • context_len = None

  • skip_seq_start = None

  • skip_seq_end = None

  • k = 0

  • p = 0.75

  • frequency_penalty = 0.0

  • presence_penalty = 0.0

  • stop = []

  • preset = None

  • api_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'