LLMs
BaseRagasLLM
dataclass
BaseRagasLLM(run_config: RunConfig = RunConfig(), multiple_completion_supported: bool = False, cache: Optional[CacheInterface] = None)
Bases: ABC
get_temperature
is_finished
abstractmethod
generate
async
generate(prompt: PromptValue, n: int = 1, temperature: Optional[float] = 0.01, stop: Optional[List[str]] = None, callbacks: Callbacks = None) -> LLMResult
Generate text using the given event loop.
Source code in src/ragas/llms/base.py
InstructorBaseRagasLLM
Bases: ABC
Base class for LLMs using the Instructor library pattern.
generate
abstractmethod
Generate a response using the configured LLM.
For async clients, this will run the async method in the appropriate event loop.
Source code in src/ragas/llms/base.py
agenerate
abstractmethod
async
Asynchronously generate a response using the configured LLM.
InstructorLLM
Bases: InstructorBaseRagasLLM
LLM wrapper using the Instructor library for structured outputs.
Source code in src/ragas/llms/base.py
generate
Generate a response using the configured LLM.
For async clients, this will run the async method in the appropriate event loop.
Source code in src/ragas/llms/base.py
agenerate
async
Asynchronously generate a response using the configured LLM.
Source code in src/ragas/llms/base.py
HaystackLLMWrapper
HaystackLLMWrapper(haystack_generator: Any, run_config: Optional[RunConfig] = None, cache: Optional[CacheInterface] = None)
Bases: BaseRagasLLM
A wrapper class for using Haystack LLM generators within the Ragas framework.
This class integrates Haystack's LLM components (e.g., OpenAIGenerator,
HuggingFaceAPIGenerator, etc.) into Ragas, enabling both synchronous and
asynchronous text generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
haystack_generator
|
AzureOpenAIGenerator | HuggingFaceAPIGenerator | HuggingFaceLocalGenerator | OpenAIGenerator
|
An instance of a Haystack generator. |
required |
run_config
|
RunConfig
|
Configuration object to manage LLM execution settings, by default None. |
None
|
cache
|
CacheInterface
|
A cache instance for storing results, by default None. |
None
|
Source code in src/ragas/llms/haystack_wrapper.py
OCIGenAIWrapper
OCIGenAIWrapper(model_id: str, compartment_id: str, config: Optional[Dict[str, Any]] = None, endpoint_id: Optional[str] = None, run_config: Optional[RunConfig] = None, cache: Optional[Any] = None, default_system_prompt: Optional[str] = None, client: Optional[Any] = None)
Bases: BaseRagasLLM
OCI Gen AI LLM wrapper for Ragas.
This wrapper provides direct integration with Oracle Cloud Infrastructure Generative AI services without requiring LangChain or LlamaIndex.
Args: model_id: The OCI model ID to use for generation compartment_id: The OCI compartment ID config: OCI configuration dictionary (optional, uses default if not provided) endpoint_id: Optional endpoint ID for the model run_config: Ragas run configuration cache: Optional cache backend
Source code in src/ragas/llms/oci_genai_wrapper.py
generate_text
generate_text(prompt: PromptValue, n: int = 1, temperature: Optional[float] = 0.01, stop: Optional[List[str]] = None, callbacks: Optional[Any] = None) -> LLMResult
Generate text using OCI Gen AI.
Source code in src/ragas/llms/oci_genai_wrapper.py
agenerate_text
async
agenerate_text(prompt: PromptValue, n: int = 1, temperature: Optional[float] = 0.01, stop: Optional[List[str]] = None, callbacks: Optional[Any] = None) -> LLMResult
Generate text asynchronously using OCI Gen AI.
Source code in src/ragas/llms/oci_genai_wrapper.py
is_finished
Check if the LLM response is finished/complete.
Source code in src/ragas/llms/oci_genai_wrapper.py
instructor_llm_factory
instructor_llm_factory(provider: str, model: Optional[str] = None, client: Optional[Any] = None, **kwargs: Any) -> InstructorBaseRagasLLM
Factory function to create an InstructorLLM instance based on the provider.
Args: provider (str): The name of the LLM provider or provider/model string (e.g., "openai", "openai/gpt-4"). model (str, optional): The model name to use for generation. client (Any, optional): Pre-initialized client for the provider. **kwargs: Additional arguments for the LLM (model_args).
Returns: InstructorBaseRagasLLM: An instance of the specified LLM provider.
Examples: # OpenAI with separate parameters llm = instructor_llm_factory("openai", "gpt-4", client=openai_client)
# OpenAI with provider/model string
llm = instructor_llm_factory("openai/gpt-4", client=openai_client)
# Anthropic
llm = instructor_llm_factory("anthropic", "claude-3-sonnet-20240229", client=anthropic_client)
# Cohere
llm = instructor_llm_factory("cohere", "command-r-plus", client=cohere_client)
# Google
llm = instructor_llm_factory(provider="google", model="gemini-2.0-flash", client=google_client)
# LiteLLM (supports 100+ models)
llm = instructor_llm_factory("litellm", "gpt-4", client=litellm_client)
Raises: ValueError: If provider is unsupported or required parameters are missing.
Source code in src/ragas/llms/base.py
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 | |
llm_factory
llm_factory(model: str = 'gpt-4o-mini', run_config: Optional[RunConfig] = None, default_headers: Optional[Dict[str, str]] = None, base_url: Optional[str] = None) -> BaseRagasLLM
Create and return a BaseRagasLLM instance. Used for running default LLMs used in Ragas (OpenAI).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The name of the model to use, by default "gpt-4o-mini". |
'gpt-4o-mini'
|
run_config
|
RunConfig
|
Configuration for the run, by default None. |
None
|
default_headers
|
dict of str
|
Default headers to be used in API requests, by default None. |
None
|
base_url
|
str
|
Base URL for the API, by default None. |
None
|
Returns:
| Type | Description |
|---|---|
BaseRagasLLM
|
An instance of BaseRagasLLM configured with the specified parameters. |
Source code in src/ragas/llms/base.py
oci_genai_factory
oci_genai_factory(model_id: str, compartment_id: str, config: Optional[Dict[str, Any]] = None, endpoint_id: Optional[str] = None, run_config: Optional[RunConfig] = None, cache: Optional[Any] = None, default_system_prompt: Optional[str] = None, client: Optional[Any] = None) -> OCIGenAIWrapper
Factory function to create an OCI Gen AI LLM instance.
Args: model_id: The OCI model ID to use for generation compartment_id: The OCI compartment ID config: OCI configuration dictionary (optional) endpoint_id: Optional endpoint ID for the model run_config: Ragas run configuration **kwargs: Additional arguments passed to OCIGenAIWrapper
Returns: OCIGenAIWrapper: An instance of the OCI Gen AI LLM wrapper
Examples: # Basic usage with default config llm = oci_genai_factory( model_id="cohere.command", compartment_id="ocid1.compartment.oc1..example" )
# With custom config
llm = oci_genai_factory(
model_id="cohere.command",
compartment_id="ocid1.compartment.oc1..example",
config={"user": "user_ocid", "key_file": "~/.oci/private_key.pem"}
)