Here is the code
os.environ[“GOOGLE_CSE_ID”] = “cse_id”
os.environ[“GOOGLE_API_KEY”] = “api_key”
search = GoogleSearchAPIWrapper()
llm = ChatOpenAI(temperature=0)
memory = ConversationSummaryBufferMemory(llm=llm, input_key=‘question’, output_key=‘answer’, return_messages=True)
vectorstore = Chroma(embedding_function=OpenAIEmbeddings(), persist_directory=“./chroma_db_ws”)
web_research_retriever = WebResearchRetriever.from_llm(
vectorstore=vectorstore,
llm=llm,
search=search,
)
query = “How to automate the process of web research using a retriever?”
qa_chain = RetrievalQAWithSourcesChain.from_chain_type(llm,retriever=web_research_retriever)
result = qa_chain({“question”: query})