Skip to content

Commit 321ab75

Browse files
authored
chore: fix integration tests (#49)
1 parent c22a2aa commit 321ab75

14 files changed

Lines changed: 108 additions & 115 deletions

.env.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
POETRY=poetry
22
POETRY_PYTHON=python
3+
4+
# For integration tests
5+
DIAL_URL=dial-url
6+
DIAL_API_KEY=dial-api-key
7+
DIAL_MODEL=gpt-5.2

.markdownlint.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"MD013": false,
3+
"MD033": false
4+
}

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@
2323
"files.insertFinalNewline": true,
2424
"files.trimFinalNewlines": true,
2525
"files.trimTrailingWhitespace": true,
26+
"python-envs.defaultEnvManager": "ms-python.python:poetry",
27+
"python-envs.defaultPackageManager": "ms-python.python:poetry",
2628
}

README.md

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,55 @@
1515

1616
- [Usage](#usage)
1717
- [Authentication](#authentication)
18-
- [API Keys](#api-keys)
19-
- [Bearer Token](#bearer-token)
18+
- [API Keys](#api-keys)
19+
- [Bearer Token](#bearer-token)
2020
- [Lifecycle Management](#lifecycle-management)
2121
- [Deployments](#deployments)
22-
- [List Deployments](#list-deployments)
23-
- [Get Deployment by Id](#get-deployment-by-id)
24-
- [Get Deployment Configuration](#get-deployment-configuration)
25-
- [Make Chat Completions Requests](#make-completions-requests)
26-
- [Without Streaming](#without-streaming)
27-
- [With Streaming](#with-streaming)
22+
- [List Deployments](#list-deployments)
23+
- [Get Deployment by Id](#get-deployment-by-id)
24+
- [Get Deployment Configuration](#get-deployment-configuration)
25+
- [Make Chat Completions Requests](#make-chat-completions-requests)
26+
- [Without Streaming](#without-streaming)
27+
- [With Streaming](#with-streaming)
2828
- [Working with Files](#working-with-files)
29-
- [Working with URLs](#working-with-urls)
30-
- [Uploading Files](#uploading-files)
31-
- [Downloading Files](#downloading-files)
32-
- [Deleting Files](#deleting-files)
33-
- [Accessing Metadata](#accessing-metadata)
29+
- [Working with URLs](#working-with-urls)
30+
- [Uploading Files](#uploading-files)
31+
- [Downloading Files](#downloading-files)
32+
- [Deleting Files](#deleting-files)
33+
- [Moving and Copying Files](#moving-and-copying-files)
34+
- [Accessing Metadata](#accessing-metadata)
3435
- [Prompts](#prompts)
35-
- [Get Prompt](#get-prompt)
36-
- [Get Prompt Metadata](#get-prompt-metadata)
36+
- [Save Prompt](#save-prompt)
37+
- [Get Prompt](#get-prompt)
38+
- [Get Prompt Metadata](#get-prompt-metadata)
39+
- [Delete Prompt](#delete-prompt)
3740
- [Applications](#applications)
38-
- [List Applications](#list-applications)
39-
- [Get Application by Id](#get-application-by-id)
41+
- [List Applications](#list-applications)
42+
- [Get Application by Id](#get-application-by-id)
4043
- [Models](#models)
41-
- [Get Model by Name](#get-model-by-name)
44+
- [Get Model by Name](#get-model-by-name)
4245
- [User](#user)
43-
- [Get Authenticated User Info](#get-authenticated-user-info)
46+
- [Get Authenticated User Info](#get-authenticated-user-info)
4447
- [Toolsets](#toolsets)
45-
- [Get Toolset by Id](#get-toolset-by-id)
48+
- [Get Toolset by Id](#get-toolset-by-id)
4649
- [Resource Permissions](#resource-permissions)
47-
- [Grant Permissions](#grant-permissions)
50+
- [Grant Permissions](#grant-permissions)
4851
- [Client Channel](#client-channel)
49-
- [Sign In to Toolsets](#sign-in-to-toolsets)
52+
- [Sign In to Toolsets](#sign-in-to-toolsets)
5053
- [Client Pool](#client-pool)
51-
- [Synchronous Client Pool](#synchronous-client-pool)
52-
- [Asynchronous Client Pool](#asynchronous-client-pool)
54+
- [Synchronous Client Pool](#synchronous-client-pool)
55+
- [Asynchronous Client Pool](#asynchronous-client-pool)
5356
- [Development](#development)
5457
- [Pre-requisites](#pre-requisites)
5558
- [Setup](#setup)
56-
- [Main commands](#main-commands)
5759
- [Git hooks](#git-hooks)
60+
- [Main commands](#main-commands)
61+
- [Integration tests](#integration-tests)
5862

5963
## Usage
6064

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

6569
### Authentication
@@ -284,7 +288,7 @@ The response is a plain `dict` whose shape is entirely deployment-specific:
284288
}
285289
```
286290

287-
### Make Completions Requests
291+
### Make Chat Completions Requests
288292

289293
#### Without Streaming
290294

@@ -466,8 +470,8 @@ ChatCompletionChunk(
466470

467471
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.
468472

469-
* Use `client.my_files_home()` to upload a file into your bucket in the AI DIAL storage.
470-
* Use `await async_client.my_files_home()` to get the URL of your bucket and then use it to upload files.
473+
- Use `client.my_files_home()` to upload a file into your bucket in the AI DIAL storage.
474+
- Use `await async_client.my_files_home()` to get the URL of your bucket and then use it to upload files.
471475

472476
The following example demonstrates how you can use the path-like object returned by `my_files_home()` function:
473477

@@ -602,7 +606,6 @@ await result.awrite_to("./some-local-file.txt")
602606

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

605-
606609
```python
607610
await sync_client.files.delete(
608611
url=sync_client.my_files_home() / "relative_folder/my-file.txt"
@@ -1095,7 +1098,6 @@ second_client = client_pool.create_client(
10951098
)
10961099
```
10971100

1098-
10991101
## Development
11001102

11011103
To set up the development environment and run the project, follow the instructions below.
@@ -1106,18 +1108,21 @@ The following tools are required to work with the project:
11061108

11071109
1. `Make`
11081110
2. `Python 3.10`
1109-
3. `Poetry 2.*`. Installation guidance can be found [here](https://python-poetry.org/docs/#installation)
1111+
3. `Poetry 2.*`. See the [Poetry installation guide](https://python-poetry.org/docs/#installation)
11101112

11111113
### Setup
11121114

11131115
1. Create `.env` file in the root of the project. Copy `.env.template` file data to the `.env` and customize the values
11141116
if needed. You can customize python and poetry locations.
11151117
2. Create and activate virtual environment
1118+
11161119
```bash
11171120
make init_env
11181121
source .venv/bin/activate
11191122
```
1123+
11201124
3. Install dependencies
1125+
11211126
```bash
11221127
make install
11231128
```
@@ -1147,3 +1152,13 @@ make install_git_hooks
11471152
| `make integration_test` | Run integration tests |
11481153
| `make coverage` | Generate test coverage report |
11491154
| `make help` | Show available commands |
1155+
1156+
### Integration tests
1157+
1158+
`make integration_test` runs against a real DIAL deployment and requires the following environment variables:
1159+
1160+
| Variable | Description |
1161+
|----------------|----------------------------------------------------|
1162+
| `DIAL_URL` | Base URL of the DIAL Core service |
1163+
| `DIAL_API_KEY` | API key used to authenticate requests in DIAL Core |
1164+
| `DIAL_MODEL` | Name of a chat model deployment to run tests with |
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,24 @@
1111
@pytest.fixture
1212
def dial_url() -> str:
1313
url = os.getenv("DIAL_URL")
14-
assert url
14+
assert url, "DIAL_URL environment variable is not set"
1515
return url
1616

1717

1818
@pytest.fixture
1919
def dial_api_key() -> str:
2020
api_key = os.getenv("DIAL_API_KEY")
21-
assert api_key
21+
assert api_key, "DIAL_API_KEY environment variable is not set"
2222
return api_key
2323

2424

25+
@pytest.fixture
26+
def dial_model() -> str:
27+
model = os.getenv("DIAL_MODEL")
28+
assert model, "DIAL_MODEL environment variable is not set"
29+
return model
30+
31+
2532
@pytest.fixture
2633
def sync_client(dial_url, dial_api_key):
2734
return Dial(base_url=dial_url, api_key=dial_api_key)
@@ -32,15 +39,6 @@ def async_client(dial_url, dial_api_key):
3239
return AsyncDial(base_url=dial_url, api_key=dial_api_key)
3340

3441

35-
@pytest.fixture
36-
def test_deployment(sync_client: Dial) -> str:
37-
deployments = sync_client.deployments.list()
38-
assert len(deployments)
39-
deployment = next(d for d in deployments if d.id.startswith("gpt-"))
40-
assert deployment
41-
return deployment.id
42-
43-
4442
@pytest.fixture
4543
def absent_test_file(sync_client):
4644
def _save_delete_file(p):

tests/integration/test_async_completions.py

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@
22

33
from aidial_client import AsyncDial
44
from aidial_client._exception import DialException
5-
from tests.integration.fixtures import * # noqa
65

76

87
@pytest.mark.asyncio
9-
async def test_async_default_api_version(
10-
async_client: AsyncDial,
11-
dial_url: str,
12-
dial_api_key: str,
13-
test_deployment: str,
8+
async def test_async_missing_api_version_raises(
9+
async_client: AsyncDial, dial_model: str
1410
):
1511
with pytest.raises(DialException):
1612
await async_client.chat.completions.create(
17-
deployment_name="gpt-35-turbo",
13+
deployment_name=dial_model,
1814
stream=False,
1915
messages=[
2016
{
@@ -23,13 +19,19 @@ async def test_async_default_api_version(
2319
}
2420
],
2521
)
22+
23+
24+
@pytest.mark.asyncio
25+
async def test_async_client_default_api_version(
26+
dial_url: str, dial_api_key: str, dial_model: str
27+
):
2628
client_with_default_api_version = AsyncDial(
2729
base_url=dial_url,
2830
api_key=dial_api_key,
2931
api_version="2024-02-15-preview",
3032
)
3133
await client_with_default_api_version.chat.completions.create(
32-
deployment_name=test_deployment,
34+
deployment_name=dial_model,
3335
stream=False,
3436
messages=[
3537
{
@@ -42,10 +44,10 @@ async def test_async_default_api_version(
4244

4345
@pytest.mark.asyncio
4446
async def test_completions_without_streaming(
45-
async_client: AsyncDial, test_deployment: str
47+
async_client: AsyncDial, dial_model: str
4648
):
4749
completion = await async_client.chat.completions.create(
48-
deployment_name=test_deployment,
50+
deployment_name=dial_model,
4951
stream=False,
5052
messages=[
5153
{
@@ -70,13 +72,11 @@ async def test_completions_without_streaming(
7072

7173

7274
@pytest.mark.asyncio
73-
async def test_completions_with_streaming(async_client: AsyncDial):
74-
deployments = await async_client.deployments.list()
75-
assert len(deployments)
76-
deployment = next(d for d in deployments if d.id.startswith("gpt-"))
77-
assert deployment
75+
async def test_completions_with_streaming(
76+
async_client: AsyncDial, dial_model: str
77+
):
7878
completion = await async_client.chat.completions.create(
79-
deployment_name=deployment.id,
79+
deployment_name=dial_model,
8080
stream=True,
8181
messages=[
8282
{
@@ -105,24 +105,3 @@ async def test_completions_with_streaming(async_client: AsyncDial):
105105
last_chunk.usage.completion_tokens + last_chunk.usage.prompt_tokens
106106
== last_chunk.usage.total_tokens
107107
)
108-
109-
110-
@pytest.mark.asyncio
111-
async def test_error_during_streaming(
112-
async_client: AsyncDial, test_deployment: str
113-
):
114-
completion = await async_client.chat.completions.create(
115-
deployment_name=test_deployment,
116-
stream=True,
117-
messages=[
118-
{
119-
"role": "system",
120-
"content": "2+3=",
121-
}
122-
],
123-
max_tokens=20,
124-
api_version="2024-02-15-preview",
125-
)
126-
127-
async for chunk in completion:
128-
print(chunk)

tests/integration/test_async_files.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from aidial_client import AsyncDial, DialException
66
from aidial_client._exception import EtagMismatchError
77
from aidial_client.types.metadata import FileItem
8-
from tests.integration.fixtures import * # type: ignore # noqa
98

109
current_file_path = os.path.abspath(__file__)
1110
file_name = "test-file-async"

tests/integration/test_async_prompts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from aidial_client._exception import EtagMismatchError, ResourceNotFoundError
88
from aidial_client.types.metadata import PromptItem
99
from aidial_client.types.prompt import Prompt
10-
from tests.integration.fixtures import * # type: ignore # noqa
1110

1211
PROMPT_FOLDER = "test-folder-artifacts"
1312

0 commit comments

Comments
 (0)