Skip to content

Commit

Permalink
Add demo bot code
Browse files Browse the repository at this point in the history
  • Loading branch information
OgnjenFrancuski committed Jan 11, 2024
1 parent fc0cb45 commit 1a3894e
Show file tree
Hide file tree
Showing 136 changed files with 10,657 additions and 0 deletions.
137 changes: 137 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
.idea/
.DS_Store
# emacs
*~

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version
# asdf
.tool-versions

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
.rasa/
models/
78 changes: 78 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "chat",
"type": "python",
"request": "launch",
"module": "rasa.__main__",
"args": ["inspect", "--debug"],
"cwd": "${workspaceFolder}",
"justMyCode": false,
"python": "${workspaceFolder}/.venv/bin/python"
},
{
"name": "train",
"type": "python",
"request": "launch",
"module": "rasa.__main__",
"args": ["train", "-c" ,"config.yml", "-d", "domain","--data", "data", "--debug", "--force"],
"cwd": "${workspaceFolder}",
"justMyCode": false,
"python": "${workspaceFolder}/.venv/bin/python",
},
{
"name": "test",
"type": "python",
"request": "launch",
"module": "rasa.__main__",
"args": ["test", "e2e", "tests/"],
"cwd": "${workspaceFolder}",
"justMyCode": false,
"python": "${workspaceFolder}/.venv/bin/python",
},
{
"name": "train starter-pack-intentless-policy",
"type": "python",
"request": "launch",
"module": "rasa.__main__",
"args": ["train"],
"cwd": "${workspaceFolder}/../starter-pack-intentless-policy",
"justMyCode": false,
"python": "${workspaceFolder}/.venv/bin/python",
},
{
"name": "chat starter-pack-intentless-policy",
"type": "python",
"request": "launch",
"module": "rasa.__main__",
"args": ["shell", "--debug"],
"cwd": "${workspaceFolder}/../starter-pack-intentless-policy",
"justMyCode": false,
"python": "${workspaceFolder}/.venv/bin/python",
},
{
"name": "test example",
"type": "python",
"request": "launch",
"module": "rasa.__main__",
"args": ["test", "nlu", "--nlu", "tests/test_nlu.md"],
"cwd": "${workspaceFolder}/../example",
"justMyCode": false,
"python": "${workspaceFolder}/.venv/bin/python",
},
{
"name": "train example",
"type": "python",
"request": "launch",
"module": "rasa.__main__",
"args": ["train", "nlu"],
"cwd": "${workspaceFolder}/../example",
"justMyCode": false,
"python": "${workspaceFolder}/.venv/bin/python",
}
]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.formatting.provider": "black",
"python.formatting.blackPath": "${workspaceFolder}/.venv/bin/black"
}
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.PHONY: install test run train test-passing help actions

-include .env

help:
@echo "install - install dependencies"
@echo "test - run tests"
@echo "run - run chatbot"
@echo "train - train chatbot"

.EXPORT_ALL_VARIABLES:

install:
poetry install

test: .EXPORT_ALL_VARIABLES
poetry run rasa test e2e e2e_tests

run: .EXPORT_ALL_VARIABLES
poetry run rasa chat --debug

train: .EXPORT_ALL_VARIABLES
poetry run rasa train -c config.yml -d domain --data data

actions:
poetry run rasa run actions

test-passing: .EXPORT_ALL_VARIABLES
poetry run rasa test e2e e2e_tests/passing

test-failing: .EXPORT_ALL_VARIABLES
poetry run rasa test e2e e2e_tests/failing

test-one: .EXPORT_ALL_VARIABLES
poetry run rasa test e2e $(target) --debug
Empty file added actions/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions actions/add_contact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import Any, Dict
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet
from rasa_sdk.executor import CollectingDispatcher
from actions.db import get_contacts, add_contact, Contact


class AddContact(Action):

def name(self) -> str:
return "add_contact"

def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker, domain: Dict[str, Any]):
contacts = get_contacts(tracker.sender_id)
name = tracker.get_slot("add_contact_name")
handle = tracker.get_slot("add_contact_handle")

if name is None or handle is None:
return [SlotSet("return_value", "data_not_present")]

existing_handles = {c.handle for c in contacts}
if handle in existing_handles:
return [SlotSet("return_value", "already_exists")]

new_contact = Contact(name=name, handle=handle)
add_contact(tracker.sender_id, new_contact)
return [SlotSet("return_value", "success")]
16 changes: 16 additions & 0 deletions actions/check_balance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import Any, Dict
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet
from rasa_sdk.executor import CollectingDispatcher
from actions.db import get_account


class CheckBalance(Action):

def name(self) -> str:
return "check_balance"

def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker, domain: Dict[str, Any]):
account = get_account(tracker.sender_id)
return [SlotSet("current_balance", account.funds)]
Loading

0 comments on commit 1a3894e

Please sign in to comment.