Skip to main content

Framework to create applications and model adapters for AI DIAL

Project description

AI DIAL Python SDK

Overview

Framework to create applications and model adapters for AI DIAL.

Applications and model adapters implemented using this framework will be compatible with AI DIAL API that was designed based on Azure OpenAI API.

Usage

Install the library using pip:

pip install aidial-sdk

Echo application example

The echo application example replies to the user by repeating their last message:

# Save this as app.py
import uvicorn

from aidial_sdk import DIALApp
from aidial_sdk.chat_completion import ChatCompletion, Request, Response


# ChatCompletion is an abstract class for applications and model adapters
class EchoApplication(ChatCompletion):
    async def chat_completion(
        self, request: Request, response: Response
    ) -> None:
        # Get last message (the newest) from the history
        last_user_message = request.messages[-1]

        # Generate response with a single choice
        with response.create_single_choice() as choice:
            # Fill the content of the response with the last user's content
            choice.append_content(last_user_message.content or "")


# DIALApp extends FastAPI to provide a user-friendly interface for routing requests to your applications
app = DIALApp()
app.add_chat_completion("echo", EchoApplication())

# Run built app
if __name__ == "__main__":
    uvicorn.run(app, port=5000)

Run

python3 app.py

Check

Send the next request:

curl http://127.0.0.1:5000/openai/deployments/echo/chat/completions \
  -H "Content-Type: application/json" \
  -H "Api-Key: DIAL_API_KEY" \
  -d '{
    "messages": [{"role": "user", "content": "Repeat me!"}]
  }'

You will see the JSON response as:

{
    "choices":[
        {
            "index": 0,
            "finish_reason": "stop",
            "message": {
                "role": "assistant",
                "content": "Repeat me!"
            }
        }
    ],
    "usage": null,
    "id": "d08cfda2-d7c8-476f-8b95-424195fcdafe",
    "created": 1695298034,
    "object": "chat.completion"
}

Developer environment

This project uses Python>=3.8 and Poetry>=1.6.1 as a dependency manager.

Check out Poetry's documentation on how to install it on your system before proceeding.

To install requirements:

poetry install

This will install all requirements for running the package, linting, formatting and tests.

IDE configuration

The recommended IDE is VSCode. Open the project in VSCode and install the recommended extensions.

The VSCode is configured to use PEP-8 compatible formatter Black.

Alternatively you can use PyCharm.

Set-up the Black formatter for PyCharm manually or install PyCharm>=2023.2 with built-in Black support.

Environment Variables

Variable Default Description
DIAL_SDK_LOG WARNING DIAL SDK log level

Lint

Run the linting before committing:

make lint

To auto-fix formatting issues run:

make format

Test

Run unit tests locally for available python versions:

make test

Run unit tests for the specific python version:

make test PYTHON=3.11

Clean

To remove the virtual environment and build artifacts run:

make clean

Build

To build the package run:

make build

Publish

To publish the package to PyPI run:

make publish

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aidial_sdk-0.14.0rc0.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

aidial_sdk-0.14.0rc0-py3-none-any.whl (36.9 kB view details)

Uploaded Python 3

File details

Details for the file aidial_sdk-0.14.0rc0.tar.gz.

File metadata

  • Download URL: aidial_sdk-0.14.0rc0.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.8.0-1014-azure

File hashes

Hashes for aidial_sdk-0.14.0rc0.tar.gz
Algorithm Hash digest
SHA256 ac7924955dc72254e877f72ad96921662b19543a487bc1c5c1bd6e8c12284bee
MD5 eedf4fffdb8c934c80e53493c7fac46b
BLAKE2b-256 326985b734c420a9eb14b0566e1ddbbdccd1fcf736ce4a3a5c4f5cf90f7e82dd

See more details on using hashes here.

File details

Details for the file aidial_sdk-0.14.0rc0-py3-none-any.whl.

File metadata

  • Download URL: aidial_sdk-0.14.0rc0-py3-none-any.whl
  • Upload date:
  • Size: 36.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.8.0-1014-azure

File hashes

Hashes for aidial_sdk-0.14.0rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae84b6323cfa7e63ba5354f88455422cbb33e87712790950072f83a3a94d3115
MD5 9819380ac375952f83ffebad8bb2c0cd
BLAKE2b-256 fb7cbc91fe34102f8fbf9f22f147c6577da0896512db29bcd2425ecf964fcc90

See more details on using hashes here.

Supported by

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