Skip to main content

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

🇯🇵日本語のREADMEはこちら

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

chatdollkit-0.3.0-py3-none-any.whl (12.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page