colinrdavisMBA commited on
Commit
4f4295c
Β·
1 Parent(s): e542a5c

initial add

Browse files
.DS_Store ADDED
Binary file (6.15 kB). View file
 
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.faiss filter=lfs diff=lfs merge=lfs -text
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"]
app.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[1]:
5
+
6
+
7
+ #import necessary packages
8
+ import os
9
+ from openai import AsyncOpenAI # importing openai for API usage
10
+ import chainlit as cl # importing chainlit for our app
11
+ from chainlit.playground.providers import ChatOpenAI # importing ChatOpenAI tools
12
+ from langchain_community.vectorstores import FAISS
13
+ from langchain_openai import OpenAIEmbeddings
14
+ from langchain.prompts import ChatPromptTemplate
15
+ from operator import itemgetter
16
+ from langchain_core.runnables import RunnablePassthrough
17
+ from langchain_community.vectorstores import FAISS
18
+ from langchain_openai import ChatOpenAI
19
+ from langchain.retrievers import MultiQueryRetriever
20
+ from langchain.chains.combine_documents import create_stuff_documents_chain
21
+ from langchain.chains import create_retrieval_chain
22
+ from langchain import hub
23
+
24
+
25
+
26
+ #from langchain.utils import itemgetter, RunnablePassthrough
27
+ #from langchain.chains import build_chain
28
+ #from langchain.text_splitter import RecursiveCharacterTextSplitter
29
+ #from langchain_community.document_loaders import PyMuPDFLoader
30
+
31
+
32
+ # In[2]:
33
+
34
+
35
+ #load environment var
36
+ from dotenv import load_dotenv
37
+ load_dotenv()
38
+
39
+
40
+ # In[3]:
41
+
42
+
43
+ #load in embeddings model
44
+ out_fp = './data'
45
+ embeddings = OpenAIEmbeddings(model="text-embedding-3-small")
46
+ #vector_store = FAISS.from_documents(documents, embeddings)
47
+ faiss_fn = 'nvidia_10k_faiss_index.bin'
48
+ vector_store=FAISS.load_local(out_fp+faiss_fn, embeddings, allow_dangerous_deserialization=True)
49
+ retriever = vector_store.as_retriever()
50
+ openai_llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0)
51
+
52
+
53
+ # In[4]:
54
+
55
+
56
+ # ChatOpenAI Templates
57
+ template = """Answer the question based only on the following context. If you cannot answer the question with the context, respond with 'I don't know'. You'll get a big bonus and a potential promotion if you provide a high quality answer:
58
+
59
+ Context:
60
+ {context}
61
+
62
+ Question:
63
+ {question}
64
+ """
65
+ prompt_template = ChatPromptTemplate.from_template(template)
66
+
67
+
68
+ # In[5]:
69
+
70
+
71
+ #create chain
72
+ retrieval_qa_prompt = hub.pull("langchain-ai/retrieval-qa-chat")
73
+ primary_qa_llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0)
74
+ advanced_retriever = MultiQueryRetriever.from_llm(retriever=retriever, llm=primary_qa_llm)
75
+ document_chain = create_stuff_documents_chain(primary_qa_llm, retrieval_qa_prompt)
76
+ retrieval_chain = create_retrieval_chain(advanced_retriever, document_chain)
77
+
78
+
79
+ # In[6]:
80
+
81
+
82
+ @cl.on_chat_start # marks a function that will be executed at the start of a user session
83
+ async def start_chat():
84
+ settings = {
85
+ "model": "gpt-3.5-turbo",
86
+ "temperature": 0,
87
+ "max_tokens": 250,
88
+ "top_p": 1,
89
+ "frequency_penalty": 0,
90
+ "presence_penalty": 0,
91
+ }
92
+
93
+ cl.user_session.set("settings", settings)
94
+
95
+
96
+ # In[8]:
97
+
98
+
99
+ @cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
100
+ async def main(message: cl.Message):
101
+ settings = cl.user_session.get("settings")
102
+
103
+ # Use the retrieval_augmented_qa_chain_openai pipeline with the user's question
104
+ question = message.content # Extracting the question from the message content
105
+ response = retrieval_chain.invoke({"input": question}) # Invoke the pipeline
106
+ #print(response['answer'])
107
+ # Extract the response content and context documents
108
+ response_content = response['answer']
109
+ #context_documents = '\n'.join([document.page_content for document in response["context"]])
110
+ #page_numbers = set([document.metadata['page'] for document in response["context"]])
111
+
112
+ # Stream the response content back to the user
113
+ msg = cl.Message(content="")
114
+ await msg.stream_token(response_content)
115
+
116
+
117
+ # In[ ]:
118
+
119
+
120
+
121
+
chainlit.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Welcome to Chainlit! πŸš€πŸ€–
2
+
3
+ Hi there, Developer! πŸ‘‹ We're excited to have you on board. Chainlit is a powerful tool designed to help you prototype, debug and share applications built on top of LLMs.
4
+
5
+ ## Useful Links πŸ”—
6
+
7
+ - **Documentation:** Get started with our comprehensive [Chainlit Documentation](https://docs.chainlit.io) πŸ“š
8
+ - **Discord Community:** Join our friendly [Chainlit Discord](https://discord.gg/k73SQ3FyUh) to ask questions, share your projects, and connect with other developers! πŸ’¬
9
+
10
+ We can't wait to see what you create with Chainlit! Happy coding! πŸ’»πŸ˜Š
11
+
12
+ ## Welcome screen
13
+
14
+ To modify the welcome screen, edit the `chainlit.md` file at the root of your project. If you do not want a welcome screen, just leave this file empty.
datanvidia_10k_faiss_index.bin/index.faiss ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6b7736d6111b170f0ac1bab605803e524e7a33fbdc123a99fde8366f44b7dfc3
3
+ size 2691117
datanvidia_10k_faiss_index.bin/index.pkl ADDED
Binary file (452 kB). View file
 
gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.faiss filter=lfs diff=lfs merge=lfs -text
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ async-openai
2
+ chainlit
3
+ langchain
4
+ faiss
5
+ langchain-openai
6
+ langchain-community