Skip to content
Open
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
4 changes: 4 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"MD013": false,
"MD033": false
}
66 changes: 40 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
# AI DIAL Client (Python)
<h1 align="center">
DIAL Client SDK
</h1>
<p align="center">
<p align="center">
<a href="https://dialx.ai/">
<img src="https://dialx.ai/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>

- [AI DIAL Client (Python)](#ai-dial-client-python)
- [Authentication](#authentication)
- [API Keys](#api-keys)
- [Bearer Token](#bearer-token)
- [List Deployments](#list-deployments)
- [Make 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)

## 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)
# AI DIAL Client (Python)

## Authentication

Expand Down Expand Up @@ -139,7 +153,7 @@ Synchronous:
client = Dial(api_key="your-api-key", base_url="https://your-dial-instance.com")

completion = client.chat.completions.create(
deployment_name="gpt-35-turbo",
deployment_name="gpt-4o",
stream=False,
messages=[
{
Expand All @@ -159,7 +173,7 @@ async_client = AsyncDial(
api_key="your-api-key", base_url="https://your-dial-instance.com"
)
completion = await async_client.chat.completions.create(
deployment_name="gpt-35-turbo",
deployment_name="gpt-4o",
stream=False,
messages=[
{
Expand Down Expand Up @@ -212,7 +226,7 @@ Synchronous:
client = Dial(api_key="your-api-key", base_url="https://your-dial-instance.com")

completion = client.chat.completions.create(
deployment_name="gpt-35-turbo",
deployment_name="gpt-4o",
# Specify a stream parameter
stream=True,
messages=[
Expand All @@ -235,7 +249,7 @@ async_client = AsyncDial(
api_key="your-api-key", base_url="https://your-dial-instance.com"
)
completion = await async_client.chat.completions.create(
deployment_name="gpt-35-turbo",
deployment_name="gpt-4o",
# Specify a stream parameter
stream=True,
messages=[
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os

INTEGRATION_TEST_DEPLOYMENT_NAME = os.getenv(
"INTEGRATION_TEST_DEPLOYMENT_NAME", "gpt-4o"
)
2 changes: 1 addition & 1 deletion tests/integration/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def async_client(dial_url, dial_api_key):
def test_deployment(sync_client: Dial) -> str:
deployments = sync_client.deployments.list()
assert len(deployments)
deployment = next((d for d in deployments if d.id.startswith("gpt-")))
deployment = next((d for d in deployments if d.id.startswith("gpt-4o")))
assert deployment
return deployment.id

Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_async_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from aidial_client import AsyncDial
from aidial_client._exception import DialException
from tests.integration.configuration import INTEGRATION_TEST_DEPLOYMENT_NAME
from tests.integration.fixtures import * # noqa


Expand All @@ -14,7 +15,7 @@ async def test_async_default_api_version(
):
with pytest.raises(DialException):
await async_client.chat.completions.create(
deployment_name="gpt-35-turbo",
deployment_name=INTEGRATION_TEST_DEPLOYMENT_NAME,
stream=False,
messages=[
{
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/test_sync_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from aidial_client import Dial
from aidial_client._exception import DialException
from tests.integration.configuration import INTEGRATION_TEST_DEPLOYMENT_NAME
from tests.integration.fixtures import * # type: ignore # noqa


Expand Down Expand Up @@ -36,7 +37,7 @@ def test_default_api_version(
):
with pytest.raises(DialException):
sync_client.chat.completions.create(
deployment_name="gpt-35-turbo",
deployment_name=INTEGRATION_TEST_DEPLOYMENT_NAME,
stream=False,
messages=[
{
Expand All @@ -51,7 +52,7 @@ def test_default_api_version(
api_version="2024-02-15-preview",
)
client_with_default_api_version.chat.completions.create(
deployment_name="gpt-35-turbo",
deployment_name=INTEGRATION_TEST_DEPLOYMENT_NAME,
stream=False,
messages=[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from aidial_client.types.chat import ChatCompletionChunk, ToolParam
from tests.client_mock import get_async_client_mock, get_client_mock
from tests.integration.configuration import INTEGRATION_TEST_DEPLOYMENT_NAME
from tests.utils.chunks import create_mock_chunk, create_sse_data_field

_TOOL_DEFINITION: ToolParam = {
Expand Down Expand Up @@ -172,7 +173,7 @@ def test_sync_streaming_tool_call():
)

response = client.chat.completions.create(
deployment_name="gpt-35-turbo",
deployment_name=INTEGRATION_TEST_DEPLOYMENT_NAME,
messages=[{"role": "user", "content": "what's the weather in Paris?"}],
tools=[_TOOL_DEFINITION],
stream=True,
Expand All @@ -190,7 +191,7 @@ async def test_async_streaming_tool_call():
stream_chunks_mock=_STREAM_CHUNKS_MOCK,
)
response = await async_client.chat.completions.create(
deployment_name="gpt-35-turbo",
deployment_name=INTEGRATION_TEST_DEPLOYMENT_NAME,
messages=[{"role": "user", "content": "what's the weather in Paris?"}],
tools=[_TOOL_DEFINITION],
stream=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from aidial_client.types.chat import ChatCompletionChunk
from tests.client_mock import get_async_client_mock, get_client_mock
from tests.integration.configuration import INTEGRATION_TEST_DEPLOYMENT_NAME
from tests.utils.chunks import create_mock_chunk, create_sse_data_field

STREAM_CHUNKS_MOCK: List[bytes] = [
Expand Down Expand Up @@ -53,7 +54,7 @@ def test_sync_streaming():
)

response = client.chat.completions.create(
deployment_name="gpt-35-turbo",
deployment_name=INTEGRATION_TEST_DEPLOYMENT_NAME,
messages=[{"role": "user", "content": "2+3="}],
stream=True,
)
Expand All @@ -70,7 +71,7 @@ async def test_async_streaming():
stream_chunks_mock=STREAM_CHUNKS_MOCK,
)
response = await async_client.chat.completions.create(
deployment_name="gpt-35-turbo",
deployment_name=INTEGRATION_TEST_DEPLOYMENT_NAME,
messages=[{"role": "user", "content": "2+3="}],
stream=True,
)
Expand Down
4 changes: 3 additions & 1 deletion tests/utils/chunks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
from typing import Optional, Union

from tests.integration.configuration import INTEGRATION_TEST_DEPLOYMENT_NAME


def create_mock_chunk(
*,
Expand All @@ -19,7 +21,7 @@ def create_mock_chunk(
}
],
"created": 1723806872,
"model": "gpt-35-turbo",
"model": INTEGRATION_TEST_DEPLOYMENT_NAME,
"object": "chat.completion.chunk",
"system_fingerprint": None,
**({} if usage is None else {"usage": usage}),
Expand Down