Skip to content

error: non-openai llm model has no attribute 'validate_api_key'Β #348

Closed
@arm-diaz

Description

@arm-diaz

Describe the bug

An error is raised when evaluating Langchain QA Chains with a non-openai llm model.

Ragas version: 0.0.21
Python version: 3.10.0

Code to Reproduce

# list of metrics we're going to use
metrics = [
    faithfulness,
    answer_relevancy,
    context_precision,
    context_recall,
]

for m in metrics:
    m.__setattr__("llm", bedrock_llm)

faithfulness_chain = RagasEvaluatorChain(metric=metrics[0])

Error trace

AttributeError                            Traceback (most recent call last)
Cell In[25], line 24
     21     m.__setattr__("llm", llm)
     23 # create evaluation chains
---> 24 faithfulness_chain = RagasEvaluatorChain(metric=metrics[0])
     25 answer_relevancy_chain = RagasEvaluatorChain(metric=metrics[1])
     26 context_precision_chain = RagasEvaluatorChain(metric=metrics[2])

File ~/anaconda3/envs/python3/lib/python3.10/site-packages/ragas/langchain/evalchain.py:29, in RagasEvaluatorChain.__init__(self, **kwargs)
     27 def __init__(self, **kwargs: t.Any):
     28     super().__init__(**kwargs)
---> 29     self.metric.init_model()

File ~/anaconda3/envs/python3/lib/python3.10/site-packages/ragas/metrics/base.py:121, in MetricWithLLM.init_model(self)
    115 def init_model(self):
    116     """
    117     Init any models in the metric, this is invoked before evaluate()
    118     to load all the models
    119     Also check if the api key is valid for OpenAI and AzureOpenAI
    120     """
--> 121     self.llm.validate_api_key()
    122     if hasattr(self, "embeddings"):
    123         # since we are using Langchain Embeddings directly, we need to check this
    124         if hasattr(self.embeddings, "validate_api_key"):

AttributeError: 'BedrockChat' object has no attribute 'validate_api_key'

Expected behavior
It should not raise an error because models from Amazon do not need an api key and the validate_api_key does not exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions