There are cases where developers may want to contribute code to ChatterBot but for various reasons it doesn't make sense or isn't possible to add the code to the main ChatterBot repository on GitHub.
Common reasons that code can't be contributed include:
In addition, all code should be well documented and thoroughly tested.
Suppose we want to create a new logic adapter for ChatterBot and add it the Python Package Index (PyPI) so that other developers can install it and use it. We would begin doing this by setting up a directory file the following structure.
.. literalinclude:: _includes/python_module_structure.txt :caption: Python Module Structure
More information on creating Python packages can be found here: https://packaging.python.org/tutorials/distributing-packages/
Create an account: https://pypi.python.org/pypi?%3Aaction=register_form
Create a .pypirc
configuration file.
[distutils]
index-servers =
pypi
[pypi]
username=my_username
password=my_password
python setup.py sdist bdist_wheel
The official tool for uploading Python packages is called twine. You can install twine with pip if you don't already have it installed.
pip install twine
twine upload dist/*
cd IronyAdapter
pip install . --upgrade
If you are creating a module that ChatterBot imports from a dotted module path then you can set the following in your chat bot.
chatbot = ChatBot(
"My ChatBot",
logic_adapters=[
"irony_adapter.logic.IronyAdapter"
]
)
from unittest import TestCase
class IronyAdapterTestCase(TestCase):
"""
Test that the irony adapter allows
the chat bot to understand irony.
"""
def test_irony(self):
# TODO: Implement test logic
self.assertTrue(response.irony)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。