-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Add support for ConversationalRetrievalChain): (#37)
- Loading branch information
Showing
5 changed files
with
58 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ | |
"examples.ex10_cc:chain", | ||
"examples.ex12:run", | ||
"examples.ex13:chain", | ||
"examples.ex14:chain", | ||
) |
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,26 @@ | ||
from langchain.chains import ConversationalRetrievalChain | ||
from langchain.chat_models import ChatOpenAI | ||
from langchain.document_loaders import TextLoader | ||
from langchain.embeddings.fake import FakeEmbeddings | ||
from langchain.embeddings.openai import OpenAIEmbeddings | ||
from langchain.llms import OpenAI | ||
from langchain.text_splitter import CharacterTextSplitter | ||
from langchain.vectorstores import Chroma | ||
|
||
loader = TextLoader("Readme.md") | ||
documents = loader.load() | ||
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0) | ||
texts = text_splitter.split_documents(documents) | ||
|
||
embeddings = FakeEmbeddings(size=1504) | ||
docsearch = Chroma.from_documents(texts, embeddings) | ||
|
||
chain = ConversationalRetrievalChain.from_llm( | ||
llm=ChatOpenAI(model="gpt-3.5-turbo"), | ||
retriever=docsearch.as_retriever(search_kwargs={"k": 1}), | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
# Run the chain only specifying the input variable. | ||
print(chain.run(question="colorful socks", chat_history=[])) |
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
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
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
17f804e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
langcorn – ./
langcorn.vercel.app
langcorn-msoedov.vercel.app
langcorn-git-main-msoedov.vercel.app