SDK to create remote skill server for ChatdollKit.
Project description
ChatdollKit Server SDK for Python
SDK to create remote skill server 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
Server side
Run example API server that just echo what user says.
$ python run_flask.py
Or
$ uvicorn run_fastapi:app --port 12345 --reload
Client side
See ChatdollKit Documentation > Setup Skill client (ChatdollKit device) to use Examples/SkillServer
.
If you want to run skill server on host other than localhost configure URLs on the inspector of HttpSkillRouter
and HttpPrompter
.
After setting up both server and client, run your Chatdoll app and start conversation. Your 3D model will echo what you say.
Create your own Skill Server
Basically Skill(s), Server application and Entrypoint are required to create your Skill Server as following chapters.
First of all, make allinone.py
and import required libraries.
from flask import Flask
from chatdollkit.app import SkillBase, AppBase
from chatdollkit.models import (
Request, Response, State, IntentExtractionResult, Intent
)
from chatdollkit.controllers.flask_controller import bp as api_bp
1. Skill
Make EchoSkill
class that extends SkillBase
and implement process
methods to return response that includes a Text-to-Speech voice request.
class EchoSkill(SkillBase):
topic = "echo"
def process(self, request: Request, state: State) -> Response:
# Just echo
resp = Response(Id=request.Id)
resp.AddVoiceTTS(request.Text)
return resp
2. Server application
Make MyApp
that extends AppBase
and implement get_prompt
methods that requires voice input to user and extract_intent
to route to EchoSkill
.
class MyApp(AppBase):
# Register skill(s)
skills = [EchoSkill]
def get_prompt(self, request: Request, state: State) -> Response:
# Return prompt message
resp = Response(Id="_" if request is None else request.Id)
resp.AddVoiceTTS("This prompt is from server. Please say something.")
return resp
def extract_intent(self, request: Request, state: State) -> IntentExtractionResult:
# Always extract Echo intent
return IntentExtractionResult(Intent=Intent(Name=EchoSkill.topic))
3. Application entry point
Lastly, Add the instance of MyApp
to Flask application and register API controller blueprint to app.
# Create Flask app
app = Flask(__name__)
# Create ChatdollKit server app and set it to Flask application
app.chatdoll_app = MyApp(app.logger, True)
# Register API controller
app.register_blueprint(api_bp)
if __name__ == "__main__":
# Start API
app.run(port="12345", debug=True)
See the example if you want to create FastAPI-based skill server.
Use other application framework
To use application framework other than Flask and FastAPI, create controller that handles http request from ChatdollKit client by your self. You can reuse Skill, Server application and models. See chatdollkit.controllers.flask_controller.py
or fastapi_controller.py
.
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
File details
Details for the file chatdollkit-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: chatdollkit-0.3.0-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d45c168b0ab2312efd98430f5f0eeef9395535eb07a761f894a770f12869133 |
|
MD5 | eb985a6f346227f3680fcdae457d3bec |
|
BLAKE2b-256 | f13229601a7d979e8efd8ef0ea1f1f4f1d638b0783e08159ec9a262e52fd04d1 |