ragas
ragas copied to clipboard
How do I put ragas outputs into a clean JSON, like the JSON that I can get from the dashboard?
Hi. I want to extract the output results from the Ragas result object on my local machine. How do I do that?
Hi @AmirPoursaberi, you can convert the evaluation result to pandas then can convert them to dict.
from ragas.dataset_schema import EvaluationDataset
from ragas import evaluate
from ragas.dataset_schema import SingleTurnSample
from ragas.metrics import AnswerAccuracy
from langchain_openai import ChatOpenAI
from ragas.llms import LangchainLLMWrapper
sample = SingleTurnSample(
user_input="When was Einstein born?",
response="Albert Einstein was born in 1879.",
reference="Albert Einstein was born in 1879."
)
dataset = EvaluationDataset(samples=[sample])
llm = ChatOpenAI(model="gpt-4o-mini")
evaluator_llm = LangchainLLMWrapper(langchain_llm=llm)
result = evaluate(dataset=dataset, metrics=[AnswerAccuracy(llm=evaluator_llm)])
result.to_pandas().to_dict()
It seems the issue was answered, closing this now.