SDK to create backend APIs for ChatdollKit HttpDialogRouter and HttpDialogProcessor.
Project description
ChatdollKit Server SDK for Python
SDK to create backend APIs for ChatdollKit. See also 👉 ChatdollKit
Install
$ pip install chatdollkit
Also install application framework you like. We support Flask and FastAPI.
$ pip install flask
Or
$ pip install fastapi uvicorn
Quick start
Run example API server that just echo what user says.
$ python flaskapp.py
On Unity, attach HttpDialogRouter
and HttpPrompter
to your 3D model and configure like below:
- Intent Extractor Uri:
http://localhost:12345/chatdollkit/intent
- Dialog Processor Uri Base:
http://localhost:12345/chatdollkit/dialog
- Prompter Uri:
http://localhost:12345/chatdollkit/prompter
- Ping Uri:
http://localhost:12345/chatdollkit/ping
NOTE: Text-to-Speech service is required
Run your Chatdoll app and start conversation. Your 3D model will echo what you say.
Create your own dialog
Create classes that extend PrompterBase
, IntentExtractorBase
, and DialogProcessorBase
and override their methods.
class MyPrompter(PrompterBase):
def get_prompt(self, context, response):
response.AddVoiceTTS("May I help you?")
class MyIntentExtractor(IntentExtractorBase):
def extract_intent(self, request, context):
# define conditions to decide intent
if ("weather" in request.Text):
request.Intent = "weather"
elif ("translation" in request.Text):
request.Intent = "translation"
else:
request.Intent = "chat"
request.IntentPriority = Priority.Low
class WeatherDialog(DialogProcessorBase):
def process(self, request, context, response):
weather = get_weather() # getting weather
response.AddVoiceTTS(
f"It's {weather} today.")
If you use FastAPI or some application frameworks that support async, override get_prompt_async
, extract_intent_async
and process_async
instead.
After that configure app with these classes.
dialog_classes = {
"weather": WeatherDialog,
"translation": TranslationDialog,
"chat": ChatDialog
}
FlaskConnector.configure_app(
app, MyIntentExtractor, dialog_classes, MyPrompter, debug=True)
Use other application framework
To use application framework other than Flask and FastAPI, create and use connector class that extends ConnectorBase
and override these methods:
parse_request
: convert HTTP request object to internal api objectsmake_response
: convert internal api objects to HTTP responsemake_error_response
: convert internal api objects to HTTP response with error info
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for chatdollkit-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23a53b52287dcbe0509a61c19ea39c46d4caf4ed65e8c82143182596346740c3 |
|
MD5 | 0dc31b5493e2560a6e28ae0795438ceb |
|
BLAKE2b-256 | 448921fbdeffbb2a4ce61f934075671529ab80d3901b27592c7494e38e2721d8 |