Observed since 21 Oct, 10:30 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
aidial-sdk
Framework to create applications and model adapters for AI DIAL
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.
| Variable | Default | Description |
|---|---|---|
| DIAL_SDK_HEADERS_TO_PROXY | `` | A comma-separated list of headers that should be proxied from incoming requests to outgoing requests to the DIAL API. By default, no headers are proxied. |
| DIAL_SDK_SSE_HEARTBEAT_INTERVAL | When set, the SDK inserts ping comments into streaming chat completion responses after the response has been idle for the specified number of seconds, helping prevent read timeouts when the DIAL application isn't responsive. | |
| PYDANTIC_V2 | False | When True and Pydantic V2 is installed, DIAL SDK classes for requests/responses will be based on Pydantic V2 BaseModel. Otherwise, they will be based on Pydantic V1 BaseModel. |
Logging-related environment variables (log level, console format, and trace/span correlation) are documented in docs/logging.md.
Install the library using pip:
pip install aidial-sdk
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.text())
# 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)
python3 app.py
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"
}
Every deployment is exposed under two base paths:
| Base path | Description |
|---|---|
/openai/deployments/{deployment_name} | The DIAL API path. The deployment name is a part of the path. |
/openai/v1 | The Azure OpenAI v1 API path. The deployment name comes from the request headers. |
The following endpoints are served under each of them:
POST <base path>/chat/completionsPOST <base path>/ratePOST <base path>/tokenizePOST <base path>/truncate_promptGET <base path>/configurationPOST <base path>/embeddingsrequest.deployment_id is resolved from the first of the following sources that is set:
X-DIAL-OVERRIDE-NAME header,/openai/deployments/{deployment_name} requests,X-DIAL-DEPLOYMENT-ID header, which DIAL Core sets when it calls the /openai/v1 endpoints.An /openai/v1 request with none of the headers set fails with 500 Internal Server Error.
This project requires Python ≥3.11 and Poetry ≥2.1.1 for dependency management.
Install Poetry. See the official installation guide.
(Optional) Specify custom Python or Poetry executables in .env.dev. This is useful if multiple versions are installed. By default, python and poetry are used.
POETRY_PYTHON=path-to-python-exe
POETRY=path-to-poetry-exe
Create and activate the virtual environment:
make init_env
source .venv/bin/activate
Install project dependencies (including linting, formatting, and test tools):
make install
The recommended IDE is VSCode. Open the project in VSCode and install the recommended extensions. VS Code is configured to use the Ruff formatter.
Alternatively you can use PyCharm that has built-in Ruff support.
Run the linting before committing:
make lint
To auto-fix formatting issues run:
make format
Run unit tests locally for available python versions:
make test
Run unit tests for the specific python version:
make test PYTHON=3.11
You may optionally install Git hooks that will automatically run the linting step on Git push. You only need to do it once for the given repository.
make install_git_hooks
[!IMPORTANT] This command doesn't work if you have already installed Git hooks locally or globally.
To remove the virtual environment and build artifacts run:
make clean
To build the package run:
make build
To publish the package to PyPI run:
make publish
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
fastapiEnvironment{
"extras": "",
"marker": null,
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | fastapi<1.0,>=0.51 | runtime |
uvicornEnvironment{
"extras": "",
"marker": null,
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | uvicorn<1.0,>=0.19 | runtime |
pydanticEnvironment{
"extras": "",
"marker": null,
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | pydantic<3,>=1.10.17 | runtime |
wraptEnvironment{
"extras": "",
"marker": null,
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | wrapt<3,>=1.10 | runtime |
opentelemetry-sdkEnvironment{
"extras": "",
"marker": "extra == \"telemetry\"",
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | opentelemetry-sdk<2.0,>=1.22.0; extra == "telemetry" | runtime |
opentelemetry-apiEnvironment{
"extras": "",
"marker": "extra == \"telemetry\"",
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | opentelemetry-api<2.0,>=1.22.0; extra == "telemetry" | runtime |
opentelemetry-exporter-otlp-proto-grpcEnvironment{
"extras": "",
"marker": "extra == \"telemetry\"",
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | opentelemetry-exporter-otlp-proto-grpc<2.0,>=1.22.0; extra == "telemetry" | runtime |
opentelemetry-instrumentation-aiohttp-clientEnvironment{
"extras": "",
"marker": "extra == \"telemetry\"",
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | opentelemetry-instrumentation-aiohttp-client>=0.43b0; extra == "telemetry" | runtime |
opentelemetry-instrumentation-fastapiEnvironment{
"extras": "",
"marker": "extra == \"telemetry\"",
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | opentelemetry-instrumentation-fastapi>=0.43b0; extra == "telemetry" | runtime |
opentelemetry-instrumentation-httpxEnvironment{
"extras": "",
"marker": "extra == \"telemetry\"",
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | opentelemetry-instrumentation-httpx>=0.43b0; extra == "telemetry" | runtime |
opentelemetry-instrumentation-loggingEnvironment{
"extras": "",
"marker": "extra == \"telemetry\"",
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | opentelemetry-instrumentation-logging>=0.43b0; extra == "telemetry" | runtime |
opentelemetry-instrumentation-requestsEnvironment{
"extras": "",
"marker": "extra == \"telemetry\"",
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | opentelemetry-instrumentation-requests>=0.43b0; extra == "telemetry" | runtime |
opentelemetry-instrumentation-system-metricsEnvironment{
"extras": "",
"marker": "extra == \"telemetry\"",
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | opentelemetry-instrumentation-system-metrics>=0.43b0; extra == "telemetry" | runtime |
opentelemetry-instrumentation-urllibEnvironment{
"extras": "",
"marker": "extra == \"telemetry\"",
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | opentelemetry-instrumentation-urllib>=0.43b0; extra == "telemetry" | runtime |
opentelemetry-exporter-prometheusEnvironment{
"extras": "",
"marker": "extra == \"telemetry\"",
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | opentelemetry-exporter-prometheus>=0.43b0; extra == "telemetry" | runtime |
prometheus-clientEnvironment{
"extras": "",
"marker": "extra == \"telemetry\"",
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | prometheus-client<1.0,>=0.17.1; extra == "telemetry" | runtime |
httpxEnvironment{
"extras": "",
"marker": "extra == \"httpx\"",
"requires_python": "<4.0,>=3.10",
"evaluation": "NOT_EVALUATED"
} | httpx<1.0,>=0.25.0; extra == "httpx" | runtime |
bdist_wheel · 63.01 KB · Python py3
sdist · 47.69 KB · Python source
Observed since 21 Oct, 10:30 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:44584ffaaf44eea4bd4df8a42e6ec8ad2a9c40830da4437ca9e3bfa68f82d1ce