OpikBaseModel

class opik.evaluation.models.OpikBaseModel(model_name: str)

Bases: ABC

This class serves as an interface to LLMs.

If you want to implement custom LLM provider in evaluation metrics, you should inherit from this class.

__init__(model_name: str)

Initializes the base model with a given model name.

Parameters:

model_name – The name of the LLM to be used.

abstract generate_string(input: str, **kwargs: Any) str

Simplified interface to generate a string output from the model.

Parameters:
  • input – The input string based on which the model will generate the output.

  • kwargs – Additional arguments that may be used by the model for string generation.

Returns:

The generated string output.

Return type:

str

abstract async agenerate_string(input: str, **kwargs: Any) str

Simplified interface to generate a string output from the model. Async version.

Parameters:
  • input – The input string based on which the model will generate the output.

  • kwargs – Additional arguments that may be used by the model for string generation.

Returns:

The generated string output.

Return type:

str

abstract generate_provider_response(**kwargs: Any) Any

Generate a provider-specific response. Can be used to interface with the underlying model provider (e.g., OpenAI, Anthropic) and get raw output.

Parameters:

kwargs – arguments required by the provider to generate a response.

Returns:

The response from the model provider, which can be of any type depending on the use case and LLM model.

Return type:

Any

abstract async agenerate_provider_response(**kwargs: Any) Any

Generate a provider-specific response. Can be used to interface with the underlying model provider (e.g., OpenAI, Anthropic) and get raw output. Async version.

Parameters:

kwargs – arguments required by the provider to generate a response.

Returns:

The response from the model provider, which can be of any type depending on the use case and LLM model.

Return type:

Any