-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+58.4 KB
tutorial25/rag_retrieval_generation-1046a4668d6bb08786ef73c56d4f228a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from langchain.document_loaders import AsyncChromiumLoader | ||
from langchain.document_transformers import Html2TextTransformer | ||
from langchain.text_splitter import RecursiveCharacterTextSplitter | ||
from langchain.vectorstores import Chroma | ||
from langchain.embeddings import OpenAIEmbeddings | ||
from langchain.chat_models import ChatOpenAI | ||
from langchain.chains import RetrievalQA | ||
|
||
urls=["https://www.espncricinfo.com/series/afghanistan-in-india-2023-24-1389384/india-vs-afghanistan-3rd-t20i-1389398/full-scorecard"] | ||
loader=AsyncChromiumLoader(urls=urls) | ||
htmldocs=loader.load() | ||
tf=Html2TextTransformer() | ||
fd=tf.transform_documents(htmldocs) | ||
ts=RecursiveCharacterTextSplitter(chunk_size=1000,chunk_overlap=0) | ||
splits=ts.split_documents(fd) | ||
llm=ChatOpenAI(model="gpt-4",temperature=0.8) | ||
embeddings=OpenAIEmbeddings() | ||
chroma_db=Chroma.from_documents( | ||
documents=splits, | ||
embedding=embeddings | ||
) | ||
query="Rinku Singh scores on the match between india vs afghanistan" | ||
chain=RetrievalQA.from_chain_type( | ||
llm=llm, | ||
chain_type="stuff", | ||
retriever=chroma_db.as_retriever() | ||
) | ||
response=chain(query) | ||
print(response) | ||
|
||
|
Binary file not shown.