There is my code snippet
import os,openaifrom langchain.document_loaders import YoutubeLoaderfrom langchain.embeddings.openai import OpenAIEmbeddingsfrom langchain.vectorstores import Chromafrom langchain.text_splitter import RecursiveCharacterTextSplitterfrom langchain.chains import ChatVectorDBChain,ConversationalRetrievalChainfrom langchain.chat_models import ChatOpenAIfrom langchain.prompts.chat import ( ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate)os.environ["OPENAI_API_KEY"] = "apikey"loader = YoutubeLoader.from_youtube_url(youtube_url="https://www.youtube.com/watch?v=7OPg-ksxZ4Y",add_video_info=True)documents = loader.load()text_splitter = RecursiveCharacterTextSplitter( chunk_size = 300, chunk_overlap = 20)documents = text_splitter.split_documents(documents)#print(documents)embeddings = OpenAIEmbeddings()vector_store = Chroma.from_documents(documents=documents,embedding=embeddings)retriever = vector_store.as_retriever()system_template = """Use the following context to answer the user's question.If you don't know the answer, say you don't, don't try to make it up. And answer in Chinese.-----------{context}-----------{chat_history}"""messages =[ SystemMessagePromptTemplate.from_template(system_template), HumanMessagePromptTemplate.from_template('{question}')]prompt = ChatPromptTemplate.from_messages(messages)qa = ConversationalRetrievalChain.from_llm(ChatOpenAI(temperature=0.1,max_tokens=2048),retriever,qa_prompt=prompt)chat_history = []while True: question = input('问题:') result = qa({'question':question,'chat_history':chat_history}) chat_history.append((question,result['answer'])) print(result['answer'])
and there is the detail of the error
PS C:\Users\12875\Desktop\新建文件夹> & E:/Program/python/python.exe c:/Users/12875/Desktop/新建文件夹/分析youtube视频.pyUsing embedded DuckDB without persistence: data will be transientTraceback (most recent call last): File "c:\Users\12875\Desktop\新建文件夹\分析youtube视频.py", line 30, in <module> vector_store = Chroma.from_documents(documents=documents,embedding=embeddings) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\Program\python\Lib\site-packages\langchain\vectorstores\chroma.py", line 412, in from_documents return cls.from_texts( ^^^^^^^^^^^^^^^ File "E:\Program\python\Lib\site-packages\langchain\vectorstores\chroma.py", line 380, in from_texts chroma_collection.add_texts(texts=texts, metadatas=metadatas, ids=ids) File "E:\Program\python\Lib\site-packages\langchain\vectorstores\chroma.py", line 159, in add_texts self._collection.add( File "E:\Program\python\Lib\site-packages\chromadb\api\models\Collection.py", line 84, in add metadatas = validate_metadatas(maybe_cast_one_to_many(metadatas)) if metadatas else None ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\Program\python\Lib\site-packages\chromadb\api\types.py", line 107, in validate_metadatas validate_metadata(metadata) File "E:\Program\python\Lib\site-packages\chromadb\api\types.py", line 98, in validate_metadata raise ValueError(f"Expected metadata value to be a str, int, or float, got {value}")ValueError: Expected metadata value to be a str, int, or float, got None
The class YoutubeLoader recently updated one of the methods from from_youtube_channel to from_youtube_url.But when i use the from_youtube_url,i happened the error that "ValueError: Expected metadata value to be a str, int, or float, got None".I want to know what should I do,thank you!