速率限制¶
Ragas利用Python中的异步并行性,但RunConfig
中有一个名为max_workers
的字段,用于控制允许同时发出的请求数量。您可以调整此值,以获得您的服务提供商所允许的最大并发性。
In [1]:
Copied!
from ragas.run_config import RunConfig
# 将max_workers增加到64,并将超时时间设置为60秒
my_run_config = RunConfig(max_workers=64, timeout=60)
from ragas.run_config import RunConfig
# 将max_workers增加到64,并将超时时间设置为60秒
my_run_config = RunConfig(max_workers=64, timeout=60)
评估¶
In [ ]:
Copied!
from ragas import EvaluationDataset, SingleTurnSample
from ragas.metrics import Faithfulness
from datasets import load_dataset
from ragas import evaluate
dataset = load_dataset("explodinggradients/amnesty_qa", "english_v3")
samples = []
for row in dataset["eval"]:
sample = SingleTurnSample(
user_input=row["user_input"],
reference=row["reference"],
response=row["response"],
retrieved_contexts=row["retrieved_contexts"],
)
samples.append(sample)
eval_dataset = EvaluationDataset(samples=samples)
metric = Faithfulness()
_ = evaluate(
dataset=eval_dataset,
metrics=[metric],
run_config=my_run_config,
)
from ragas import EvaluationDataset, SingleTurnSample
from ragas.metrics import Faithfulness
from datasets import load_dataset
from ragas import evaluate
dataset = load_dataset("explodinggradients/amnesty_qa", "english_v3")
samples = []
for row in dataset["eval"]:
sample = SingleTurnSample(
user_input=row["user_input"],
reference=row["reference"],
response=row["response"],
retrieved_contexts=row["retrieved_contexts"],
)
samples.append(sample)
eval_dataset = EvaluationDataset(samples=samples)
metric = Faithfulness()
_ = evaluate(
dataset=eval_dataset,
metrics=[metric],
run_config=my_run_config,
)