Spaces:
Runtime error
Runtime error
Commit
·
9f99fe2
1
Parent(s):
ff29b62
chore: update
Browse files- .DS_Store +0 -0
- .gitignore +327 -0
- main.py +98 -0
- src/.DS_Store +0 -0
- src/__pycache__/api.cpython-38.pyc +0 -0
- src/agent/__pycache__/__init__.cpython-38.pyc +0 -0
- src/agent/__pycache__/base.cpython-38.pyc +0 -0
- src/agent/__pycache__/utils.cpython-38.pyc +0 -0
- src/agent/base.py +46 -0
- src/agent/tools/__pycache__/__init__.cpython-38.pyc +0 -0
- src/agent/tools/__pycache__/image.cpython-38.pyc +0 -0
- src/agent/tools/__pycache__/reminder.cpython-38.pyc +0 -0
- src/agent/tools/__pycache__/search.cpython-38.pyc +0 -0
- src/agent/tools/text_summary.py +65 -0
- src/api.py +63 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
.gitignore
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Created by https://www.toptal.com/developers/gitignore/api/jupyternotebooks,python,pycharm+all,visualstudiocode,macos
|
| 2 |
+
# Edit at https://www.toptal.com/developers/gitignore?templates=jupyternotebooks,python,pycharm+all,visualstudiocode,macos
|
| 3 |
+
|
| 4 |
+
### JupyterNotebooks ###
|
| 5 |
+
# gitignore template for Jupyter Notebooks
|
| 6 |
+
# website: http://jupyter.org/
|
| 7 |
+
|
| 8 |
+
.ipynb_checkpoints
|
| 9 |
+
*/.ipynb_checkpoints/*
|
| 10 |
+
|
| 11 |
+
# IPython
|
| 12 |
+
profile_default/
|
| 13 |
+
ipython_config.py
|
| 14 |
+
|
| 15 |
+
# Remove previous ipynb_checkpoints
|
| 16 |
+
# git rm -r .ipynb_checkpoints/
|
| 17 |
+
|
| 18 |
+
### macOS ###
|
| 19 |
+
# General
|
| 20 |
+
.DS_Store
|
| 21 |
+
.AppleDouble
|
| 22 |
+
.LSOverride
|
| 23 |
+
|
| 24 |
+
# Icon must end with two \r
|
| 25 |
+
Icon
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# Thumbnails
|
| 29 |
+
._*
|
| 30 |
+
|
| 31 |
+
# Files that might appear in the root of a volume
|
| 32 |
+
.DocumentRevisions-V100
|
| 33 |
+
.fseventsd
|
| 34 |
+
.Spotlight-V100
|
| 35 |
+
.TemporaryItems
|
| 36 |
+
.Trashes
|
| 37 |
+
.VolumeIcon.icns
|
| 38 |
+
.com.apple.timemachine.donotpresent
|
| 39 |
+
|
| 40 |
+
# Directories potentially created on remote AFP share
|
| 41 |
+
.AppleDB
|
| 42 |
+
.AppleDesktop
|
| 43 |
+
Network Trash Folder
|
| 44 |
+
Temporary Items
|
| 45 |
+
.apdisk
|
| 46 |
+
|
| 47 |
+
### macOS Patch ###
|
| 48 |
+
# iCloud generated files
|
| 49 |
+
*.icloud
|
| 50 |
+
|
| 51 |
+
### PyCharm+all ###
|
| 52 |
+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
| 53 |
+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
| 54 |
+
|
| 55 |
+
# User-specific stuff
|
| 56 |
+
.idea/**/workspace.xml
|
| 57 |
+
.idea/**/tasks.xml
|
| 58 |
+
.idea/**/usage.statistics.xml
|
| 59 |
+
.idea/**/dictionaries
|
| 60 |
+
.idea/**/shelf
|
| 61 |
+
|
| 62 |
+
# AWS User-specific
|
| 63 |
+
.idea/**/aws.xml
|
| 64 |
+
|
| 65 |
+
# Generated files
|
| 66 |
+
.idea/**/contentModel.xml
|
| 67 |
+
|
| 68 |
+
# Sensitive or high-churn files
|
| 69 |
+
.idea/**/dataSources/
|
| 70 |
+
.idea/**/dataSources.ids
|
| 71 |
+
.idea/**/dataSources.local.xml
|
| 72 |
+
.idea/**/sqlDataSources.xml
|
| 73 |
+
.idea/**/dynamic.xml
|
| 74 |
+
.idea/**/uiDesigner.xml
|
| 75 |
+
.idea/**/dbnavigator.xml
|
| 76 |
+
|
| 77 |
+
# Gradle
|
| 78 |
+
.idea/**/gradle.xml
|
| 79 |
+
.idea/**/libraries
|
| 80 |
+
|
| 81 |
+
# Gradle and Maven with auto-import
|
| 82 |
+
# When using Gradle or Maven with auto-import, you should exclude module files,
|
| 83 |
+
# since they will be recreated, and may cause churn. Uncomment if using
|
| 84 |
+
# auto-import.
|
| 85 |
+
# .idea/artifacts
|
| 86 |
+
# .idea/compiler.xml
|
| 87 |
+
# .idea/jarRepositories.xml
|
| 88 |
+
# .idea/modules.xml
|
| 89 |
+
# .idea/*.iml
|
| 90 |
+
# .idea/modules
|
| 91 |
+
# *.iml
|
| 92 |
+
# *.ipr
|
| 93 |
+
|
| 94 |
+
# CMake
|
| 95 |
+
cmake-build-*/
|
| 96 |
+
|
| 97 |
+
# Mongo Explorer plugin
|
| 98 |
+
.idea/**/mongoSettings.xml
|
| 99 |
+
|
| 100 |
+
# File-based project format
|
| 101 |
+
*.iws
|
| 102 |
+
|
| 103 |
+
# IntelliJ
|
| 104 |
+
out/
|
| 105 |
+
|
| 106 |
+
# mpeltonen/sbt-idea plugin
|
| 107 |
+
.idea_modules/
|
| 108 |
+
|
| 109 |
+
# JIRA plugin
|
| 110 |
+
atlassian-ide-plugin.xml
|
| 111 |
+
|
| 112 |
+
# Cursive Clojure plugin
|
| 113 |
+
.idea/replstate.xml
|
| 114 |
+
|
| 115 |
+
# SonarLint plugin
|
| 116 |
+
.idea/sonarlint/
|
| 117 |
+
|
| 118 |
+
# Crashlytics plugin (for Android Studio and IntelliJ)
|
| 119 |
+
com_crashlytics_export_strings.xml
|
| 120 |
+
crashlytics.properties
|
| 121 |
+
crashlytics-build.properties
|
| 122 |
+
fabric.properties
|
| 123 |
+
|
| 124 |
+
# Editor-based Rest Client
|
| 125 |
+
.idea/httpRequests
|
| 126 |
+
|
| 127 |
+
# Android studio 3.1+ serialized cache file
|
| 128 |
+
.idea/caches/build_file_checksums.ser
|
| 129 |
+
|
| 130 |
+
### PyCharm+all Patch ###
|
| 131 |
+
# Ignore everything but code style settings and run configurations
|
| 132 |
+
# that are supposed to be shared within teams.
|
| 133 |
+
|
| 134 |
+
.idea/*
|
| 135 |
+
|
| 136 |
+
!.idea/codeStyles
|
| 137 |
+
!.idea/runConfigurations
|
| 138 |
+
|
| 139 |
+
### Python ###
|
| 140 |
+
# Byte-compiled / optimized / DLL files
|
| 141 |
+
__pycache__/
|
| 142 |
+
*.py[cod]
|
| 143 |
+
*$py.class
|
| 144 |
+
|
| 145 |
+
# C extensions
|
| 146 |
+
*.so
|
| 147 |
+
|
| 148 |
+
# Distribution / packaging
|
| 149 |
+
.Python
|
| 150 |
+
build/
|
| 151 |
+
develop-eggs/
|
| 152 |
+
dist/
|
| 153 |
+
downloads/
|
| 154 |
+
eggs/
|
| 155 |
+
.eggs/
|
| 156 |
+
lib/
|
| 157 |
+
lib64/
|
| 158 |
+
parts/
|
| 159 |
+
sdist/
|
| 160 |
+
var/
|
| 161 |
+
wheels/
|
| 162 |
+
share/python-wheels/
|
| 163 |
+
*.egg-info/
|
| 164 |
+
.installed.cfg
|
| 165 |
+
*.egg
|
| 166 |
+
MANIFEST
|
| 167 |
+
|
| 168 |
+
# PyInstaller
|
| 169 |
+
# Usually these files are written by a python script from a template
|
| 170 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 171 |
+
*.manifest
|
| 172 |
+
*.spec
|
| 173 |
+
|
| 174 |
+
# Installer logs
|
| 175 |
+
pip-log.txt
|
| 176 |
+
pip-delete-this-directory.txt
|
| 177 |
+
|
| 178 |
+
# Unit test / coverage reports
|
| 179 |
+
htmlcov/
|
| 180 |
+
.tox/
|
| 181 |
+
.nox/
|
| 182 |
+
.coverage
|
| 183 |
+
.coverage.*
|
| 184 |
+
.cache
|
| 185 |
+
nosetests.xml
|
| 186 |
+
coverage.xml
|
| 187 |
+
*.cover
|
| 188 |
+
*.py,cover
|
| 189 |
+
.hypothesis/
|
| 190 |
+
.pytest_cache/
|
| 191 |
+
cover/
|
| 192 |
+
|
| 193 |
+
# Translations
|
| 194 |
+
*.mo
|
| 195 |
+
*.pot
|
| 196 |
+
|
| 197 |
+
# Django stuff:
|
| 198 |
+
*.log
|
| 199 |
+
local_settings.py
|
| 200 |
+
db.sqlite3
|
| 201 |
+
db.sqlite3-journal
|
| 202 |
+
|
| 203 |
+
# Flask stuff:
|
| 204 |
+
instance/
|
| 205 |
+
.webassets-cache
|
| 206 |
+
|
| 207 |
+
# Scrapy stuff:
|
| 208 |
+
.scrapy
|
| 209 |
+
|
| 210 |
+
# Sphinx documentation
|
| 211 |
+
docs/_build/
|
| 212 |
+
|
| 213 |
+
# PyBuilder
|
| 214 |
+
.pybuilder/
|
| 215 |
+
target/
|
| 216 |
+
|
| 217 |
+
# Jupyter Notebook
|
| 218 |
+
|
| 219 |
+
# IPython
|
| 220 |
+
|
| 221 |
+
# pyenv
|
| 222 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 223 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 224 |
+
# .python-version
|
| 225 |
+
|
| 226 |
+
# pipenv
|
| 227 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 228 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 229 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 230 |
+
# install all needed dependencies.
|
| 231 |
+
#Pipfile.lock
|
| 232 |
+
|
| 233 |
+
# poetry
|
| 234 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 235 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 236 |
+
# commonly ignored for libraries.
|
| 237 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 238 |
+
#poetry.lock
|
| 239 |
+
|
| 240 |
+
# pdm
|
| 241 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 242 |
+
#pdm.lock
|
| 243 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 244 |
+
# in version control.
|
| 245 |
+
# https://pdm.fming.dev/#use-with-ide
|
| 246 |
+
.pdm.toml
|
| 247 |
+
|
| 248 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 249 |
+
__pypackages__/
|
| 250 |
+
|
| 251 |
+
# Celery stuff
|
| 252 |
+
celerybeat-schedule
|
| 253 |
+
celerybeat.pid
|
| 254 |
+
|
| 255 |
+
# SageMath parsed files
|
| 256 |
+
*.sage.py
|
| 257 |
+
|
| 258 |
+
# Environments
|
| 259 |
+
.env
|
| 260 |
+
.venv
|
| 261 |
+
env/
|
| 262 |
+
venv/
|
| 263 |
+
ENV/
|
| 264 |
+
env.bak/
|
| 265 |
+
venv.bak/
|
| 266 |
+
|
| 267 |
+
# Spyder project settings
|
| 268 |
+
.spyderproject
|
| 269 |
+
.spyproject
|
| 270 |
+
|
| 271 |
+
# Rope project settings
|
| 272 |
+
.ropeproject
|
| 273 |
+
|
| 274 |
+
# mkdocs documentation
|
| 275 |
+
/site
|
| 276 |
+
|
| 277 |
+
# mypy
|
| 278 |
+
.mypy_cache/
|
| 279 |
+
.dmypy.json
|
| 280 |
+
dmypy.json
|
| 281 |
+
|
| 282 |
+
# Pyre type checker
|
| 283 |
+
.pyre/
|
| 284 |
+
|
| 285 |
+
# pytype static type analyzer
|
| 286 |
+
.pytype/
|
| 287 |
+
|
| 288 |
+
# Cython debug symbols
|
| 289 |
+
cython_debug/
|
| 290 |
+
|
| 291 |
+
# PyCharm
|
| 292 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 293 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 294 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 295 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 296 |
+
#.idea/
|
| 297 |
+
|
| 298 |
+
### Python Patch ###
|
| 299 |
+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
|
| 300 |
+
poetry.toml
|
| 301 |
+
|
| 302 |
+
# ruff
|
| 303 |
+
.ruff_cache/
|
| 304 |
+
|
| 305 |
+
# LSP config files
|
| 306 |
+
pyrightconfig.json
|
| 307 |
+
|
| 308 |
+
### VisualStudioCode ###
|
| 309 |
+
.vscode/*
|
| 310 |
+
!.vscode/settings.json
|
| 311 |
+
!.vscode/tasks.json
|
| 312 |
+
!.vscode/launch.json
|
| 313 |
+
!.vscode/extensions.json
|
| 314 |
+
!.vscode/*.code-snippets
|
| 315 |
+
|
| 316 |
+
# Local History for Visual Studio Code
|
| 317 |
+
.history/
|
| 318 |
+
|
| 319 |
+
# Built Visual Studio Code Extensions
|
| 320 |
+
*.vsix
|
| 321 |
+
|
| 322 |
+
### VisualStudioCode Patch ###
|
| 323 |
+
# Ignore all local history of files
|
| 324 |
+
.history
|
| 325 |
+
.ionide
|
| 326 |
+
|
| 327 |
+
# End of https://www.toptal.com/developers/gitignore/api/jupyternotebooks,python,pycharm+all,visualstudiocode,macos
|
main.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
import threading
|
| 5 |
+
|
| 6 |
+
sys.path.insert(0, "src")
|
| 7 |
+
os.environ['TRANSFORMERS_CACHE'] = '/tmp'
|
| 8 |
+
|
| 9 |
+
from telegram.ext import (
|
| 10 |
+
CommandHandler,
|
| 11 |
+
CallbackContext,
|
| 12 |
+
Application,
|
| 13 |
+
ContextTypes,
|
| 14 |
+
)
|
| 15 |
+
from api import GirlfriendGPT
|
| 16 |
+
from functools import partial
|
| 17 |
+
from typing import List
|
| 18 |
+
from telegram import Update
|
| 19 |
+
from termcolor import colored
|
| 20 |
+
|
| 21 |
+
SELECT_COMMAND, GET_TEXT = range(2)
|
| 22 |
+
|
| 23 |
+
# Enable logging
|
| 24 |
+
logging.basicConfig(
|
| 25 |
+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
|
| 26 |
+
)
|
| 27 |
+
logger = logging.getLogger(__name__)
|
| 28 |
+
|
| 29 |
+
# def show_results(response_messages):
|
| 30 |
+
# print(colored("\nResults: ", "blue", attrs=["bold"]))
|
| 31 |
+
# for message in response_messages:
|
| 32 |
+
# if message.mime_type:
|
| 33 |
+
# print(message.url, end="\n\n")
|
| 34 |
+
# else:
|
| 35 |
+
# print(message.text, end="\n\n")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def shutdown(updater: Update):
|
| 39 |
+
updater.stop()
|
| 40 |
+
updater.is_idle = False
|
| 41 |
+
|
| 42 |
+
def stop(update):
|
| 43 |
+
threading.Thread(target=shutdown(updater=update)).start()
|
| 44 |
+
|
| 45 |
+
async def hello(update: Update, context: CallbackContext) -> None:
|
| 46 |
+
intro_text = f"🤖 Greetings human!🤗\nI'm a bot built by Rexthecoder\n🦾 I can do a lot of things"
|
| 47 |
+
await update.message.reply_text(intro_text)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
# async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
|
| 51 |
+
# """Echo the user message."""
|
| 52 |
+
# await update.message.reply_text("Enter your text")
|
| 53 |
+
# return GET_TEXT
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class LoggingDisabled:
|
| 57 |
+
"""Context manager that turns off logging within context."""
|
| 58 |
+
|
| 59 |
+
def __enter__(self):
|
| 60 |
+
logging.disable(logging.CRITICAL)
|
| 61 |
+
|
| 62 |
+
def __exit__(self, exit_type, exit_value, exit_traceback):
|
| 63 |
+
logging.disable(logging.NOTSET)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def main():
|
| 67 |
+
app = Application.builder().token(
|
| 68 |
+
'6207542226:AAEoNVXw766dq8fYqVvBQW9Hve2Rovq0ERI',).build()
|
| 69 |
+
# application = Application.builder().token('6207542226:AAGXBVVxNNUKLUz17-5_sGJnhFDaVWUXTc8').build()
|
| 70 |
+
# application.add_handler(CommandHandler('start', hello))
|
| 71 |
+
|
| 72 |
+
# # Run the bot until the user presses Ctrl-C
|
| 73 |
+
# application.run_polling()
|
| 74 |
+
run_agent(
|
| 75 |
+
agent=GirlfriendGPT(
|
| 76 |
+
token="hello",
|
| 77 |
+
application=app
|
| 78 |
+
)
|
| 79 |
+
)
|
| 80 |
+
print(f"Starting Agent...")
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def run_agent(agent: GirlfriendGPT, as_api: bool = False) -> None:
|
| 84 |
+
# For Debugging
|
| 85 |
+
summary_handler = agent.conversation_summary_handler()
|
| 86 |
+
agent.application.add_handler(summary_handler)
|
| 87 |
+
agent.application.add_handler(CommandHandler('stop', stop))
|
| 88 |
+
agent.application.add_handler(CommandHandler('start', hello))
|
| 89 |
+
# agent.application.add_handler(CommandHandler('summary', agent.conversation_summary))
|
| 90 |
+
# agent.application.add_handler(MessageHandler(
|
| 91 |
+
# filters.TEXT & ~filters.COMMAND, agent.create_response))
|
| 92 |
+
agent.application.run_polling()
|
| 93 |
+
# agent.application.add_handler(MessageHandler(
|
| 94 |
+
# filters.TEXT & ~filters.COMMAND, agent.create_response))
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
if __name__ == "__main__":
|
| 98 |
+
main()
|
src/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
src/__pycache__/api.cpython-38.pyc
ADDED
|
Binary file (2.36 kB). View file
|
|
|
src/agent/__pycache__/__init__.cpython-38.pyc
ADDED
|
Binary file (159 Bytes). View file
|
|
|
src/agent/__pycache__/base.cpython-38.pyc
ADDED
|
Binary file (3.46 kB). View file
|
|
|
src/agent/__pycache__/utils.cpython-38.pyc
ADDED
|
Binary file (1.32 kB). View file
|
|
|
src/agent/base.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Define your LangChain chatbot."""
|
| 2 |
+
import re
|
| 3 |
+
from abc import abstractmethod
|
| 4 |
+
|
| 5 |
+
from telegram import Update
|
| 6 |
+
import telegram
|
| 7 |
+
from telegram.ext import (
|
| 8 |
+
ConversationHandler,
|
| 9 |
+
CallbackContext,
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
from agent.tools.text_summary import ConversationSummary
|
| 13 |
+
|
| 14 |
+
SELECT_COMMAND, GET_TEXT = range(2)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class LangChainAgentBot(ConversationSummary):
|
| 18 |
+
def is_verbose_logging_enabled(self):
|
| 19 |
+
return True
|
| 20 |
+
|
| 21 |
+
def send_message(self, message: str, update: Update) -> str:
|
| 22 |
+
"""Send a message to Telegram.
|
| 23 |
+
|
| 24 |
+
Note: This is a private endpoint that requires authentication."""
|
| 25 |
+
update.message.reply_text(message)
|
| 26 |
+
return "ok"
|
| 27 |
+
|
| 28 |
+
def _invoke_later(self, delay_ms: int, message: str, chat_id: str):
|
| 29 |
+
self.invoke_later(
|
| 30 |
+
"send_message",
|
| 31 |
+
delay_ms=delay_ms,
|
| 32 |
+
arguments={
|
| 33 |
+
"message": message,
|
| 34 |
+
"chat_id": chat_id,
|
| 35 |
+
},
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
async def cancel(update: Update, context: CallbackContext) -> int:
|
| 39 |
+
"""Cancel the conversation."""
|
| 40 |
+
await update.message.reply_text("Oops, glad to help you.")
|
| 41 |
+
return ConversationHandler.END
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
async def create_response(self, update: Update, context: CallbackContext) -> None:
|
| 45 |
+
await update.message.chat.send_action(action=telegram.constants.ChatAction.TYPING)
|
| 46 |
+
await update.message.reply_text(update.message.text)
|
src/agent/tools/__pycache__/__init__.cpython-38.pyc
ADDED
|
Binary file (165 Bytes). View file
|
|
|
src/agent/tools/__pycache__/image.cpython-38.pyc
ADDED
|
Binary file (2.17 kB). View file
|
|
|
src/agent/tools/__pycache__/reminder.cpython-38.pyc
ADDED
|
Binary file (3.59 kB). View file
|
|
|
src/agent/tools/__pycache__/search.cpython-38.pyc
ADDED
|
Binary file (1.59 kB). View file
|
|
|
src/agent/tools/text_summary.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import logging
|
| 3 |
+
import telegram
|
| 4 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 5 |
+
from telegram.ext import (
|
| 6 |
+
Updater,
|
| 7 |
+
CommandHandler,
|
| 8 |
+
ConversationHandler,
|
| 9 |
+
CallbackContext,
|
| 10 |
+
CallbackQueryHandler,
|
| 11 |
+
MessageHandler,
|
| 12 |
+
filters
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
from telegram import Update
|
| 16 |
+
|
| 17 |
+
NAME = "ConversationSummary"
|
| 18 |
+
|
| 19 |
+
DESCRIPTION = """
|
| 20 |
+
Useful for summarizing conversation.
|
| 21 |
+
Input: A conversation text
|
| 22 |
+
Output: A summazrised version of the conversation
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
SELECT_COMMAND, GET_TEXT = range(2)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class ConversationSummary():
|
| 29 |
+
"""Tool used to summarize text from a conversational text."""
|
| 30 |
+
|
| 31 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 32 |
+
"mrm8488/flan-t5-small-finetuned-samsum")
|
| 33 |
+
|
| 34 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(
|
| 35 |
+
"mrm8488/flan-t5-small-finetuned-samsum")
|
| 36 |
+
|
| 37 |
+
async def summarize(self, input: str, words: int):
|
| 38 |
+
|
| 39 |
+
logging.info(f"{input} {words}")
|
| 40 |
+
|
| 41 |
+
input_ids = self.tokenizer(input, return_tensors="pt").input_ids
|
| 42 |
+
outputs = self.model.generate(input_ids, max_length=words)
|
| 43 |
+
decoded_output = self.tokenizer.decode(
|
| 44 |
+
outputs[0], skip_special_tokens=True)
|
| 45 |
+
return f"{decoded_output}"
|
| 46 |
+
|
| 47 |
+
def conversation_summary_handler(self) -> ConversationHandler:
|
| 48 |
+
handler = ConversationHandler(
|
| 49 |
+
entry_points=[CommandHandler(
|
| 50 |
+
"summary", self.conversation_summary)],
|
| 51 |
+
states={
|
| 52 |
+
GET_TEXT: [MessageHandler(filters.TEXT & ~filters.COMMAND, self.process_conversation_summary)],
|
| 53 |
+
},
|
| 54 |
+
fallbacks=[CommandHandler("cancel", self.cancel)],
|
| 55 |
+
)
|
| 56 |
+
return handler
|
| 57 |
+
|
| 58 |
+
async def process_conversation_summary(self, update: Update, context: CallbackContext) -> int:
|
| 59 |
+
message = update.message.text
|
| 60 |
+
await self.summarize(message, 100)
|
| 61 |
+
return ConversationHandler.END
|
| 62 |
+
|
| 63 |
+
async def conversation_summary(self, update: Update, context: CallbackContext) -> str:
|
| 64 |
+
await update.message.reply_text(f'Please enter your conversations...')
|
| 65 |
+
return GET_TEXT
|
src/api.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Scaffolding to host your LangChain Chatbot on Steamship and connect it to Telegram."""
|
| 2 |
+
from typing import List, Optional, Type
|
| 3 |
+
|
| 4 |
+
from pydantic import Field
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
from agent.base import LangChainAgentBot
|
| 8 |
+
from telegram.ext import Updater, CommandHandler, CallbackContext, Application, ContextTypes
|
| 9 |
+
from telegram import Update
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
VERBOSE = True
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class GirlFriendAIConfig():
|
| 16 |
+
elevenlabs_api_key: str = Field(
|
| 17 |
+
default="", description="Optional API KEY for ElevenLabs Voice Bot"
|
| 18 |
+
)
|
| 19 |
+
elevenlabs_voice_id: str = Field(
|
| 20 |
+
default="", description="Optional voice_id for ElevenLabs Voice Bot"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class GirlfriendGPT(LangChainAgentBot):
|
| 25 |
+
"""Deploy LangChain chatbots and connect them to Telegram."""
|
| 26 |
+
|
| 27 |
+
token: str
|
| 28 |
+
application: Application
|
| 29 |
+
|
| 30 |
+
def __init__(self, token, application):
|
| 31 |
+
super().__init__()
|
| 32 |
+
self.application = application
|
| 33 |
+
# application.add_handler(CommandHandler('start', hello))
|
| 34 |
+
# Run the bot until the user presses Ctrl-C
|
| 35 |
+
# self.application.run_polling()
|
| 36 |
+
self.token = token
|
| 37 |
+
|
| 38 |
+
# async def echo(self, update: Update, context: CallbackContext) -> None:
|
| 39 |
+
# """Echo the user message."""
|
| 40 |
+
# await update.message.reply_text(update.message.text)
|
| 41 |
+
|
| 42 |
+
# def voice_tool(self) -> Optional[Tool]:
|
| 43 |
+
# """Return tool to generate spoken version of output text."""
|
| 44 |
+
# # return None
|
| 45 |
+
# return GenerateSpeechTool(
|
| 46 |
+
# client=self.client,
|
| 47 |
+
# voice_id=self.config.elevenlabs_voice_id,
|
| 48 |
+
# elevenlabs_api_key=self.config.elevenlabs_api_key,
|
| 49 |
+
# )
|
| 50 |
+
|
| 51 |
+
# def get_memory(self, chat_id):
|
| 52 |
+
# if self.context and self.context.invocable_instance_handle:
|
| 53 |
+
# my_instance_handle = self.context.invocable_instance_handle
|
| 54 |
+
# else:
|
| 55 |
+
# my_instance_handle = "local-instance-handle"
|
| 56 |
+
# memory = ConversationBufferMemory(
|
| 57 |
+
# memory_key="chat_history",
|
| 58 |
+
# chat_memory=ChatMessageHistory(
|
| 59 |
+
# client=self.client, key=f"history-{chat_id}-{my_instance_handle}"
|
| 60 |
+
# ),
|
| 61 |
+
# return_messages=True,
|
| 62 |
+
# )
|
| 63 |
+
# return memory
|