diff --git a/openchatbotclient/__init__.py b/openchatbotclient/__init__.py index 9c27f9f..79bb375 100644 --- a/openchatbotclient/__init__.py +++ b/openchatbotclient/__init__.py @@ -1,4 +1,48 @@ -"""Client for Open Chat Bot's""" +""" +Open Chat Bot Client package +============================ + +This Python package contains utilities that allow you to find, access, and use bots that are compliant with the Alliance for Open Chatbot standard. The package is designed for the Python 3 environments. + +The Open Chatbot standard +------------------------- + +The implementation is based on the standard defined by the Alliance. + - The Alliance: https://www.alliance-open-chatbot.org/ + - The standard: https://github.com/alliance-for-openchatbot/standard + +Authors +------- + +The initial implementation is made by Konverso in 2020 by Alexander Danilov and Amedee Potier (amedee.potier@konverso.ai). + +See also +-------- + + - The API standard specifications: + https://github.com/alliance-for-openchatbot/standard + - The definition of the standard bot descriptor: + https://openchatbot.io/domainbots + - The easy-to-use web client that adds a widget connected to any chatbot to your website: + https://github.com/ohoachuck/openchatbot-webclient + +License +------- + +This package is released under the MIT license. To learn more about it, view the LICENSE file in this folder. + +Usage +----- + +To get started, either view the test.py file in this module, or consult the help on the client module: + + from openchatbotclient import client + help(client) + +View complete examples and tutorials in the related GitHub repository: + https://github.com/konverso-ai/open-chatbot-py-client + +""" from .client import Client from .descriptor import Descriptor diff --git a/openchatbotclient/client.py b/openchatbotclient/client.py index 038f3e6..7b467f9 100644 --- a/openchatbotclient/client.py +++ b/openchatbotclient/client.py @@ -1,14 +1,21 @@ """Client for Open Chat Bot. - Example of usage: - from openchatbotclient.client import client - myclient = client('bot.domain.com', 8443, path='api') - response = myclient.ask("my-userId", "hello") + Example of usage: - In this case next GET request will be invoked: - https://bot.domain.com:8443/api/ask - with params: - {'userId': 'my-userId', 'query': 'hello'} + from openchatbotclient.client import Client + + # You can create a Client using the native constructor + client = Client('bot.domain.com', 8443, path='api') + response = client.ask("my-userId", "hello") + + # Or using a URL to the API + client = Client.from_url("https://mybot.mydomain.com/api/v1/ask") + response = client.ask("john.doe", "what is the weather today?") + + The 'ask' method causes a GET request to be invoked, such as: + https://bot.domain.com:8443/api/ask + with params: + {'userId': 'my-userId', 'query': 'hello'} Authors: - Alexander Danilov from Konverso @@ -18,6 +25,9 @@ - 2019/11/01: Alexander: Initial class implementation - 2020/11/02: Amédée: Renaming class to "client" - 2020/11/02: Amédée: Adding the "from_descriptor" static method + - 2020/12/15: Amédée: Adding the "from_url" static method + Adjusting names to be PEP8 compliants + """ import json @@ -97,7 +107,7 @@ def from_descriptor(descriptor): @staticmethod def from_url(url): - """Given a "descriptor" instance, returns a new "client" instance""" + """Given a URL pointing to the "ask" API, returns a new "client" instance""" # Extracting from the URL the protocol, the domain, the path # token0://token2/token3 @@ -126,6 +136,10 @@ def from_url(url): @property def base_url(self) -> str: + """Returns the URL of the remote bot "ask" API web service, + that is something like: + http[s]://host.domain[:port]/path/to/api/ask + """ url = self.host if self.port: diff --git a/openchatbotclient/client_group.py b/openchatbotclient/client_group.py index 4ce79e4..9937513 100644 --- a/openchatbotclient/client_group.py +++ b/openchatbotclient/client_group.py @@ -9,6 +9,8 @@ History: - 2020/11/02: Amédée: Initial class implementation + - 2020/12/15: Amédée: Adjusting names to be compliant with PEP8 + """ from .client import Client diff --git a/openchatbotclient/repository.py b/openchatbotclient/repository.py index d9d6b97..00e5f74 100644 --- a/openchatbotclient/repository.py +++ b/openchatbotclient/repository.py @@ -10,6 +10,7 @@ History: - 2020/11/02: Amédée: Initial version. + - 2020/12/15: Amédée: Adjusting names to be compliant with PEP8 """ diff --git a/openchatbotclient/test.py b/openchatbotclient/test.py index cec4d13..8981478 100644 --- a/openchatbotclient/test.py +++ b/openchatbotclient/test.py @@ -13,11 +13,17 @@ from openchatbotclient import Client - bot_konverso = Client('https://callbot.konverso.ai', port=443, path='/api/ask') + # Create a client using its constructor and query it + bot_konverso = Client('https://callbot.konverso.ai', port=443, path='/api/ask') response = bot_konverso.ask("amedee", "hello", lang="fr") print(response) + # Create a client using a URL pointing to its open chatbot API + bot_konverso = Client.from_url('https://callbot.konverso.ai/api/ask') + response = bot_konverso.ask("amedee", "hello you", lang="fr") + print(response) + # # Use the Repository to retrieve a Client or a Descriptor # @@ -92,11 +98,11 @@ import json print(json.dumps(bot_konverso.descriptor, indent=4)) - print("\n\n#### Testing wikipedia") - bot_doungdoung = Client.from_url('https://doungdoung.com/api/wikipedia/v1.0/ask') - response = bot_doungdoung.ask("amedee", "hello", lang="fr") - print("Wikipedia says: %s", response.text) + #print("\n\n#### Testing wikipedia") + #bot_doungdoung = Client.from_url('https://doungdoung.com/api/wikipedia/v1.0/ask') + #response = bot_doungdoung.ask("amedee", "hello", lang="fr") + #print("Wikipedia says: %s", response.text) bot_kwalys = repo.get_client("kwalys.com") response = bot_kwalys.ask("amedee", "hello", lang="fr") - print("EDF says: %s", response.text) + print("EDF replies: ", response.text) diff --git a/setup.py b/setup.py index 9b1f81f..509b743 100755 --- a/setup.py +++ b/setup.py @@ -4,14 +4,14 @@ long_description = fh.read() setuptools.setup( - name="open-chat-bot-client", - version="0.0.1", + name="open-chatbot-py-client", + version="0.1.0", author="Konverso", - author_email="", - description="Client for Open Chat Bot", + author_email="contact@konverso.ai", + description="Client to access any chatbot compliant with the Alliance for Open Chatbot standard", long_description=long_description, long_description_content_type="text/markdown", - url="https://konverso.ai", + url="https://www.konverso.ai", packages=setuptools.find_packages(), classifiers=[ "Programming Language :: Python :: 3",