llm-wizard commited on
Commit
d1f3dc6
0 Parent(s):

Duplicate from c-s-ale/AliceInWonderLandChainlit

Browse files
.env.example ADDED
@@ -0,0 +1 @@
 
 
1
+ OPENAI_API_KEY=
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ .env
2
+ .vscode
3
+ .chroma
4
+ __pycache__
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+ RUN useradd -m -u 1000 user
3
+ USER user
4
+ ENV HOME=/home/user \
5
+ PATH=/home/user/.local/bin:$PATH
6
+ WORKDIR $HOME/app
7
+ COPY --chown=user . $HOME/app
8
+ COPY ./requirements.txt ~/app/requirements.txt
9
+ RUN pip install -r requirements.txt
10
+ COPY . .
11
+ CMD ["chainlit", "run", "app.py", "--port", "7860"]
README.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: ArxivChainLitDemo
3
+ emoji: 💻
4
+ colorFrom: indigo
5
+ colorTo: gray
6
+ sdk: docker
7
+ pinned: false
8
+ license: openrail
9
+ duplicated_from: c-s-ale/AliceInWonderLandChainlit
10
+ ---
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from langchain.agents import initialize_agent, Tool
3
+ from langchain.embeddings.openai import OpenAIEmbeddings
4
+ from langchain.agents import AgentType
5
+ from langchain.tools import BaseTool
6
+ from langchain.llms import OpenAI
7
+ from langchain import SerpAPIWrapper, LLMChain
8
+ from langchain.chains import RetrievalQA
9
+ from langchain.chat_models import ChatOpenAI
10
+ from langchain.agents import ZeroShotAgent, Tool, AgentExecutor
11
+ from langchain.memory import ConversationBufferMemory, ReadOnlySharedMemory
12
+ from langchain.document_loaders import TextLoader, DirectoryLoader
13
+ from langchain.vectorstores import Chroma
14
+ import os
15
+ import arxiv
16
+ import chainlit as cl
17
+ from chainlit import user_session
18
+
19
+ @cl.langchain_factory(use_async=True)
20
+ async def init():
21
+ # Set the OpenAI Embeddings model
22
+ embeddings = embeddings = OpenAIEmbeddings()
23
+
24
+ # Set the persist directory
25
+ persist_directory = "vector_db"
26
+
27
+ # Load the persisted Chroma vector store
28
+ vectordb = Chroma(persist_directory=persist_directory, embedding_function=embeddings)
29
+
30
+ # Create a chain that uses the Chroma vector store
31
+ alice_qa = RetrievalQA.from_chain_type(
32
+ ChatOpenAI(
33
+ model_name="gpt-3.5-turbo-16k",
34
+ temperature=0,
35
+ ),
36
+ chain_type="stuff",
37
+ retriever=vectordb.as_retriever(),
38
+ )
39
+
40
+ search = SerpAPIWrapper()
41
+
42
+ memory = ConversationBufferMemory(memory_key="chat_history")
43
+ readonlymemory = ReadOnlySharedMemory(memory=memory)
44
+
45
+ tools = [
46
+ Tool(
47
+ name = "Alice in Wonderland QA System",
48
+ func=alice_qa.run,
49
+ description="useful for when you need to answer questions about Alice in Wonderland. Input should be a fully formed question."
50
+ )
51
+ ]
52
+
53
+ prefix = """Have a conversation with a human, answering the following questions as best you can. You have access to the following tools:"""
54
+ suffix = """Begin!"
55
+
56
+ {chat_history}
57
+ Question: {input}
58
+ {agent_scratchpad}"""
59
+
60
+ prompt = ZeroShotAgent.create_prompt(
61
+ tools,
62
+ prefix=prefix,
63
+ suffix=suffix,
64
+ input_variables=["input", "chat_history", "agent_scratchpad"]
65
+ )
66
+
67
+ llm_chain = LLMChain(
68
+ llm=ChatOpenAI(
69
+ model_name="gpt-3.5-turbo-16k",
70
+ temperature=0,
71
+ ),
72
+ prompt=prompt
73
+ )
74
+
75
+ agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools, verbose=True)
76
+ agent_chain = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True, memory=memory)
77
+
78
+ # Let the user know that the system is ready
79
+ await cl.Message(
80
+ content=f"You can begin by asking any questions about Alice in Wonderland!"
81
+ ).send()
82
+
83
+ return agent_chain
84
+
85
+ @cl.langchain_run
86
+ async def run(agent, input_str):
87
+ res = await cl.make_async(agent)(input_str, callbacks=[cl.LangchainCallbackHandler()])
88
+ print(res)
89
+ await cl.Message(content=res["output"]).send()
chainlit.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Down the LangChain Rabbit Hole :rabbit: :clock:!
2
+
3
+ ![image](https://i.imgur.com/L5aklsK.png)
4
+
5
+ Feel free to ask questions about the Alice in Wonderland series by [Lewis Carroll](https://en.wikipedia.org/wiki/Alice%27s_Adventures_in_Wonderland)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ arxiv==1.4.7
2
+ langchain
3
+ chainlit
4
+ openai
5
+ chromadb
6
+ tiktoken
7
+ google-search-results
vector_db/chroma-collections.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dacc35a2bc6103853543323e632f513acf9899848acf03b71e451d2745138842
3
+ size 557
vector_db/chroma-embeddings.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:494201e44259368c11b93d43f1a2673ebb28d32567a27e681206b8101a552545
3
+ size 5300049
vector_db/index/id_to_uuid_d0cf4a6f-27f8-489b-ae73-fac746c9128b.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:923ac0841a588099b308d49d7b5df76e2231555f2c10897d2d511c83a59fd731
3
+ size 20355
vector_db/index/index_d0cf4a6f-27f8-489b-ae73-fac746c9128b.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a097f4871ca53fe0ce45bdad0bf4199bde4c7f203066be5dda1665df38ce0bc5
3
+ size 3983392
vector_db/index/index_metadata_d0cf4a6f-27f8-489b-ae73-fac746c9128b.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e53255fbf25ed70518581988507ffc72bfe8a4f6699d2546c3fbc1a2070ce1df
3
+ size 105
vector_db/index/uuid_to_id_d0cf4a6f-27f8-489b-ae73-fac746c9128b.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b78d6a3e9574ccfa09550c45aa17804d1e0b483ea87b862e0529153a5700718a
3
+ size 23815