首页 > 其他分享 >Ragas实践问题记录2 AttributeError: ‘TestsetGenerator‘ object has no attribute ‘generate_with_llama_index_d

Ragas实践问题记录2 AttributeError: ‘TestsetGenerator‘ object has no attribute ‘generate_with_llama_index_d

时间:2024-06-18 11:29:59浏览次数:13  
标签:index Ragas generator attribute TestsetGenerator testset llm import generate

报错问题

依然是在尝试官方文档“Compare LLMs using Ragas Evaluations”的“Create synthetic test data”步骤发生报错。官方文档以及文档中代码如下:

Ragas:Compare LLMs using Ragas Evaluations

官方文档中的代码:

import os
from llama_index import download_loader, SimpleDirectoryReader
from ragas.testset import TestsetGenerator
from ragas.testset.generator import TestsetGenerator
from ragas.testset.evolutions import simple, reasoning, multi_context
from langchain_openai import ChatOpenAI, OpenAIEmbeddings

os.environ['OPENAI_API_KEY'] = 'Your OPEN AI key'

# load documents
reader = SimpleDirectoryReader("./arxiv-papers/",num_files_limit=30)
documents = reader.load_data()

# generator with openai models
generator_llm = ChatOpenAI(model="gpt-3.5-turbo-16k")
critic_llm = ChatOpenAI(model="gpt-4")
embeddings = OpenAIEmbeddings()

generator = TestsetGenerator.from_langchain(
    generator_llm,
    critic_llm,
    embeddings
)

distributions = {
    simple: 0.5,
    multi_context: 0.4,
    reasoning: 0.1
}

# generate testset
testset = generator.generate_with_llama_index_docs(documents, 100,distributions)
testset.to_pandas()

接着报错如下:

解决方案

这其实是官方文档中有一处写错了,不应该是“generate_with_llama_index_docs”,而是“generate_with_llamaindex_docs”

修改后代码:

记得把openai api key换成自己的

import os
from llama_index import download_loader, SimpleDirectoryReader
from ragas.testset import TestsetGenerator
from ragas.testset.generator import TestsetGenerator
from ragas.testset.evolutions import simple, reasoning, multi_context
from langchain_openai import ChatOpenAI, OpenAIEmbeddings

os.environ['OPENAI_API_KEY'] = 'Your OPEN AI key'

# load documents
reader = SimpleDirectoryReader("./arxiv-papers/",num_files_limit=30)
documents = reader.load_data()

# generator with openai models
generator_llm = ChatOpenAI(model="gpt-3.5-turbo-16k")
critic_llm = ChatOpenAI(model="gpt-4")
embeddings = OpenAIEmbeddings()

generator = TestsetGenerator.from_langchain(
    generator_llm,
    critic_llm,
    embeddings
)

distributions = {
    simple: 0.5,
    multi_context: 0.4,
    reasoning: 0.1
}

# generate testset
testset = generator.generate_with_llamaindex_docs(documents, 100,distributions)
testset.to_pandas()

就没问题啦

标签:index,Ragas,generator,attribute,TestsetGenerator,testset,llm,import,generate
From: https://blog.csdn.net/z603220/article/details/139767209

相关文章

  • 解决vue项目报错 ERROR in Conflict:Multiple assets emit different content to the
    vue-cli创建项目ERROR in Conflict: Multiple assets emit different content to the same filename index.html问题的解决办法用vue-cli正常来创建新的项目在运行npmrundev或者npmrunserve有以下报错:ERRORinConflict:Multipleassetsemitdifferentco......
  • jar运行报错no main manifest attribute
    在服务器上运行:  java-jartest-0.0.1-SNAPSHOT.jar1报错:nomainmanifestattribute,intest-0.0.1-SNAPSHOT.jar1原因:原因是找不到主类。一般情况下,java打包成jar包需要在MANIFEST.MF中指定Main-Class项,以便运行java-jarxxx.jar时找到对应的主类。将test-0.......
  • Anomaly Detection on Attributed Networks via Contrastive Self-Supervised Learnin
    PaperAnomalyDetectiononAttributedNetworksviaContrastiveSelf-SupervisedLearnin代码实现异常注入inject_anomaly.pyinject_anomaly.py注入异常过程,处理原始数据集,并添加结构和属性扰动,注入结构属性异常。importnumpyasnpimportscipy.sparseasspim......
  • pg_index
    在pg11之后,引入了indnkeyatts字段,根据官方文档解释其作用:Thenumberofkeycolumnsintheindex,notcountinganyincludedcolumns,whicharemerelystoredanddonotparticipateintheindexsemantics。第一感觉,和indnatts字段差不多,但两者的说明存在差异。后者是参......
  • AttributeError: ‘ChatGLMModel‘ object has no attribute ‘prefix_encoder‘
    AttributeError:‘ChatGLMModel‘objecthasnoattribute‘prefix_encoder‘:全面解析问题概述当您使用ChatGLM模型或相关库时遇到AttributeError:‘ChatGLMModel‘objecthasnoattribute‘prefix_encoder‘错误时,这意味着ChatGLMModel类中不存在prefix_encod......
  • python-数据分析-Pandas-5、DataFrame-index
    Index类型,它为Series和DataFrame对象提供了索引服务,有了索引我们就可以排序数据(sort_index方法)、对齐数据(在运算和合并数据时非常重要)并实现对数据的快速检索(索引运算)。由于DataFrame类型表示的是二维数据,所以它的行和列都有索引,分别是index和columns。Index类型的创建的比较简单......
  • 在centos7.9下编译安装nginx1.16.1带fancyindex
    在centos7.9下编译安装nginx1.16.1带fancyindex文章目录前言一、安装环境centos7.9/nginx1.16.1/ngx-fancyindex-0.4.4二、需要达到的效果1.默认效果2.安装主题效果三、nginx编译安装1.安装依赖工具2.创建目录并下载Nginx及其模块3.运行编译与安装4.配置环境变......
  • 解决Docker遇到error NU1301: Unable to load the service index for source https://
    解决Docker容器内无法通过HTTPS访问外部网络的问题在使用Docker构建.NET项目时,有时会遇到无法通过HTTPS访问外部网络的问题,导致dotnetrestore命令无法从NuGet源下载依赖项。本文将介绍一种通过修改Docker配置文件config.json来解决该问题的方法。问题描述在......
  • lightdb hash index的性能和限制
    除了btree外,lightdb是支持hashindex的,但是总体来说支持的特性范围均不如btree索引,比如parallel没有btree索引智能,不支持=之外的操作,不支持bitmapindexscan,不支持哈希唯一索引(但可以通过uniquenotnull约束变量实现)等等,但在内存存储不使用固定长度的场景下还是很有优势的。......
  • msSQL 语句查询时 charindex()方法的妙用
    CHARINDEX(expressionToFind,expressionToSearch[,start_location])参数说明:expressionToFind:必需,要查找的字符串。expressionToSearch:必需,要进行查找的字符串表达式。start_location:可选,指定搜索的起始位置,默认为1。如果指定了起始位置,则从该位置开始搜索。list变......