garak.generators.langchain

LangChain generator support

class LangChainLLMGenerator(name='', config_root=<module 'garak._config' from '/home/docs/checkouts/readthedocs.org/user_builds/garak/checkouts/stable/garak/_config.py'>)Source

Bases: Generator

Class supporting LangChain LLM interfaces

See LangChain’s supported models here,

https://python.langchain.com/docs/integrations/llms/

Calls invoke with the prompt and relays the response. No per-LLM specific checking, so make sure the right environment variables are set.

Set –target_name to the LLM type required.

Explicitly, garak delegates the majority of responsibility here:

  • the generator calls invoke() on the LLM, which seems to be the most widely supported method

  • langchain-relevant environment vars need to be set up there

  • There’s no support for chains, just the langchain LLM interface.

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

  • preset = None

  • frequency_penalty = 0.0

  • presence_penalty = 0.0

  • stop = []

  • model_provider = None

  • configurable_fields = None

Default values are listed

See also Configuring garak for how to set these values.

Other attributes:

extra_dependency_names = ['langchain.chat_models']
generator_family_name = 'LangChain'