Open SushmitaSingh96 opened 3 months ago
Hey, @SushmitaSingh96! I'm here to help you with bugs, questions, and more while we wait for a human maintainer. Let's tackle this together!
To resolve the ValidationError
when using the evaluate
function from Ragas with the OpenAIEmbeddings
model, ensure that you are passing the correct instances of the embeddings and LLM models. Since you are using the standard OpenAI API and not Azure, you should wrap your OpenAI embeddings and LLM instances with the appropriate wrappers provided by Ragas.
Here is an example of how to do this:
from langchain.embeddings import OpenAIEmbeddings
from langchain.llms import OpenAI
from ragas.llms import LangchainLLMWrapper
from ragas.embeddings import LangchainEmbeddingsWrapper
from ragas.metrics import answer_correctness
from ragas import evaluate
from datasets import Dataset
# Initialize OpenAI embeddings and LLM
openai_embeddings = OpenAIEmbeddings(model="text-embedding-ada-002")
openai_llm = OpenAI(model="text-davinci-003")
# Wrap them with Ragas wrappers
wrapped_embeddings = LangchainEmbeddingsWrapper(openai_embeddings)
wrapped_llm = LangchainLLMWrapper(openai_llm)
# Prepare your data
data_samples = {
'question': ['When was the first super bowl?', 'Who won the most super bowls?'],
'answer': ['The first superbowl was held on Jan 15, 1967', 'The most super bowls have been won by The New England Patriots'],
'ground_truth': ['The first superbowl was held on January 15, 1967', 'The New England Patriots have won the Super Bowl a record six times']
}
dataset = Dataset.from_dict(data_samples)
# Perform evaluation
score = evaluate(dataset, metrics=[answer_correctness], llm=wrapped_llm, embeddings=wrapped_embeddings)
print(score.to_pandas())
This code ensures that the OpenAI embeddings and LLM are correctly wrapped and passed to the evaluate
function, which should resolve the ValidationError
[1][2].
To continue talking to Dosu, mention @dosu.
thanks for reporting this @SushmitaSingh96, seems like the fix you suggested should help but not sure why I don't see it in mine
have you set OPENAI_API_TYPE
in your env ?
A
ValidationError
occurs when trying to use theevaluate
function from Ragas with theOpenAIEmbeddings
model. The error message suggests usingAzureOpenAIEmbeddings
when using Azure, but I am using the standard OpenAI API.To Reproduce
Steps to reproduce the behavior:
Error Message
Expected behavior
The code should execute without errors, generating the evaluation scores and converting them to a pandas DataFrame.
Suggested Workaround
The issue seems to be related to the LangChain framework, and a suggested workaround can be found here.
The code change is:
Environment: