Skip to content

Kb 8933 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion openchatbotclient/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
32 changes: 23 additions & 9 deletions openchatbotclient/client.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions openchatbotclient/client_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions openchatbotclient/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""

Expand Down
18 changes: 12 additions & 6 deletions openchatbotclient/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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)
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down