Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
POETRY=poetry
POETRY_PYTHON=python
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
secrets: inherit
with:
python-version: "3.10"
poetry-version: "1.8.5"
poetry-version: "2.3.2"
code-checks-python-versions: '["3.10", "3.11", "3.12", "3.13"]'
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
secrets: inherit
with:
python-version: "3.10"
poetry-version: "1.8.5"
poetry-version: "2.3.2"
code-checks-python-versions: '["3.10", "3.11", "3.12", "3.13"]'
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
VENV_DIR ?= .venv
POETRY ?= $(VENV_DIR)/bin/poetry
POETRY_VERSION ?= 1.8.5
POETRY ?= poetry
POETRY_PYTHON ?= python

.PHONY: all init_env install clean lint format test spell_check

-include .env
export

all: build

init_env:
python -m venv $(VENV_DIR)
$(VENV_DIR)/bin/pip install poetry==$(POETRY_VERSION) --quiet
$(POETRY) env use $(POETRY_PYTHON)

install: init_env
$(POETRY) install
Expand Down
151 changes: 107 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,52 @@
# AI DIAL Client (Python)

## Table of Contents

- [Authentication](#authentication)
- [API Keys](#api-keys)
- [Bearer Token](#bearer-token)
- [List Deployments](#list-deployments)
- [Make Chat Completions Requests](#make-completions-requests)
- [Without Streaming](#without-streaming)
- [With Streaming](#with-streaming)
- [Working with Files](#working-with-files)
- [Working with URLs](#working-with-urls)
- [Uploading Files](#uploading-files)
- [Downloading Files](#downloading-files)
- [Deleting Files](#deleting-files)
- [Accessing Metadata](#accessing-metadata)
- [Applications](#applications)
- [List Applications](#list-applications)
- [Get Application by Id](#get-application-by-id)
- [Client Pool](#client-pool)
- [Synchronous Client Pool](#synchronous-client-pool)
- [Asynchronous Client Pool](#asynchronous-client-pool)

## Authentication

### API Keys
<h1 align="center">
AI DIAL Client (Python)
</h1>
<p align="center">
<p align="center">
<a href="https://dialx.ai/">
<img src="https://dialx.ai/logo/dialx_logo.svg" alt="About DIALX">
</a>
</p>
<h4 align="center">
<a href="https://discord.gg/ukzj9U9tEe">
<img src="https://img.shields.io/static/v1?label=DIALX%20Community%20on&message=Discord&color=blue&logo=Discord&style=flat-square" alt="Discord">
</a>
</h4>

- [Usage](#usage)
- [Authentication](#authentication)
- [API Keys](#api-keys)
- [Bearer Token](#bearer-token)
- [List Deployments](#list-deployments)
- [Make Chat Completions Requests](#make-completions-requests)
- [Without Streaming](#without-streaming)
- [With Streaming](#with-streaming)
- [Working with Files](#working-with-files)
- [Working with URLs](#working-with-urls)
- [Uploading Files](#uploading-files)
- [Downloading Files](#downloading-files)
- [Deleting Files](#deleting-files)
- [Accessing Metadata](#accessing-metadata)
- [Applications](#applications)
- [List Applications](#list-applications)
- [Get Application by Id](#get-application-by-id)
- [Client Pool](#client-pool)
- [Synchronous Client Pool](#synchronous-client-pool)
- [Asynchronous Client Pool](#asynchronous-client-pool)
- [Development](#development)
- [Pre-requisites](#pre-requisites)
- [Setup](#setup)
- [Main commands](#main-commands)

## Usage

This section outlines how to use the AI DIAL Python client to interact with the DIAL Core API.
It covers authentication methods, making chat completion requests, working with files, managing applications,
and utilizing client pools for efficient connection management.

### Authentication

#### API Keys

For authentication with an API key, pass it during the client initialization:

Expand Down Expand Up @@ -66,7 +88,7 @@ async_dial_client = AsyncDial(
)
```

### Bearer Token
#### Bearer Token

You can use a Bearer Token for a token-based authentication of API calls. Client instances will use it to construct the `Authorization` header when making requests:

Expand Down Expand Up @@ -115,7 +137,7 @@ dial_client = Dial(
)
```

## List Deployments
### List Deployments

If you want to get a list of available deployments, use `client.deployments.list()` or method:

Expand All @@ -128,9 +150,9 @@ If you want to get a list of available deployments, use `client.deployments.list
]
```

## Make Completions Requests
### Make Completions Requests

### Without Streaming
#### Without Streaming

Synchronous:

Expand Down Expand Up @@ -203,7 +225,7 @@ ChatCompletionResponse(
)
```

### With Streaming
#### With Streaming

Synchronous:

Expand Down Expand Up @@ -304,9 +326,9 @@ ChatCompletionChunk(
)
```

## Working with Files
### Working with Files

### Working with URLs
#### Working with URLs

Files are AI DIAL resources that operate with URL-like objects. Use `pathlib.PurePosixPath` or `str` to create to create new URL-like objects or to get a `string` representation of them.

Expand Down Expand Up @@ -341,7 +363,7 @@ sync_client.files.upload(url=absolute_url, ...)

**Note**, that an invalid URL provided to the function, will raise an `InvalidDialURLException` exception.

### Uploading Files
#### Uploading Files

Use `upload()` to add files into your storage bucket:

Expand All @@ -367,7 +389,7 @@ sync_client.files.upload(
)
```

### Downloading Files
#### Downloading Files

Use `download()` to download files from your storage bucket:

Expand Down Expand Up @@ -406,7 +428,7 @@ result.write_to("./some-local-file.txt")
await result.awrite_to("./some-local-file.txt")
```

### Deleting Files
#### Deleting Files

Use `delete()` to remove files from your storage bucket:

Expand All @@ -421,7 +443,7 @@ await async_client.files.delete(
)
```

### Accessing Metadata
#### Accessing Metadata

Use `metadata()` to access metadata of a file:

Expand Down Expand Up @@ -450,9 +472,9 @@ FileMetadata(
)
```

## Applications
### Applications

### List Applications
#### List Applications

To get a list of your DIAL applications:

Expand Down Expand Up @@ -501,7 +523,7 @@ As a result, you will receive a list of `Application` objects:
]
```

### Get Application by Id
#### Get Application by Id

You can get your DIAL applications by their Ids:

Expand All @@ -514,11 +536,11 @@ application = await async_client.application.get("app_id")

As a result, you will receive a list of `Application` objects. Refer to the [previous example](#list-applications).

## Client Pool
### Client Pool

When you need to create multiple DIAL clients and wish to enhance performance by reusing the HTTP connection for the same DIAL instance, consider using synchronous and asynchronous **client pools**.

### Synchronous Client Pool
#### Synchronous Client Pool

```python
from aidial_client import DialClientPool
Expand All @@ -534,7 +556,7 @@ second_client = client_pool.create_client(
)
```

### Asynchronous Client Pool
#### Asynchronous Client Pool

```python
from dial_client import (
Expand All @@ -551,3 +573,44 @@ second_client = client_pool.create_client(
base_url="https://your-dial-instance.com", bearer_token="your-bearer-token"
)
```


## Development

To set up the development environment and run the project, follow the instructions below.

### Pre-requisites

The following tools are required to work with the project:

1. `Make`
2. `Python 3.10`
3. `Poetry 2.*`. Installation guidance can be found [here](https://python-poetry.org/docs/#installation)

### Setup

1. Create `.env` file in the root of the project. Copy `.env.template` file data to the `.env` and customize the values
if needed. You can customize python and poetry locations.
2. Create and activate virtual environment
```bash
make init_env
source .venv/bin/activate
```
3. Install dependencies
```bash
make install
```

### Main commands

| Command | Description |
|-------------------------|-----------------------------------------------|
| `make install` | Install virtual environment and dependencies |
| `make build` | Build the package |
| `make clean` | Clean virtual environment and build artifacts |
| `make lint` | Run linters |
| `make format` | Run code formatters |
| `make test` | Run tests (e.g., `make test PYTHON=3.12`) |
| `make integration_test` | Run integration tests |
| `make coverage` | Generate test coverage report |
| `make help` | Show available commands |
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 18 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
[tool.poetry]
[project]
name = "aidial-client"
version = "0.5.0rc"

description = "A Python client library for the AI DIAL API"
authors = ["EPAM RAIL <SpecialEPM-DIALDevTeam@epam.com>"]
homepage = "https://epam-rail.com"
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/epam/ai-dial-client-python"
packages = [{ include = "aidial_client" }]
license = "Apache-2.0"
requires-python = ">=3.10,<3.14"
authors = [
{ name = "DIALX", email = "SpecialEPM-DIALDevTeam@epam.com" },
]
dependencies = [
"openai>=1.1.0,<2.0.0",
"httpx>=0.25.0,<1.0",
"pydantic>=1.10,<3",
"aiofiles>=0.5.0",
]

[tool.poetry.dependencies]
python = ">=3.10,<4.0"
openai = ">=1.1.0,<2.0.0"
httpx = ">=0.25.0,<1.0"
pydantic = ">=1.10,<3"
aiofiles = ">=0.5.0"
[project.urls]
Homepage = "https://dialx.ai"
Repository = "https://github.com/epam/ai-dial-client-python"

[tool.setuptools]
packages = ["aidial_client"]
[tool.poetry]
packages = [{ include = "aidial_client" }]

[build-system]
requires = ["poetry-core>=1.0.0"]
requires = ["poetry-core>=2.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.group.test.dependencies]
Expand Down
Loading