Spaces:
Runtime error
Runtime error
Moved project from github and created dockerfile
Browse files- .chainlit/config.toml +106 -0
- .chainlit/translations/en-US.json +231 -0
- .gitignore +160 -0
- .pre-commit-config.yaml +27 -0
- .vscode/settings.json +16 -0
- Dockerfile +24 -0
- LICENSE +21 -0
- README.md +53 -11
- app.py +118 -0
- chainlit.md +27 -0
- poetry.lock +0 -0
- prompts.py +15 -0
- pyproject.toml +49 -0
.chainlit/config.toml
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
# Whether to enable telemetry (default: true). No personal data is collected.
|
| 3 |
+
enable_telemetry = true
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# List of environment variables to be provided by each user to use the app.
|
| 7 |
+
user_env = ["OPENAI_API_KEY"]
|
| 8 |
+
|
| 9 |
+
# Duration (in seconds) during which the session is saved when the connection is lost
|
| 10 |
+
session_timeout = 3600
|
| 11 |
+
|
| 12 |
+
# Enable third parties caching (e.g LangChain cache)
|
| 13 |
+
cache = false
|
| 14 |
+
|
| 15 |
+
# Authorized origins
|
| 16 |
+
allow_origins = ["*"]
|
| 17 |
+
|
| 18 |
+
# Follow symlink for asset mount (see https://github.com/Chainlit/chainlit/issues/317)
|
| 19 |
+
# follow_symlink = false
|
| 20 |
+
|
| 21 |
+
[features]
|
| 22 |
+
# Show the prompt playground
|
| 23 |
+
prompt_playground = true
|
| 24 |
+
|
| 25 |
+
# 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)
|
| 26 |
+
unsafe_allow_html = false
|
| 27 |
+
|
| 28 |
+
# Process and display mathematical expressions. This can clash with "$" characters in messages.
|
| 29 |
+
latex = false
|
| 30 |
+
|
| 31 |
+
# Authorize users to upload files with messages
|
| 32 |
+
[features.multi_modal]
|
| 33 |
+
enabled = false
|
| 34 |
+
accept = ["*/*"]
|
| 35 |
+
max_files = 20
|
| 36 |
+
max_size_mb = 500
|
| 37 |
+
|
| 38 |
+
# Allows user to use speech to text
|
| 39 |
+
[features.speech_to_text]
|
| 40 |
+
enabled = true
|
| 41 |
+
# See all languages here https://github.com/JamesBrill/react-speech-recognition/blob/HEAD/docs/API.md#language-string
|
| 42 |
+
# language = "en-US"
|
| 43 |
+
|
| 44 |
+
[UI]
|
| 45 |
+
# Name of the app and chatbot.
|
| 46 |
+
name = "Chatbot"
|
| 47 |
+
|
| 48 |
+
# Show the readme while the thread is empty.
|
| 49 |
+
show_readme_as_default = false
|
| 50 |
+
|
| 51 |
+
# Description of the app and chatbot. This is used for HTML tags.
|
| 52 |
+
# description = ""
|
| 53 |
+
|
| 54 |
+
# Large size content are by default collapsed for a cleaner ui
|
| 55 |
+
default_collapse_content = true
|
| 56 |
+
|
| 57 |
+
# The default value for the expand messages settings.
|
| 58 |
+
default_expand_messages = false
|
| 59 |
+
|
| 60 |
+
# Hide the chain of thought details from the user in the UI.
|
| 61 |
+
hide_cot = false
|
| 62 |
+
|
| 63 |
+
# Link to your github repo. This will add a github button in the UI's header.
|
| 64 |
+
github = "https://github.com/NanthagopalEswaran/ChatBot"
|
| 65 |
+
|
| 66 |
+
# Specify a CSS file that can be used to customize the user interface.
|
| 67 |
+
# The CSS file can be served from the public directory or via an external link.
|
| 68 |
+
# custom_css = "/public/test.css"
|
| 69 |
+
|
| 70 |
+
# Specify a Javascript file that can be used to customize the user interface.
|
| 71 |
+
# The Javascript file can be served from the public directory.
|
| 72 |
+
# custom_js = "/public/test.js"
|
| 73 |
+
|
| 74 |
+
# Specify a custom font url.
|
| 75 |
+
# custom_font = "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap"
|
| 76 |
+
|
| 77 |
+
# Specify a custom build directory for the frontend.
|
| 78 |
+
# This can be used to customize the frontend code.
|
| 79 |
+
# Be careful: If this is a relative path, it should not start with a slash.
|
| 80 |
+
# custom_build = "./public/build"
|
| 81 |
+
|
| 82 |
+
# Override default MUI light theme. (Check theme.ts)
|
| 83 |
+
[UI.theme]
|
| 84 |
+
#font_family = "Inter, sans-serif"
|
| 85 |
+
[UI.theme.light]
|
| 86 |
+
#background = "#FAFAFA"
|
| 87 |
+
#paper = "#FFFFFF"
|
| 88 |
+
|
| 89 |
+
[UI.theme.light.primary]
|
| 90 |
+
#main = "#F80061"
|
| 91 |
+
#dark = "#980039"
|
| 92 |
+
#light = "#FFE7EB"
|
| 93 |
+
|
| 94 |
+
# Override default MUI dark theme. (Check theme.ts)
|
| 95 |
+
[UI.theme.dark]
|
| 96 |
+
#background = "#FAFAFA"
|
| 97 |
+
#paper = "#FFFFFF"
|
| 98 |
+
|
| 99 |
+
[UI.theme.dark.primary]
|
| 100 |
+
#main = "#F80061"
|
| 101 |
+
#dark = "#980039"
|
| 102 |
+
#light = "#FFE7EB"
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
[meta]
|
| 106 |
+
generated_by = "1.0.502"
|
.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 |
+
}
|
.gitignore
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Byte-compiled / optimized / DLL files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
|
| 6 |
+
# C extensions
|
| 7 |
+
*.so
|
| 8 |
+
|
| 9 |
+
# Distribution / packaging
|
| 10 |
+
.Python
|
| 11 |
+
build/
|
| 12 |
+
develop-eggs/
|
| 13 |
+
dist/
|
| 14 |
+
downloads/
|
| 15 |
+
eggs/
|
| 16 |
+
.eggs/
|
| 17 |
+
lib/
|
| 18 |
+
lib64/
|
| 19 |
+
parts/
|
| 20 |
+
sdist/
|
| 21 |
+
var/
|
| 22 |
+
wheels/
|
| 23 |
+
share/python-wheels/
|
| 24 |
+
*.egg-info/
|
| 25 |
+
.installed.cfg
|
| 26 |
+
*.egg
|
| 27 |
+
MANIFEST
|
| 28 |
+
|
| 29 |
+
# PyInstaller
|
| 30 |
+
# Usually these files are written by a python script from a template
|
| 31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 32 |
+
*.manifest
|
| 33 |
+
*.spec
|
| 34 |
+
|
| 35 |
+
# Installer logs
|
| 36 |
+
pip-log.txt
|
| 37 |
+
pip-delete-this-directory.txt
|
| 38 |
+
|
| 39 |
+
# Unit test / coverage reports
|
| 40 |
+
htmlcov/
|
| 41 |
+
.tox/
|
| 42 |
+
.nox/
|
| 43 |
+
.coverage
|
| 44 |
+
.coverage.*
|
| 45 |
+
.cache
|
| 46 |
+
nosetests.xml
|
| 47 |
+
coverage.xml
|
| 48 |
+
*.cover
|
| 49 |
+
*.py,cover
|
| 50 |
+
.hypothesis/
|
| 51 |
+
.pytest_cache/
|
| 52 |
+
cover/
|
| 53 |
+
|
| 54 |
+
# Translations
|
| 55 |
+
*.mo
|
| 56 |
+
*.pot
|
| 57 |
+
|
| 58 |
+
# Django stuff:
|
| 59 |
+
*.log
|
| 60 |
+
local_settings.py
|
| 61 |
+
db.sqlite3
|
| 62 |
+
db.sqlite3-journal
|
| 63 |
+
|
| 64 |
+
# Flask stuff:
|
| 65 |
+
instance/
|
| 66 |
+
.webassets-cache
|
| 67 |
+
|
| 68 |
+
# Scrapy stuff:
|
| 69 |
+
.scrapy
|
| 70 |
+
|
| 71 |
+
# Sphinx documentation
|
| 72 |
+
docs/_build/
|
| 73 |
+
|
| 74 |
+
# PyBuilder
|
| 75 |
+
.pybuilder/
|
| 76 |
+
target/
|
| 77 |
+
|
| 78 |
+
# Jupyter Notebook
|
| 79 |
+
.ipynb_checkpoints
|
| 80 |
+
|
| 81 |
+
# IPython
|
| 82 |
+
profile_default/
|
| 83 |
+
ipython_config.py
|
| 84 |
+
|
| 85 |
+
# pyenv
|
| 86 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 88 |
+
# .python-version
|
| 89 |
+
|
| 90 |
+
# pipenv
|
| 91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 94 |
+
# install all needed dependencies.
|
| 95 |
+
#Pipfile.lock
|
| 96 |
+
|
| 97 |
+
# poetry
|
| 98 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 100 |
+
# commonly ignored for libraries.
|
| 101 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 102 |
+
#poetry.lock
|
| 103 |
+
|
| 104 |
+
# pdm
|
| 105 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 106 |
+
#pdm.lock
|
| 107 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 108 |
+
# in version control.
|
| 109 |
+
# https://pdm.fming.dev/#use-with-ide
|
| 110 |
+
.pdm.toml
|
| 111 |
+
|
| 112 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 113 |
+
__pypackages__/
|
| 114 |
+
|
| 115 |
+
# Celery stuff
|
| 116 |
+
celerybeat-schedule
|
| 117 |
+
celerybeat.pid
|
| 118 |
+
|
| 119 |
+
# SageMath parsed files
|
| 120 |
+
*.sage.py
|
| 121 |
+
|
| 122 |
+
# Environments
|
| 123 |
+
.env
|
| 124 |
+
.venv
|
| 125 |
+
env/
|
| 126 |
+
venv/
|
| 127 |
+
ENV/
|
| 128 |
+
env.bak/
|
| 129 |
+
venv.bak/
|
| 130 |
+
|
| 131 |
+
# Spyder project settings
|
| 132 |
+
.spyderproject
|
| 133 |
+
.spyproject
|
| 134 |
+
|
| 135 |
+
# Rope project settings
|
| 136 |
+
.ropeproject
|
| 137 |
+
|
| 138 |
+
# mkdocs documentation
|
| 139 |
+
/site
|
| 140 |
+
|
| 141 |
+
# mypy
|
| 142 |
+
.mypy_cache/
|
| 143 |
+
.dmypy.json
|
| 144 |
+
dmypy.json
|
| 145 |
+
|
| 146 |
+
# Pyre type checker
|
| 147 |
+
.pyre/
|
| 148 |
+
|
| 149 |
+
# pytype static type analyzer
|
| 150 |
+
.pytype/
|
| 151 |
+
|
| 152 |
+
# Cython debug symbols
|
| 153 |
+
cython_debug/
|
| 154 |
+
|
| 155 |
+
# PyCharm
|
| 156 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 157 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 158 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 159 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 160 |
+
#.idea/
|
.pre-commit-config.yaml
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# See https://pre-commit.com for more information
|
| 2 |
+
# See https://pre-commit.com/hooks.html for more hooks
|
| 3 |
+
|
| 4 |
+
repos:
|
| 5 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
| 6 |
+
rev: v4.6.0
|
| 7 |
+
hooks:
|
| 8 |
+
- id: check-added-large-files
|
| 9 |
+
- id: check-toml
|
| 10 |
+
- id: check-yaml
|
| 11 |
+
args:
|
| 12 |
+
- --unsafe
|
| 13 |
+
- id: end-of-file-fixer
|
| 14 |
+
- id: trailing-whitespace
|
| 15 |
+
- id: detect-private-key
|
| 16 |
+
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
| 17 |
+
rev: v0.3.5
|
| 18 |
+
hooks:
|
| 19 |
+
# Run the linter.
|
| 20 |
+
- id: ruff
|
| 21 |
+
args: [ --fix ]
|
| 22 |
+
# Run the formatter.
|
| 23 |
+
- id: ruff-format
|
| 24 |
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
| 25 |
+
rev: 'v1.9.0' # Use the sha / tag you want to point at
|
| 26 |
+
hooks:
|
| 27 |
+
- id: mypy
|
.vscode/settings.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"[python]": {
|
| 3 |
+
"editor.formatOnSave": true,
|
| 4 |
+
"editor.defaultFormatter": "charliermarsh.ruff",
|
| 5 |
+
"editor.codeActionsOnSave": {
|
| 6 |
+
"source.fixAll": "explicit",
|
| 7 |
+
"source.organizeImports": "explicit"
|
| 8 |
+
}
|
| 9 |
+
},
|
| 10 |
+
"notebook.formatOnSave.enabled": true,
|
| 11 |
+
"notebook.codeActionsOnSave": {
|
| 12 |
+
"notebook.source.fixAll": "explicit",
|
| 13 |
+
"notebook.source.organizeImports": "explicit"
|
| 14 |
+
},
|
| 15 |
+
"editor.rulers": [100]
|
| 16 |
+
}
|
Dockerfile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# you will also find guides on how best to write your Dockerfile
|
| 3 |
+
|
| 4 |
+
FROM python:3.11-buster
|
| 5 |
+
|
| 6 |
+
# Install Poetry package manager
|
| 7 |
+
RUN pip install poetry==1.5.1
|
| 8 |
+
|
| 9 |
+
# Set Poetry environment variables for non-interactive mode, virtual environments in project, auto creation, and cache directory
|
| 10 |
+
ENV POETRY_NO_INTERACTION=1 \
|
| 11 |
+
POETRY_VIRTUALENVS_IN_PROJECT=1 \
|
| 12 |
+
POETRY_VIRTUALENVS_CREATE=1 \
|
| 13 |
+
POETRY_CACHE_DIR=/tmp/poetry_cache
|
| 14 |
+
|
| 15 |
+
COPY pyproject.toml poetry.lock app.py prompts.py chainlit.md ./
|
| 16 |
+
|
| 17 |
+
# Install project dependencies using Poetry
|
| 18 |
+
RUN poetry install --without dev
|
| 19 |
+
|
| 20 |
+
# Define the default command to run the application
|
| 21 |
+
CMD ["chainlit", "run", "app.py", "--port", "7860"]
|
| 22 |
+
|
| 23 |
+
# Expose port 7860 for external access
|
| 24 |
+
EXPOSE 7860
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2024 NanthagopalEswaran
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
README.md
CHANGED
|
@@ -1,11 +1,53 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ๐ค ChatBot
|
| 2 |
+
|
| 3 |
+
This project is a simple ChatBot built using **Chainlit**, a Python library for quickly building chat applications. Chainlit provides a wide range of features that make it easy to develop interactive and engaging chatbots. ๐
|
| 4 |
+
|
| 5 |
+
## ๐ Features
|
| 6 |
+
|
| 7 |
+
- **Easy to use**: Similar interface to ChatGPT. ๐ฎ
|
| 8 |
+
- **Customizable**: You can easily customize the behavior and responses of your ChatBot to suit your specific requirements. ๐ ๏ธ
|
| 9 |
+
- **Models**: Choose models that you want (Only OpenAI models are supported for now) ๐ง
|
| 10 |
+
- **Temperature**: Alter the temperature as per your need and continue the conversation ๐ก๏ธ
|
| 11 |
+
- **Stream Answers**: Control streaming of answers. ๐ก
|
| 12 |
+
- **Chat Window Size**: Control no of chat that you want to use for further communications. This helps staying within the context window of the model ๐ฅ๏ธ
|
| 13 |
+
- **Microphone Support**: ChatBot can use your microphone instead of keyboards for chats. (Permission Required) ๐ค
|
| 14 |
+
- **Multiple Chats**: Multiple Chats in single window is disabled for now since it required to store chats in chainlit account for data persistent. Quick Work Around is to open the chatbot in new tabs. ๐ฌ
|
| 15 |
+
|
| 16 |
+
## ๐ Getting Started
|
| 17 |
+
|
| 18 |
+
To get started with the ChatBot, follow these steps:
|
| 19 |
+
|
| 20 |
+
1. Clone the repository: `git clone https://github.com/NanthagopalEswaran/ChatBot.git` ๐
|
| 21 |
+
2. Install the required dependencies: `poetry install` ๐ฆ
|
| 22 |
+
3. Run the ChatBot application: `poetry run chainlit run app.py`. This will automatically open the chatbot in your default browser. ๐
|
| 23 |
+
|
| 24 |
+
> Default url - [http://localhost:8000/](http://localhost:8000/)
|
| 25 |
+
|
| 26 |
+
## โ๏ธ Usage
|
| 27 |
+
|
| 28 |
+
1. You will be prompted for `OpenAI API Key` for the first time. To use this ChatBot, the above API key is required. The key is stored on your device's local storage. ๐
|
| 29 |
+
2. Select a persona of your choice. ๐ญ
|
| 30 |
+
1. `Factful` - AI will try to stick to facts while giving answers instead of creating an answer on its own. ๐
|
| 31 |
+
> Note: LLMs are not reliable yet. so do not trust the answers from LLM blindly. This option is to instruct LLM to use facts but does not gurentee.
|
| 32 |
+
2. `Creative` - AI will try to generate new ideas and be creative as much as possible in its replies. ๐ก
|
| 33 |
+
3. `Normal` - Some conversations does not need to stick to facts or more creative answers. (Default) ๐ฃ๏ธ
|
| 34 |
+
3. Open Chat Settings and configure settings as per your need. For more information on each settings. refer Feature section above. โ๏ธ
|
| 35 |
+
4. You can use history and microphone features as and when needed. ๐ง
|
| 36 |
+
|
| 37 |
+
<p align="center"><strong><em>Happy chatting!! ๐</em></strong></p>
|
| 38 |
+
|
| 39 |
+
## ๐ค Contributing
|
| 40 |
+
|
| 41 |
+
We welcome contributions from the community!
|
| 42 |
+
|
| 43 |
+
This ChatBot is an example for ChatBots build using Chainlit, Langchain and OpenAI.
|
| 44 |
+
|
| 45 |
+
If you have any ideas, bug reports, or feature requests, please open an issue or submit a pull request.
|
| 46 |
+
|
| 47 |
+
## ๐ License
|
| 48 |
+
|
| 49 |
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.
|
| 50 |
+
|
| 51 |
+
## ๐ Contact
|
| 52 |
+
|
| 53 |
+
If you have any questions or need further assistance, feel free to contact us at nanthagopaleswaran@gmail.com.
|
app.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
|
| 3 |
+
import chainlit as cl
|
| 4 |
+
from chainlit.input_widget import NumberInput, Slider, Switch, TextInput
|
| 5 |
+
from langchain.memory.buffer_window import ConversationBufferWindowMemory
|
| 6 |
+
from langchain_core.messages import HumanMessage, SystemMessage
|
| 7 |
+
from langchain_openai import ChatOpenAI
|
| 8 |
+
|
| 9 |
+
from prompts import CREATIVE_SYSTEM_PROMPT, FACTFUL_SYSTEM_PROMPT, NORMAL_SYSTEM_PROMPT
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@cl.set_chat_profiles
|
| 13 |
+
async def chat_profile():
|
| 14 |
+
return [
|
| 15 |
+
cl.ChatProfile(
|
| 16 |
+
name="Normal",
|
| 17 |
+
markdown_description="Answer should be based on common knowledge",
|
| 18 |
+
),
|
| 19 |
+
cl.ChatProfile(
|
| 20 |
+
name="Factful",
|
| 21 |
+
markdown_description="Answer should be based on facts",
|
| 22 |
+
),
|
| 23 |
+
cl.ChatProfile(
|
| 24 |
+
name="Creative",
|
| 25 |
+
markdown_description="Answer should be creative and imaginative",
|
| 26 |
+
),
|
| 27 |
+
]
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@cl.on_message
|
| 31 |
+
async def main(message: cl.Message):
|
| 32 |
+
system_prompt = cl.user_session.get("system-prompt")
|
| 33 |
+
memory = cl.user_session.get("memory")
|
| 34 |
+
messages: list = memory.load_memory_variables({})["history"]
|
| 35 |
+
messages.insert(0, SystemMessage(content=system_prompt))
|
| 36 |
+
messages.append(HumanMessage(content=message.content))
|
| 37 |
+
|
| 38 |
+
streaming = cl.user_session.get("streaming")
|
| 39 |
+
|
| 40 |
+
settings = {
|
| 41 |
+
"model": cl.user_session.get("model"),
|
| 42 |
+
"temperature": cl.user_session.get("temperature"),
|
| 43 |
+
"streaming": streaming,
|
| 44 |
+
"api_key": cl.user_session.get("api_key"),
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
chat_llm = ChatOpenAI(**settings)
|
| 48 |
+
|
| 49 |
+
bot_response = cl.Message(content="", author="ChatBot")
|
| 50 |
+
|
| 51 |
+
if streaming:
|
| 52 |
+
async for chunk in chat_llm.astream(messages):
|
| 53 |
+
if chunk.content:
|
| 54 |
+
# Stream the output of the step
|
| 55 |
+
await bot_response.stream_token(chunk.content)
|
| 56 |
+
|
| 57 |
+
await bot_response.send()
|
| 58 |
+
else:
|
| 59 |
+
response = await chat_llm.ainvoke(messages)
|
| 60 |
+
bot_response.content = response.content
|
| 61 |
+
await bot_response.send()
|
| 62 |
+
|
| 63 |
+
memory.save_context({"input": message.content}, {"output": bot_response.content})
|
| 64 |
+
cl.user_session.set("memory", memory)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
@cl.on_chat_start
|
| 68 |
+
async def start_chat():
|
| 69 |
+
chat_profile = cl.user_session.get("chat_profile")
|
| 70 |
+
logging.info(f"Starting chat with profile: {chat_profile}")
|
| 71 |
+
if chat_profile == "Factful":
|
| 72 |
+
cl.user_session.set("system-prompt", FACTFUL_SYSTEM_PROMPT)
|
| 73 |
+
elif chat_profile == "Creative":
|
| 74 |
+
cl.user_session.set("system-prompt", CREATIVE_SYSTEM_PROMPT)
|
| 75 |
+
else:
|
| 76 |
+
cl.user_session.set("system-prompt", NORMAL_SYSTEM_PROMPT)
|
| 77 |
+
|
| 78 |
+
await cl.ChatSettings(
|
| 79 |
+
[
|
| 80 |
+
TextInput(
|
| 81 |
+
id="Model",
|
| 82 |
+
label="Model",
|
| 83 |
+
initial="gpt-3.5-turbo-0125",
|
| 84 |
+
),
|
| 85 |
+
Switch(id="Streaming", label="Stream Messages", initial=True),
|
| 86 |
+
Slider(
|
| 87 |
+
id="Temperature",
|
| 88 |
+
label="Temperature",
|
| 89 |
+
initial=1,
|
| 90 |
+
min=0,
|
| 91 |
+
max=2,
|
| 92 |
+
step=0.1,
|
| 93 |
+
),
|
| 94 |
+
NumberInput(
|
| 95 |
+
id="Chat Window Size",
|
| 96 |
+
label="Chat Window Size",
|
| 97 |
+
initial=5,
|
| 98 |
+
description="Chat window size to use for completion",
|
| 99 |
+
),
|
| 100 |
+
]
|
| 101 |
+
).send()
|
| 102 |
+
|
| 103 |
+
api_key = cl.user_session.get("env")["OPENAI_API_KEY"]
|
| 104 |
+
cl.user_session.set("api_key", api_key)
|
| 105 |
+
cl.user_session.set("model", "gpt-3.5-turbo-0125")
|
| 106 |
+
cl.user_session.set("streaming", True)
|
| 107 |
+
cl.user_session.set("temperature", 1)
|
| 108 |
+
cl.user_session.set("chat_count_to_use", 5)
|
| 109 |
+
cl.user_session.set("memory", ConversationBufferWindowMemory(k=5, return_messages=True))
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
@cl.on_settings_update
|
| 113 |
+
async def update_chat_settings(settings):
|
| 114 |
+
cl.user_session.set("model", settings["Model"])
|
| 115 |
+
cl.user_session.set("streaming", settings["Streaming"])
|
| 116 |
+
cl.user_session.set("temperature", settings["Temperature"])
|
| 117 |
+
cl.user_session.set("chat_count_to_use", settings["Chat Window Size"])
|
| 118 |
+
cl.user_session.get("memory").k = settings["Chat Window Size"]
|
chainlit.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ๐ค ChatBot
|
| 2 |
+
|
| 3 |
+
This project is a simple ChatBot built using **Chainlit**, a Python library for quickly building chat applications. Chainlit provides a wide range of features that make it easy to develop interactive and engaging chatbots. ๐
|
| 4 |
+
|
| 5 |
+
## ๐ Features
|
| 6 |
+
|
| 7 |
+
- **Easy to use**: Similar interface to ChatGPT. ๐ฎ
|
| 8 |
+
- **Customizable**: You can easily customize the behavior and responses of your ChatBot to suit your specific requirements. ๐ ๏ธ
|
| 9 |
+
- **Models**: Choose models that you want (Only OpenAI models are supported for now) ๐ง
|
| 10 |
+
- **Temperature**: Alter the temperature as per your need and continue the conversation ๐ก๏ธ
|
| 11 |
+
- **Stream Answers**: Control streaming of answers. ๐ก
|
| 12 |
+
- **Chat Window Size**: Control no of chat that you want to use for further communications. This helps staying within the context window of the model ๐ฅ๏ธ
|
| 13 |
+
- **Microphone Support**: ChatBot can use your microphone instead of keyboards for chats. (Permission Required) ๐ค
|
| 14 |
+
- **Multiple Chats**: Multiple Chats in single window is disabled for now since it required to store chats in chainlit account for data persistent. Quick Work Around is to open the chatbot in new tabs. ๐ฌ
|
| 15 |
+
|
| 16 |
+
## โ๏ธ Usage
|
| 17 |
+
|
| 18 |
+
1. You will be prompted for `OpenAI API Key` for the first time. To use this ChatBot, the above API key is required. The key is stored on your device's local storage. ๐
|
| 19 |
+
2. Select a persona of your choice. ๐ญ
|
| 20 |
+
1. `Factful` - AI will try to stick to facts while giving answers instead of creating an answer on its own. ๐
|
| 21 |
+
> Note: LLMs are not reliable yet. so do not trust the answers from LLM blindly. This option is to instruct LLM to use facts but does not gurentee.
|
| 22 |
+
2. `Creative` - AI will try to generate new ideas and be creative as much as possible in its replies. ๐ก
|
| 23 |
+
3. `Normal` - Some conversations does not need to stick to facts or more creative answers. (Default) ๐ฃ๏ธ
|
| 24 |
+
3. Open Chat Settings and configure settings as per your need. For more information on each settings. refer Feature section above. โ๏ธ
|
| 25 |
+
4. You can use history and microphone features as and when needed. ๐ง
|
| 26 |
+
|
| 27 |
+
**Happy Chatting!!** ๐
|
poetry.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
prompts.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FACTFUL_SYSTEM_PROMPT = """You are a Factful Assistant.
|
| 2 |
+
Your primary role is to provide accurate and factual information to users.
|
| 3 |
+
You rely on verified sources and data to answer questions and avoid speculation or personal interpretation.
|
| 4 |
+
You do not create answers on your own but instead, you use your extensive database and search capabilities to find the most accurate and up-to-date information.
|
| 5 |
+
You can express that you are not sure about an answer or that you need more information to provide a complete response.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
NORMAL_SYSTEM_PROMPT = """You are a Helpful Assistant"""
|
| 9 |
+
|
| 10 |
+
CREATIVE_SYSTEM_PROMPT = """You are a Creative Assistant.
|
| 11 |
+
Your primary role is to provide imaginative and engaging responses to users and make the conversation more enjoyable.
|
| 12 |
+
You are not bound by strict factual accuracy, and you can take creative liberties to make the conversation more interesting.
|
| 13 |
+
You can create fictional scenarios, tell stories, or make jokes to engage users and keep the conversation light-hearted.
|
| 14 |
+
You are encouraged to think outside the box and come up with unique and entertaining responses to user queries.
|
| 15 |
+
"""
|
pyproject.toml
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[tool.poetry]
|
| 2 |
+
name = "chainlit-handson"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = ""
|
| 5 |
+
authors = ["Nanthagopal-Eswaran <nanthagopal.eswaran@solitontech.com>"]
|
| 6 |
+
readme = "README.md"
|
| 7 |
+
|
| 8 |
+
[tool.poetry.dependencies]
|
| 9 |
+
python = ">=3.11,<3.13"
|
| 10 |
+
chainlit = "^1.0.502"
|
| 11 |
+
langchain = "^0.1.14"
|
| 12 |
+
langchain-openai = "^0.1.1"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
[tool.poetry.group.dev.dependencies]
|
| 16 |
+
ruff = "^0.3.5"
|
| 17 |
+
mypy = "^1.9.0"
|
| 18 |
+
pre-commit = "^3.7.0"
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
[tool.ruff]
|
| 22 |
+
# Allow lines to be as long as 100.
|
| 23 |
+
line-length = 100
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
[tool.ruff.lint]
|
| 27 |
+
select = [
|
| 28 |
+
"E", # pycodestyle errors
|
| 29 |
+
"W", # pycodestyle warnings
|
| 30 |
+
"F", # pyflakes
|
| 31 |
+
"B", # flake8-bugbear
|
| 32 |
+
"I", # isort
|
| 33 |
+
"C", # pylint convention
|
| 34 |
+
"A", # flake8-builtins
|
| 35 |
+
"N", # pep8-naming
|
| 36 |
+
"ASYNC", # flake8-async
|
| 37 |
+
"C4", # flake8-comprehensions
|
| 38 |
+
]
|
| 39 |
+
ignore = [
|
| 40 |
+
"E501", # line too long, handled by formatter
|
| 41 |
+
"W191", # indentation contains tabs
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
[tool.ruff.pydocstyle]
|
| 45 |
+
convention = "google"
|
| 46 |
+
|
| 47 |
+
[build-system]
|
| 48 |
+
requires = ["poetry-core"]
|
| 49 |
+
build-backend = "poetry.core.masonry.api"
|