Spaces:
Sleeping
Sleeping
Commit
·
0f9e6dd
1
Parent(s):
08c0336
first without pdf,db
Browse files- .chainlit/config.toml +84 -0
- .chainlit/translations/en-US.json +231 -0
- Dockerfile +21 -0
- Qdrant_create.ipynb +165 -0
- Qdrant_db/.lock +1 -0
- Qdrant_db/collection/Meta info 400/seed.txt +1 -0
- Qdrant_db/meta.json +1 -0
- Qdrant_loader.ipynb +296 -0
- app_one.py +74 -0
- chainlit.md +2 -0
.chainlit/config.toml
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[project]
|
2 |
+
# Whether to enable telemetry (default: true). No personal data is collected.
|
3 |
+
enable_telemetry = true
|
4 |
+
|
5 |
+
# List of environment variables to be provided by each user to use the app.
|
6 |
+
user_env = []
|
7 |
+
|
8 |
+
# Duration (in seconds) during which the session is saved when the connection is lost
|
9 |
+
session_timeout = 3600
|
10 |
+
|
11 |
+
# Enable third parties caching (e.g LangChain cache)
|
12 |
+
cache = false
|
13 |
+
|
14 |
+
# Follow symlink for asset mount (see https://github.com/Chainlit/chainlit/issues/317)
|
15 |
+
# follow_symlink = false
|
16 |
+
|
17 |
+
[features]
|
18 |
+
# Show the prompt playground
|
19 |
+
prompt_playground = true
|
20 |
+
|
21 |
+
# Process and display HTML in messages. This can be a security risk (see https://stackoverflow.com/questions/19603097/why-is-it-dangerous-to-render-user-generated-html-or-javascript)
|
22 |
+
unsafe_allow_html = false
|
23 |
+
|
24 |
+
# Process and display mathematical expressions. This can clash with "$" characters in messages.
|
25 |
+
latex = false
|
26 |
+
|
27 |
+
# Authorize users to upload files with messages
|
28 |
+
multi_modal = true
|
29 |
+
|
30 |
+
# Allows user to use speech to text
|
31 |
+
[features.speech_to_text]
|
32 |
+
enabled = false
|
33 |
+
# See all languages here https://github.com/JamesBrill/react-speech-recognition/blob/HEAD/docs/API.md#language-string
|
34 |
+
# language = "en-US"
|
35 |
+
|
36 |
+
[UI]
|
37 |
+
# Name of the app and chatbot.
|
38 |
+
name = "Chatbot"
|
39 |
+
|
40 |
+
# Show the readme while the conversation is empty.
|
41 |
+
show_readme_as_default = true
|
42 |
+
|
43 |
+
# Description of the app and chatbot. This is used for HTML tags.
|
44 |
+
# description = ""
|
45 |
+
|
46 |
+
# Large size content are by default collapsed for a cleaner ui
|
47 |
+
default_collapse_content = true
|
48 |
+
|
49 |
+
# The default value for the expand messages settings.
|
50 |
+
default_expand_messages = false
|
51 |
+
|
52 |
+
# Hide the chain of thought details from the user in the UI.
|
53 |
+
hide_cot = false
|
54 |
+
|
55 |
+
# Link to your github repo. This will add a github button in the UI's header.
|
56 |
+
# github = ""
|
57 |
+
|
58 |
+
# Specify a CSS file that can be used to customize the user interface.
|
59 |
+
# The CSS file can be served from the public directory or via an external link.
|
60 |
+
# custom_css = "/public/test.css"
|
61 |
+
|
62 |
+
# Override default MUI light theme. (Check theme.ts)
|
63 |
+
[UI.theme.light]
|
64 |
+
background = "#AAAAFF"
|
65 |
+
paper = "AAAAFA"
|
66 |
+
|
67 |
+
[UI.theme.light.primary]
|
68 |
+
#main = "#F80061"
|
69 |
+
#dark = "#980039"
|
70 |
+
#light = "#FFE7EB"
|
71 |
+
|
72 |
+
# Override default MUI dark theme. (Check theme.ts)
|
73 |
+
[UI.theme.dark]
|
74 |
+
#background = "#FAFAFA"
|
75 |
+
#paper = "#FFFFFF"
|
76 |
+
|
77 |
+
[UI.theme.dark.primary]
|
78 |
+
#main = "#F80061"
|
79 |
+
#dark = "#980039"
|
80 |
+
#light = "#FFE7EB"
|
81 |
+
|
82 |
+
|
83 |
+
[meta]
|
84 |
+
generated_by = "0.7.700"
|
.chainlit/translations/en-US.json
ADDED
@@ -0,0 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"components": {
|
3 |
+
"atoms": {
|
4 |
+
"buttons": {
|
5 |
+
"userButton": {
|
6 |
+
"menu": {
|
7 |
+
"settings": "Settings",
|
8 |
+
"settingsKey": "S",
|
9 |
+
"APIKeys": "API Keys",
|
10 |
+
"logout": "Logout"
|
11 |
+
}
|
12 |
+
}
|
13 |
+
}
|
14 |
+
},
|
15 |
+
"molecules": {
|
16 |
+
"newChatButton": {
|
17 |
+
"newChat": "New Chat"
|
18 |
+
},
|
19 |
+
"tasklist": {
|
20 |
+
"TaskList": {
|
21 |
+
"title": "\ud83d\uddd2\ufe0f Task List",
|
22 |
+
"loading": "Loading...",
|
23 |
+
"error": "An error occured"
|
24 |
+
}
|
25 |
+
},
|
26 |
+
"attachments": {
|
27 |
+
"cancelUpload": "Cancel upload",
|
28 |
+
"removeAttachment": "Remove attachment"
|
29 |
+
},
|
30 |
+
"newChatDialog": {
|
31 |
+
"createNewChat": "Create new chat?",
|
32 |
+
"clearChat": "This will clear the current messages and start a new chat.",
|
33 |
+
"cancel": "Cancel",
|
34 |
+
"confirm": "Confirm"
|
35 |
+
},
|
36 |
+
"settingsModal": {
|
37 |
+
"settings": "Settings",
|
38 |
+
"expandMessages": "Expand Messages",
|
39 |
+
"hideChainOfThought": "Hide Chain of Thought",
|
40 |
+
"darkMode": "Dark Mode"
|
41 |
+
},
|
42 |
+
"detailsButton": {
|
43 |
+
"using": "Using",
|
44 |
+
"running": "Running",
|
45 |
+
"took_one": "Took {{count}} step",
|
46 |
+
"took_other": "Took {{count}} steps"
|
47 |
+
},
|
48 |
+
"auth": {
|
49 |
+
"authLogin": {
|
50 |
+
"title": "Login to access the app.",
|
51 |
+
"form": {
|
52 |
+
"email": "Email address",
|
53 |
+
"password": "Password",
|
54 |
+
"noAccount": "Don't have an account?",
|
55 |
+
"alreadyHaveAccount": "Already have an account?",
|
56 |
+
"signup": "Sign Up",
|
57 |
+
"signin": "Sign In",
|
58 |
+
"or": "OR",
|
59 |
+
"continue": "Continue",
|
60 |
+
"forgotPassword": "Forgot password?",
|
61 |
+
"passwordMustContain": "Your password must contain:",
|
62 |
+
"emailRequired": "email is a required field",
|
63 |
+
"passwordRequired": "password is a required field"
|
64 |
+
},
|
65 |
+
"error": {
|
66 |
+
"default": "Unable to sign in.",
|
67 |
+
"signin": "Try signing in with a different account.",
|
68 |
+
"oauthsignin": "Try signing in with a different account.",
|
69 |
+
"redirect_uri_mismatch": "The redirect URI is not matching the oauth app configuration.",
|
70 |
+
"oauthcallbackerror": "Try signing in with a different account.",
|
71 |
+
"oauthcreateaccount": "Try signing in with a different account.",
|
72 |
+
"emailcreateaccount": "Try signing in with a different account.",
|
73 |
+
"callback": "Try signing in with a different account.",
|
74 |
+
"oauthaccountnotlinked": "To confirm your identity, sign in with the same account you used originally.",
|
75 |
+
"emailsignin": "The e-mail could not be sent.",
|
76 |
+
"emailverify": "Please verify your email, a new email has been sent.",
|
77 |
+
"credentialssignin": "Sign in failed. Check the details you provided are correct.",
|
78 |
+
"sessionrequired": "Please sign in to access this page."
|
79 |
+
}
|
80 |
+
},
|
81 |
+
"authVerifyEmail": {
|
82 |
+
"almostThere": "You're almost there! We've sent an email to ",
|
83 |
+
"verifyEmailLink": "Please click on the link in that email to complete your signup.",
|
84 |
+
"didNotReceive": "Can't find the email?",
|
85 |
+
"resendEmail": "Resend email",
|
86 |
+
"goBack": "Go Back",
|
87 |
+
"emailSent": "Email sent successfully.",
|
88 |
+
"verifyEmail": "Verify your email address"
|
89 |
+
},
|
90 |
+
"providerButton": {
|
91 |
+
"continue": "Continue with {{provider}}",
|
92 |
+
"signup": "Sign up with {{provider}}"
|
93 |
+
},
|
94 |
+
"authResetPassword": {
|
95 |
+
"newPasswordRequired": "New password is a required field",
|
96 |
+
"passwordsMustMatch": "Passwords must match",
|
97 |
+
"confirmPasswordRequired": "Confirm password is a required field",
|
98 |
+
"newPassword": "New password",
|
99 |
+
"confirmPassword": "Confirm password",
|
100 |
+
"resetPassword": "Reset Password"
|
101 |
+
},
|
102 |
+
"authForgotPassword": {
|
103 |
+
"email": "Email address",
|
104 |
+
"emailRequired": "email is a required field",
|
105 |
+
"emailSent": "Please check the email address {{email}} for instructions to reset your password.",
|
106 |
+
"enterEmail": "Enter your email address and we will send you instructions to reset your password.",
|
107 |
+
"resendEmail": "Resend email",
|
108 |
+
"continue": "Continue",
|
109 |
+
"goBack": "Go Back"
|
110 |
+
}
|
111 |
+
}
|
112 |
+
},
|
113 |
+
"organisms": {
|
114 |
+
"chat": {
|
115 |
+
"history": {
|
116 |
+
"index": {
|
117 |
+
"showHistory": "Show history",
|
118 |
+
"lastInputs": "Last Inputs",
|
119 |
+
"noInputs": "Such empty...",
|
120 |
+
"loading": "Loading..."
|
121 |
+
}
|
122 |
+
},
|
123 |
+
"inputBox": {
|
124 |
+
"input": {
|
125 |
+
"placeholder": "Type your message here..."
|
126 |
+
},
|
127 |
+
"speechButton": {
|
128 |
+
"start": "Start recording",
|
129 |
+
"stop": "Stop recording"
|
130 |
+
},
|
131 |
+
"SubmitButton": {
|
132 |
+
"sendMessage": "Send message",
|
133 |
+
"stopTask": "Stop Task"
|
134 |
+
},
|
135 |
+
"UploadButton": {
|
136 |
+
"attachFiles": "Attach files"
|
137 |
+
},
|
138 |
+
"waterMark": {
|
139 |
+
"text": "Built with"
|
140 |
+
}
|
141 |
+
},
|
142 |
+
"Messages": {
|
143 |
+
"index": {
|
144 |
+
"running": "Running",
|
145 |
+
"executedSuccessfully": "executed successfully",
|
146 |
+
"failed": "failed",
|
147 |
+
"feedbackUpdated": "Feedback updated",
|
148 |
+
"updating": "Updating"
|
149 |
+
}
|
150 |
+
},
|
151 |
+
"dropScreen": {
|
152 |
+
"dropYourFilesHere": "Drop your files here"
|
153 |
+
},
|
154 |
+
"index": {
|
155 |
+
"failedToUpload": "Failed to upload",
|
156 |
+
"cancelledUploadOf": "Cancelled upload of",
|
157 |
+
"couldNotReachServer": "Could not reach the server",
|
158 |
+
"continuingChat": "Continuing previous chat"
|
159 |
+
},
|
160 |
+
"settings": {
|
161 |
+
"settingsPanel": "Settings panel",
|
162 |
+
"reset": "Reset",
|
163 |
+
"cancel": "Cancel",
|
164 |
+
"confirm": "Confirm"
|
165 |
+
}
|
166 |
+
},
|
167 |
+
"threadHistory": {
|
168 |
+
"sidebar": {
|
169 |
+
"filters": {
|
170 |
+
"FeedbackSelect": {
|
171 |
+
"feedbackAll": "Feedback: All",
|
172 |
+
"feedbackPositive": "Feedback: Positive",
|
173 |
+
"feedbackNegative": "Feedback: Negative"
|
174 |
+
},
|
175 |
+
"SearchBar": {
|
176 |
+
"search": "Search"
|
177 |
+
}
|
178 |
+
},
|
179 |
+
"DeleteThreadButton": {
|
180 |
+
"confirmMessage": "This will delete the thread as well as it's messages and elements.",
|
181 |
+
"cancel": "Cancel",
|
182 |
+
"confirm": "Confirm",
|
183 |
+
"deletingChat": "Deleting chat",
|
184 |
+
"chatDeleted": "Chat deleted"
|
185 |
+
},
|
186 |
+
"index": {
|
187 |
+
"pastChats": "Past Chats"
|
188 |
+
},
|
189 |
+
"ThreadList": {
|
190 |
+
"empty": "Empty...",
|
191 |
+
"today": "Today",
|
192 |
+
"yesterday": "Yesterday",
|
193 |
+
"previous7days": "Previous 7 days",
|
194 |
+
"previous30days": "Previous 30 days"
|
195 |
+
},
|
196 |
+
"TriggerButton": {
|
197 |
+
"closeSidebar": "Close sidebar",
|
198 |
+
"openSidebar": "Open sidebar"
|
199 |
+
}
|
200 |
+
},
|
201 |
+
"Thread": {
|
202 |
+
"backToChat": "Go back to chat",
|
203 |
+
"chatCreatedOn": "This chat was created on"
|
204 |
+
}
|
205 |
+
},
|
206 |
+
"header": {
|
207 |
+
"chat": "Chat",
|
208 |
+
"readme": "Readme"
|
209 |
+
}
|
210 |
+
}
|
211 |
+
},
|
212 |
+
"hooks": {
|
213 |
+
"useLLMProviders": {
|
214 |
+
"failedToFetchProviders": "Failed to fetch providers:"
|
215 |
+
}
|
216 |
+
},
|
217 |
+
"pages": {
|
218 |
+
"Design": {},
|
219 |
+
"Env": {
|
220 |
+
"savedSuccessfully": "Saved successfully",
|
221 |
+
"requiredApiKeys": "Required API Keys",
|
222 |
+
"requiredApiKeysInfo": "To use this app, the following API keys are required. The keys are stored on your device's local storage."
|
223 |
+
},
|
224 |
+
"Page": {
|
225 |
+
"notPartOfProject": "You are not part of this project."
|
226 |
+
},
|
227 |
+
"ResumeButton": {
|
228 |
+
"resumeChat": "Resume Chat"
|
229 |
+
}
|
230 |
+
}
|
231 |
+
}
|
Dockerfile
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
RUN pip install chainlit==0.7.700
|
11 |
+
RUN pip install python-dotenv==1.0.0
|
12 |
+
RUN pip install qdrant-client
|
13 |
+
RUN pip install langchain
|
14 |
+
RUN pip install langchain-community
|
15 |
+
RUN pip install langchain-openai
|
16 |
+
COPY . .
|
17 |
+
|
18 |
+
RUN chown -R user:user $HOME/app/Qdrant_db
|
19 |
+
USER user
|
20 |
+
|
21 |
+
CMD ["chainlit", "run", "app_one.py", "--port", "7860"]
|
Qdrant_create.ipynb
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"Note: you may need to restart the kernel to use updated packages.\n"
|
13 |
+
]
|
14 |
+
}
|
15 |
+
],
|
16 |
+
"source": [
|
17 |
+
"%pip install -qU qdrant-client"
|
18 |
+
]
|
19 |
+
},
|
20 |
+
{
|
21 |
+
"cell_type": "code",
|
22 |
+
"execution_count": 3,
|
23 |
+
"metadata": {},
|
24 |
+
"outputs": [
|
25 |
+
{
|
26 |
+
"name": "stdout",
|
27 |
+
"output_type": "stream",
|
28 |
+
"text": [
|
29 |
+
"Note: you may need to restart the kernel to use updated packages.\n"
|
30 |
+
]
|
31 |
+
}
|
32 |
+
],
|
33 |
+
"source": [
|
34 |
+
"%pip install -qU langchain langchain-core langchain-community langchain-openai"
|
35 |
+
]
|
36 |
+
},
|
37 |
+
{
|
38 |
+
"cell_type": "code",
|
39 |
+
"execution_count": 5,
|
40 |
+
"metadata": {},
|
41 |
+
"outputs": [
|
42 |
+
{
|
43 |
+
"name": "stdout",
|
44 |
+
"output_type": "stream",
|
45 |
+
"text": [
|
46 |
+
"Note: you may need to restart the kernel to use updated packages.\n"
|
47 |
+
]
|
48 |
+
}
|
49 |
+
],
|
50 |
+
"source": [
|
51 |
+
"%pip install -qU tiktoken pymupdf"
|
52 |
+
]
|
53 |
+
},
|
54 |
+
{
|
55 |
+
"cell_type": "code",
|
56 |
+
"execution_count": 6,
|
57 |
+
"metadata": {},
|
58 |
+
"outputs": [],
|
59 |
+
"source": [
|
60 |
+
"from langchain.document_loaders import PyMuPDFLoader\n",
|
61 |
+
"\n",
|
62 |
+
"docs = PyMuPDFLoader(\"Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf\").load()"
|
63 |
+
]
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"cell_type": "code",
|
67 |
+
"execution_count": 7,
|
68 |
+
"metadata": {},
|
69 |
+
"outputs": [],
|
70 |
+
"source": [
|
71 |
+
"from langchain.text_splitter import RecursiveCharacterTextSplitter"
|
72 |
+
]
|
73 |
+
},
|
74 |
+
{
|
75 |
+
"cell_type": "code",
|
76 |
+
"execution_count": 9,
|
77 |
+
"metadata": {},
|
78 |
+
"outputs": [],
|
79 |
+
"source": [
|
80 |
+
"text_splitter = RecursiveCharacterTextSplitter(\n",
|
81 |
+
" chunk_size = 400,\n",
|
82 |
+
" chunk_overlap = 10,\n",
|
83 |
+
" length_function = len,\n",
|
84 |
+
")\n",
|
85 |
+
"\n",
|
86 |
+
"split_chunks = text_splitter.split_documents(docs)"
|
87 |
+
]
|
88 |
+
},
|
89 |
+
{
|
90 |
+
"cell_type": "code",
|
91 |
+
"execution_count": 5,
|
92 |
+
"metadata": {},
|
93 |
+
"outputs": [
|
94 |
+
{
|
95 |
+
"data": {
|
96 |
+
"text/plain": [
|
97 |
+
"1671"
|
98 |
+
]
|
99 |
+
},
|
100 |
+
"execution_count": 5,
|
101 |
+
"metadata": {},
|
102 |
+
"output_type": "execute_result"
|
103 |
+
}
|
104 |
+
],
|
105 |
+
"source": [
|
106 |
+
"len(split_chunks)"
|
107 |
+
]
|
108 |
+
},
|
109 |
+
{
|
110 |
+
"cell_type": "code",
|
111 |
+
"execution_count": 6,
|
112 |
+
"metadata": {},
|
113 |
+
"outputs": [],
|
114 |
+
"source": [
|
115 |
+
"from langchain_openai.embeddings import OpenAIEmbeddings\n",
|
116 |
+
"\n",
|
117 |
+
"embedding_model = OpenAIEmbeddings(model=\"text-embedding-3-small\")"
|
118 |
+
]
|
119 |
+
},
|
120 |
+
{
|
121 |
+
"cell_type": "code",
|
122 |
+
"execution_count": 10,
|
123 |
+
"metadata": {},
|
124 |
+
"outputs": [],
|
125 |
+
"source": [
|
126 |
+
"from langchain_community.vectorstores import Qdrant\n",
|
127 |
+
"\n",
|
128 |
+
"qdrant_vectorstore = Qdrant.from_documents(\n",
|
129 |
+
" split_chunks,\n",
|
130 |
+
" embedding_model,\n",
|
131 |
+
" path=\"Qdrant_db\",\n",
|
132 |
+
" collection_name=\"Meta info 400\",\n",
|
133 |
+
")"
|
134 |
+
]
|
135 |
+
},
|
136 |
+
{
|
137 |
+
"cell_type": "code",
|
138 |
+
"execution_count": null,
|
139 |
+
"metadata": {},
|
140 |
+
"outputs": [],
|
141 |
+
"source": []
|
142 |
+
}
|
143 |
+
],
|
144 |
+
"metadata": {
|
145 |
+
"kernelspec": {
|
146 |
+
"display_name": "Doc-Expert",
|
147 |
+
"language": "python",
|
148 |
+
"name": "python3"
|
149 |
+
},
|
150 |
+
"language_info": {
|
151 |
+
"codemirror_mode": {
|
152 |
+
"name": "ipython",
|
153 |
+
"version": 3
|
154 |
+
},
|
155 |
+
"file_extension": ".py",
|
156 |
+
"mimetype": "text/x-python",
|
157 |
+
"name": "python",
|
158 |
+
"nbconvert_exporter": "python",
|
159 |
+
"pygments_lexer": "ipython3",
|
160 |
+
"version": "3.9.19"
|
161 |
+
}
|
162 |
+
},
|
163 |
+
"nbformat": 4,
|
164 |
+
"nbformat_minor": 2
|
165 |
+
}
|
Qdrant_db/.lock
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
tmp lock file
|
Qdrant_db/collection/Meta info 400/seed.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
non empty folder
|
Qdrant_db/meta.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"collections": {"Meta info 400": {"vectors": {"size": 1536, "distance": "Cosine", "hnsw_config": null, "quantization_config": null, "on_disk": null, "datatype": null}, "shard_number": null, "sharding_method": null, "replication_factor": null, "write_consistency_factor": null, "on_disk_payload": null, "hnsw_config": null, "wal_config": null, "optimizers_config": null, "init_from": null, "quantization_config": null, "sparse_vectors": null}}, "aliases": {}}
|
Qdrant_loader.ipynb
ADDED
@@ -0,0 +1,296 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": []
|
9 |
+
},
|
10 |
+
{
|
11 |
+
"cell_type": "code",
|
12 |
+
"execution_count": 1,
|
13 |
+
"metadata": {},
|
14 |
+
"outputs": [],
|
15 |
+
"source": [
|
16 |
+
"from langchain_community.vectorstores import Qdrant"
|
17 |
+
]
|
18 |
+
},
|
19 |
+
{
|
20 |
+
"cell_type": "code",
|
21 |
+
"execution_count": 2,
|
22 |
+
"metadata": {},
|
23 |
+
"outputs": [],
|
24 |
+
"source": [
|
25 |
+
"from qdrant_client import QdrantClient, models\n",
|
26 |
+
"\n",
|
27 |
+
"client = QdrantClient(path=\"Qdrant_db\")"
|
28 |
+
]
|
29 |
+
},
|
30 |
+
{
|
31 |
+
"cell_type": "code",
|
32 |
+
"execution_count": 3,
|
33 |
+
"metadata": {},
|
34 |
+
"outputs": [],
|
35 |
+
"source": [
|
36 |
+
"from langchain_openai.embeddings import OpenAIEmbeddings\n",
|
37 |
+
"\n",
|
38 |
+
"embedding_model = OpenAIEmbeddings(model=\"text-embedding-3-small\")"
|
39 |
+
]
|
40 |
+
},
|
41 |
+
{
|
42 |
+
"cell_type": "code",
|
43 |
+
"execution_count": 7,
|
44 |
+
"metadata": {},
|
45 |
+
"outputs": [],
|
46 |
+
"source": [
|
47 |
+
"collection_name = \"Meta info 400\"\n",
|
48 |
+
"qdrant = Qdrant(client, collection_name, embedding_model)"
|
49 |
+
]
|
50 |
+
},
|
51 |
+
{
|
52 |
+
"cell_type": "code",
|
53 |
+
"execution_count": 8,
|
54 |
+
"metadata": {},
|
55 |
+
"outputs": [],
|
56 |
+
"source": [
|
57 |
+
"qdrant_retriever = qdrant.as_retriever()"
|
58 |
+
]
|
59 |
+
},
|
60 |
+
{
|
61 |
+
"cell_type": "code",
|
62 |
+
"execution_count": 9,
|
63 |
+
"metadata": {},
|
64 |
+
"outputs": [
|
65 |
+
{
|
66 |
+
"data": {
|
67 |
+
"text/plain": [
|
68 |
+
"[Document(page_content='these risks and uncertainties, readers are cautioned not to place undue reliance on such forward‑looking statements.\\nUnless expressly indicated or the context requires otherwise, the terms \"Meta,\" \"company,\" \"we,\" \"us,\" and \"our\" in this document refer to Meta', metadata={'source': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'file_path': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'page': 3, 'total_pages': 147, 'format': 'PDF 1.4', 'title': '0001326801-24-000012', 'author': 'EDGAR® Online LLC, a subsidiary of OTC Markets Group', 'subject': 'Form 10-K filed on 2024-02-02 for the period ending 2023-12-31', 'keywords': '0001326801-24-000012; ; 10-K', 'creator': 'EDGAR Filing HTML Converter', 'producer': 'EDGRpdf Service w/ EO.Pdf 22.0.40.0', 'creationDate': \"D:20240202060356-05'00'\", 'modDate': \"D:20240202060413-05'00'\", 'trapped': '', 'encryption': 'Standard V2 R3 128-bit RC4', '_id': '77ee8ea68d4940c7a649688a4b4dc095', '_collection_name': 'Meta info 400'}),\n",
|
69 |
+
" Document(page_content='Table of Contents\\nItem 1B. Unresolved Staff Comments\\nNone.\\nItem 1C. Cybersecurity\\nAt Meta, cybersecurity risk management is an important part of our overall risk management efforts. Our industry is prone to cybersecurity threats and\\nattacks, and we regularly experience cybersecurity incidents of varying degrees. We believe we are a particularly attractive target as a result of our prominence', metadata={'source': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'file_path': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'page': 51, 'total_pages': 147, 'format': 'PDF 1.4', 'title': '0001326801-24-000012', 'author': 'EDGAR® Online LLC, a subsidiary of OTC Markets Group', 'subject': 'Form 10-K filed on 2024-02-02 for the period ending 2023-12-31', 'keywords': '0001326801-24-000012; ; 10-K', 'creator': 'EDGAR Filing HTML Converter', 'producer': 'EDGRpdf Service w/ EO.Pdf 22.0.40.0', 'creationDate': \"D:20240202060356-05'00'\", 'modDate': \"D:20240202060413-05'00'\", 'trapped': '', 'encryption': 'Standard V2 R3 128-bit RC4', '_id': '1e13afafca6c4cdeb2815c2b168a290c', '_collection_name': 'Meta info 400'}),\n",
|
70 |
+
" Document(page_content='EXHIBIT\\xa032.1\\nCERTIFICATION PURSUANT TO\\n18 U.S.C. SECTION\\xa01350\\nAS ADOPTED PURSUANT TO SECTION\\xa0906\\nOF THE SARBANES-OXLEY ACT OF 2002\\nI, Mark Zuckerberg, Board Chair and Chief Executive Officer of Meta Platforms,\\xa0Inc. (Company), do hereby certify, pursuant to 18 U.S.C. Section\\xa01350, as\\nadopted pursuant to Section\\xa0906 of the Sarbanes-Oxley Act of 2002, that to the best of my knowledge:\\n•', metadata={'source': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'file_path': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'page': 141, 'total_pages': 147, 'format': 'PDF 1.4', 'title': '0001326801-24-000012', 'author': 'EDGAR® Online LLC, a subsidiary of OTC Markets Group', 'subject': 'Form 10-K filed on 2024-02-02 for the period ending 2023-12-31', 'keywords': '0001326801-24-000012; ; 10-K', 'creator': 'EDGAR Filing HTML Converter', 'producer': 'EDGRpdf Service w/ EO.Pdf 22.0.40.0', 'creationDate': \"D:20240202060356-05'00'\", 'modDate': \"D:20240202060413-05'00'\", 'trapped': '', 'encryption': 'Standard V2 R3 128-bit RC4', '_id': 'a7443d4d59f84e89a1573e300c05b147', '_collection_name': 'Meta info 400'}),\n",
|
71 |
+
" Document(page_content='We were incorporated in Delaware in July 2004. We completed our initial public offering in May 2012 and our Class\\xa0A common stock is currently listed\\non the Nasdaq Global Select Market under the symbol \"META.\" Our principal executive offices are located at 1 Meta Way, Menlo Park, California 94025, and\\nour telephone number is (650) 543-4800.', metadata={'source': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'file_path': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'page': 13, 'total_pages': 147, 'format': 'PDF 1.4', 'title': '0001326801-24-000012', 'author': 'EDGAR® Online LLC, a subsidiary of OTC Markets Group', 'subject': 'Form 10-K filed on 2024-02-02 for the period ending 2023-12-31', 'keywords': '0001326801-24-000012; ; 10-K', 'creator': 'EDGAR Filing HTML Converter', 'producer': 'EDGRpdf Service w/ EO.Pdf 22.0.40.0', 'creationDate': \"D:20240202060356-05'00'\", 'modDate': \"D:20240202060413-05'00'\", 'trapped': '', 'encryption': 'Standard V2 R3 128-bit RC4', '_id': '74778dd733954d4ea9701cd7726d8968', '_collection_name': 'Meta info 400'})]"
|
72 |
+
]
|
73 |
+
},
|
74 |
+
"execution_count": 9,
|
75 |
+
"metadata": {},
|
76 |
+
"output_type": "execute_result"
|
77 |
+
}
|
78 |
+
],
|
79 |
+
"source": [
|
80 |
+
"query = \"What did the meta president said\"\n",
|
81 |
+
"qdrant_retriever.invoke(query)"
|
82 |
+
]
|
83 |
+
},
|
84 |
+
{
|
85 |
+
"cell_type": "code",
|
86 |
+
"execution_count": 10,
|
87 |
+
"metadata": {},
|
88 |
+
"outputs": [],
|
89 |
+
"source": [
|
90 |
+
"from langchain_openai import ChatOpenAI\n",
|
91 |
+
"\n",
|
92 |
+
"openai_chat_model = ChatOpenAI(model=\"gpt-3.5-turbo\")"
|
93 |
+
]
|
94 |
+
},
|
95 |
+
{
|
96 |
+
"cell_type": "code",
|
97 |
+
"execution_count": 11,
|
98 |
+
"metadata": {},
|
99 |
+
"outputs": [],
|
100 |
+
"source": [
|
101 |
+
"from langchain_core.prompts import ChatPromptTemplate"
|
102 |
+
]
|
103 |
+
},
|
104 |
+
{
|
105 |
+
"cell_type": "code",
|
106 |
+
"execution_count": 126,
|
107 |
+
"metadata": {},
|
108 |
+
"outputs": [],
|
109 |
+
"source": [
|
110 |
+
"system_message = \"You are a helpful assistante, experienced lawyer and an expert reading SECURITIES AND EXCHANGE COMMISSION documents\""
|
111 |
+
]
|
112 |
+
},
|
113 |
+
{
|
114 |
+
"cell_type": "code",
|
115 |
+
"execution_count": 19,
|
116 |
+
"metadata": {},
|
117 |
+
"outputs": [],
|
118 |
+
"source": [
|
119 |
+
"RAG_PROMPT = \"\"\"\n",
|
120 |
+
"\n",
|
121 |
+
"CONTEXT:\n",
|
122 |
+
"{context}\n",
|
123 |
+
"\n",
|
124 |
+
"QUERY:\n",
|
125 |
+
"{question}\n",
|
126 |
+
"\n",
|
127 |
+
"Answer the query above using the context provided. If you don't know the answer responde with: I don't know\n",
|
128 |
+
"\"\"\"\n",
|
129 |
+
"\n",
|
130 |
+
"rag_prompt = ChatPromptTemplate.from_template(RAG_PROMPT)"
|
131 |
+
]
|
132 |
+
},
|
133 |
+
{
|
134 |
+
"cell_type": "code",
|
135 |
+
"execution_count": 13,
|
136 |
+
"metadata": {},
|
137 |
+
"outputs": [],
|
138 |
+
"source": [
|
139 |
+
"from langchain.retrievers import MultiQueryRetriever\n",
|
140 |
+
"\n",
|
141 |
+
"advanced_retriever = MultiQueryRetriever.from_llm(retriever=qdrant_retriever, llm=openai_chat_model)\n"
|
142 |
+
]
|
143 |
+
},
|
144 |
+
{
|
145 |
+
"cell_type": "code",
|
146 |
+
"execution_count": 53,
|
147 |
+
"metadata": {},
|
148 |
+
"outputs": [
|
149 |
+
{
|
150 |
+
"data": {
|
151 |
+
"text/plain": [
|
152 |
+
"ChatPromptTemplate(input_variables=['context', 'question', 'system_message'], messages=[HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['context', 'question', 'system_message'], template=\"\\n\\nSYSTEM:\\n{system_message}\\n\\nCONTEXT:\\n{context}\\n\\nQUERY:\\n{question}\\n\\nAnswer the query above only using the context provided. If you don't know the answer responde with: I don't know\\n\"))])"
|
153 |
+
]
|
154 |
+
},
|
155 |
+
"execution_count": 53,
|
156 |
+
"metadata": {},
|
157 |
+
"output_type": "execute_result"
|
158 |
+
}
|
159 |
+
],
|
160 |
+
"source": [
|
161 |
+
"rag_prompt"
|
162 |
+
]
|
163 |
+
},
|
164 |
+
{
|
165 |
+
"cell_type": "code",
|
166 |
+
"execution_count": 20,
|
167 |
+
"metadata": {},
|
168 |
+
"outputs": [],
|
169 |
+
"source": [
|
170 |
+
"from operator import itemgetter\n",
|
171 |
+
"from langchain.schema.output_parser import StrOutputParser\n",
|
172 |
+
"from langchain.schema.runnable import RunnablePassthrough\n",
|
173 |
+
"\n",
|
174 |
+
"retrieval_augmented_qa_chain = (\n",
|
175 |
+
" # INVOKE CHAIN WITH: {\"question\" : \"<<SOME USER QUESTION>>\"}\n",
|
176 |
+
" # \"question\" : populated by getting the value of the \"question\" key\n",
|
177 |
+
" # \"context\" : populated by getting the value of the \"question\" key and chaining it into the base_retriever\n",
|
178 |
+
" {\"context\": itemgetter(\"question\") | advanced_retriever, \"question\": itemgetter(\"question\")}\n",
|
179 |
+
" # \"context\" : is assigned to a RunnablePassthrough object (will not be called or considered in the next step)\n",
|
180 |
+
" # by getting the value of the \"context\" key from the previous step\n",
|
181 |
+
" | RunnablePassthrough.assign(context=itemgetter(\"context\"))\n",
|
182 |
+
" # \"response\" : the \"context\" and \"question\" values are used to format our prompt object and then piped\n",
|
183 |
+
" # into the LLM and stored in a key called \"response\"\n",
|
184 |
+
" # \"context\" : populated by getting the value of the \"context\" key from the previous step\n",
|
185 |
+
" | {\"response\": rag_prompt | openai_chat_model, \"context\": itemgetter(\"context\")}\n",
|
186 |
+
")"
|
187 |
+
]
|
188 |
+
},
|
189 |
+
{
|
190 |
+
"cell_type": "markdown",
|
191 |
+
"metadata": {},
|
192 |
+
"source": [
|
193 |
+
"\n",
|
194 |
+
"\"What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\"\n",
|
195 |
+
"\n",
|
196 |
+
"\"Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\""
|
197 |
+
]
|
198 |
+
},
|
199 |
+
{
|
200 |
+
"cell_type": "code",
|
201 |
+
"execution_count": 103,
|
202 |
+
"metadata": {},
|
203 |
+
"outputs": [
|
204 |
+
{
|
205 |
+
"data": {
|
206 |
+
"text/plain": [
|
207 |
+
"AIMessage(content=\"I don't know\", response_metadata={'token_usage': {'completion_tokens': 4, 'prompt_tokens': 49, 'total_tokens': 53}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_3b956da36b', 'finish_reason': 'stop', 'logprobs': None}, id='run-6ad6e2e1-23e4-4aa7-a17c-12beea722db8-0')"
|
208 |
+
]
|
209 |
+
},
|
210 |
+
"execution_count": 103,
|
211 |
+
"metadata": {},
|
212 |
+
"output_type": "execute_result"
|
213 |
+
}
|
214 |
+
],
|
215 |
+
"source": [
|
216 |
+
"retr = (rag_prompt | openai_chat_model)\n",
|
217 |
+
"resp = retr.invoke({\"question\" : \"What was the total value \", \"context\": \"sdfsfsdfs\", \"system_message\" : \"dfgdfg\"})\n",
|
218 |
+
"resp"
|
219 |
+
]
|
220 |
+
},
|
221 |
+
{
|
222 |
+
"cell_type": "code",
|
223 |
+
"execution_count": 21,
|
224 |
+
"metadata": {},
|
225 |
+
"outputs": [
|
226 |
+
{
|
227 |
+
"data": {
|
228 |
+
"text/plain": [
|
229 |
+
"'Mark Zuckerberg is the Board Chair and Chief Executive Officer.'"
|
230 |
+
]
|
231 |
+
},
|
232 |
+
"execution_count": 21,
|
233 |
+
"metadata": {},
|
234 |
+
"output_type": "execute_result"
|
235 |
+
}
|
236 |
+
],
|
237 |
+
"source": [
|
238 |
+
"response = retrieval_augmented_qa_chain.invoke({\"question\" : \"Who is the Board Chair and Chief Executive Officer?\"})\n",
|
239 |
+
"response[\"response\"].content"
|
240 |
+
]
|
241 |
+
},
|
242 |
+
{
|
243 |
+
"cell_type": "code",
|
244 |
+
"execution_count": 148,
|
245 |
+
"metadata": {},
|
246 |
+
"outputs": [
|
247 |
+
{
|
248 |
+
"data": {
|
249 |
+
"text/plain": [
|
250 |
+
"{'response': AIMessage(content='Mark Zuckerberg', response_metadata={'token_usage': {'completion_tokens': 2, 'prompt_tokens': 1705, 'total_tokens': 1707}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_3b956da36b', 'finish_reason': 'stop', 'logprobs': None}, id='run-7a0deb8c-4266-486b-964d-1b55397557f1-0'),\n",
|
251 |
+
" 'context': [Document(page_content='/s/ MARK ZUCKERBERG\\nMark Zuckerberg\\nBoard Chair and Chief Executive Officer\\n(Principal Executive Officer)', metadata={'source': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'file_path': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'page': 139, 'total_pages': 147, 'format': 'PDF 1.4', 'title': '0001326801-24-000012', 'author': 'EDGAR® Online LLC, a subsidiary of OTC Markets Group', 'subject': 'Form 10-K filed on 2024-02-02 for the period ending 2023-12-31', 'keywords': '0001326801-24-000012; ; 10-K', 'creator': 'EDGAR Filing HTML Converter', 'producer': 'EDGRpdf Service w/ EO.Pdf 22.0.40.0', 'creationDate': \"D:20240202060356-05'00'\", 'modDate': \"D:20240202060413-05'00'\", 'trapped': '', 'encryption': 'Standard V2 R3 128-bit RC4', '_id': '158c21bab89a4a1daefec736f7a56529', '_collection_name': 'Meta info'}),\n",
|
252 |
+
" Document(page_content='including our founder, Board Chair, and CEO, together hold a majority of the combined voting power of our outstanding capital stock, and therefore are able to', metadata={'source': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'file_path': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'page': 49, 'total_pages': 147, 'format': 'PDF 1.4', 'title': '0001326801-24-000012', 'author': 'EDGAR® Online LLC, a subsidiary of OTC Markets Group', 'subject': 'Form 10-K filed on 2024-02-02 for the period ending 2023-12-31', 'keywords': '0001326801-24-000012; ; 10-K', 'creator': 'EDGAR Filing HTML Converter', 'producer': 'EDGRpdf Service w/ EO.Pdf 22.0.40.0', 'creationDate': \"D:20240202060356-05'00'\", 'modDate': \"D:20240202060413-05'00'\", 'trapped': '', 'encryption': 'Standard V2 R3 128-bit RC4', '_id': '2333d2cb1e694d289b31df16b623076f', '_collection_name': 'Meta info'}),\n",
|
253 |
+
" Document(page_content='position as our CEO and his ability to control the election or, in some cases, the replacement of our directors. In the event of his death, the shares of our capital', metadata={'source': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'file_path': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'page': 38, 'total_pages': 147, 'format': 'PDF 1.4', 'title': '0001326801-24-000012', 'author': 'EDGAR® Online LLC, a subsidiary of OTC Markets Group', 'subject': 'Form 10-K filed on 2024-02-02 for the period ending 2023-12-31', 'keywords': '0001326801-24-000012; ; 10-K', 'creator': 'EDGAR Filing HTML Converter', 'producer': 'EDGRpdf Service w/ EO.Pdf 22.0.40.0', 'creationDate': \"D:20240202060356-05'00'\", 'modDate': \"D:20240202060413-05'00'\", 'trapped': '', 'encryption': 'Standard V2 R3 128-bit RC4', '_id': '39917b8eaae34727a610993fa1bad328', '_collection_name': 'Meta info'}),\n",
|
254 |
+
" Document(page_content='/s/ Sheryl K. Sandberg\\nDirector\\nFebruary 1, 2024\\nSheryl K. Sandberg\\n/s/ Tracey T. Travis\\nDirector\\nFebruary 1, 2024\\nTracey T. Travis\\n/s/ Tony Xu\\nDirector\\nFebruary 1, 2024\\nTony Xu\\n132', metadata={'source': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'file_path': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'page': 132, 'total_pages': 147, 'format': 'PDF 1.4', 'title': '0001326801-24-000012', 'author': 'EDGAR® Online LLC, a subsidiary of OTC Markets Group', 'subject': 'Form 10-K filed on 2024-02-02 for the period ending 2023-12-31', 'keywords': '0001326801-24-000012; ; 10-K', 'creator': 'EDGAR Filing HTML Converter', 'producer': 'EDGRpdf Service w/ EO.Pdf 22.0.40.0', 'creationDate': \"D:20240202060356-05'00'\", 'modDate': \"D:20240202060413-05'00'\", 'trapped': '', 'encryption': 'Standard V2 R3 128-bit RC4', '_id': '2d4262b80e9748a299028faa5cb05970', '_collection_name': 'Meta info'}),\n",
|
255 |
+
" Document(page_content='stockholders may be called only by a majority of our board of directors, the chairman of our board of directors, our chief executive officer or our president.\\n•', metadata={'source': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'file_path': 'Data/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf', 'page': 136, 'total_pages': 147, 'format': 'PDF 1.4', 'title': '0001326801-24-000012', 'author': 'EDGAR® Online LLC, a subsidiary of OTC Markets Group', 'subject': 'Form 10-K filed on 2024-02-02 for the period ending 2023-12-31', 'keywords': '0001326801-24-000012; ; 10-K', 'creator': 'EDGAR Filing HTML Converter', 'producer': 'EDGRpdf Service w/ EO.Pdf 22.0.40.0', 'creationDate': \"D:20240202060356-05'00'\", 'modDate': \"D:20240202060413-05'00'\", 'trapped': '', 'encryption': 'Standard V2 R3 128-bit RC4', '_id': '8188dace3340485e83414a35c710392c', '_collection_name': 'Meta info'})]}"
|
256 |
+
]
|
257 |
+
},
|
258 |
+
"execution_count": 148,
|
259 |
+
"metadata": {},
|
260 |
+
"output_type": "execute_result"
|
261 |
+
}
|
262 |
+
],
|
263 |
+
"source": [
|
264 |
+
"response"
|
265 |
+
]
|
266 |
+
},
|
267 |
+
{
|
268 |
+
"cell_type": "code",
|
269 |
+
"execution_count": null,
|
270 |
+
"metadata": {},
|
271 |
+
"outputs": [],
|
272 |
+
"source": []
|
273 |
+
}
|
274 |
+
],
|
275 |
+
"metadata": {
|
276 |
+
"kernelspec": {
|
277 |
+
"display_name": "Doc-Expert",
|
278 |
+
"language": "python",
|
279 |
+
"name": "python3"
|
280 |
+
},
|
281 |
+
"language_info": {
|
282 |
+
"codemirror_mode": {
|
283 |
+
"name": "ipython",
|
284 |
+
"version": 3
|
285 |
+
},
|
286 |
+
"file_extension": ".py",
|
287 |
+
"mimetype": "text/x-python",
|
288 |
+
"name": "python",
|
289 |
+
"nbconvert_exporter": "python",
|
290 |
+
"pygments_lexer": "ipython3",
|
291 |
+
"version": "3.9.19"
|
292 |
+
}
|
293 |
+
},
|
294 |
+
"nbformat": 4,
|
295 |
+
"nbformat_minor": 2
|
296 |
+
}
|
app_one.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
|
4 |
+
|
5 |
+
#from langchain.chat_models import ChatOpenAI
|
6 |
+
#from langchain_community.chat_models import ChatOpenAI
|
7 |
+
from langchain_openai import ChatOpenAI
|
8 |
+
from langchain.prompts import ChatPromptTemplate
|
9 |
+
from langchain.schema import StrOutputParser
|
10 |
+
from langchain.schema.runnable import Runnable
|
11 |
+
from langchain.schema.runnable.config import RunnableConfig
|
12 |
+
|
13 |
+
from langchain_community.vectorstores import Qdrant
|
14 |
+
from qdrant_client import QdrantClient, models
|
15 |
+
from langchain_openai.embeddings import OpenAIEmbeddings
|
16 |
+
|
17 |
+
from langchain.retrievers import MultiQueryRetriever
|
18 |
+
|
19 |
+
from operator import itemgetter
|
20 |
+
|
21 |
+
import chainlit as cl
|
22 |
+
|
23 |
+
|
24 |
+
model = ChatOpenAI(model="gpt-3.5-turbo", streaming=True)
|
25 |
+
|
26 |
+
|
27 |
+
client = QdrantClient(path="Qdrant_db")
|
28 |
+
embedding_model = OpenAIEmbeddings(model="text-embedding-3-small")
|
29 |
+
|
30 |
+
collection_name = "Meta info 400"
|
31 |
+
qdrant = Qdrant(client, collection_name, embedding_model)
|
32 |
+
|
33 |
+
qdrant_retriever = qdrant.as_retriever()
|
34 |
+
advanced_retriever = MultiQueryRetriever.from_llm(retriever=qdrant_retriever, llm=model)
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
@cl.on_chat_start
|
39 |
+
async def on_chat_start():
|
40 |
+
|
41 |
+
RAG_PROMPT = """
|
42 |
+
|
43 |
+
CONTEXT:
|
44 |
+
{context}
|
45 |
+
|
46 |
+
QUERY:
|
47 |
+
{question}
|
48 |
+
|
49 |
+
Answer the query above using the context provided. If you don't know the answer responde with: I don't know
|
50 |
+
"""
|
51 |
+
|
52 |
+
rag_prompt = ChatPromptTemplate.from_template(RAG_PROMPT)
|
53 |
+
|
54 |
+
runnable = (
|
55 |
+
{"context": itemgetter("question") | advanced_retriever, "question": itemgetter("question")} | rag_prompt | model | StrOutputParser()
|
56 |
+
)
|
57 |
+
|
58 |
+
|
59 |
+
cl.user_session.set("runnable", runnable)
|
60 |
+
|
61 |
+
|
62 |
+
@cl.on_message
|
63 |
+
async def on_message(message: cl.Message):
|
64 |
+
|
65 |
+
runnable = cl.user_session.get("runnable") # type: Runnable
|
66 |
+
msg = cl.Message(content="")
|
67 |
+
|
68 |
+
for chunk in await cl.make_async(runnable.stream)(
|
69 |
+
{"question": message.content},
|
70 |
+
config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]),
|
71 |
+
):
|
72 |
+
await msg.stream_token(chunk)
|
73 |
+
|
74 |
+
await msg.send()
|
chainlit.md
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
# Document Expert
|
2 |
+
### Ask me anything about Meta finance report
|