Skip to content

Commit

Permalink
another bunch of review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-romanov-o committed Dec 30, 2024
1 parent 7ce123e commit 26856d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
16 changes: 3 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,17 @@
from openai import AsyncAzureOpenAI

from aidial_adapter_openai.app import create_app
from aidial_adapter_openai.app_config import ApplicationConfig
from aidial_adapter_openai.utils.http_client import DEFAULT_TIMEOUT
from aidial_adapter_openai.utils.request import get_app_config
from tests.integration_tests.base import DeploymentConfig, TestDeployments
from tests.integration_tests.constants import TEST_DEPLOYMENTS_CONFIG_PATH
from tests.integration_tests.base import DeploymentConfig
from tests.integration_tests.constants import TEST_DEPLOYMENT_CONFIG


@pytest.fixture(scope="session")
def _app_instance():
try:
deployments_config = TestDeployments.from_config(
TEST_DEPLOYMENTS_CONFIG_PATH
)
except FileNotFoundError:
deployments_config = TestDeployments(
deployments=[], app_config=ApplicationConfig()
)

return create_app(
init_telemetry=False,
app_config=deployments_config.app_config,
app_config=TEST_DEPLOYMENT_CONFIG.app_config,
)


Expand Down
10 changes: 10 additions & 0 deletions tests/integration_tests/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
from pathlib import Path

from aidial_adapter_openai.app_config import ApplicationConfig
from aidial_adapter_openai.utils.resource import Resource
from tests.integration_tests.base import TestDeployments

CURRENT_DIR = Path(__file__).parent
SAMPLE_DOG_IMAGE_PATH = CURRENT_DIR / "images" / "dog-sample-image.png"
Expand All @@ -13,3 +15,11 @@
"INTEGRATION_TEST_DEPLOYMENTS_CONFIG_PATH",
"tests/integration_tests/integration_test_config.json",
)
try:
TEST_DEPLOYMENT_CONFIG = TestDeployments.from_config(
TEST_DEPLOYMENTS_CONFIG_PATH
)
except FileNotFoundError:
TEST_DEPLOYMENT_CONFIG = TestDeployments(
deployments=[], app_config=ApplicationConfig()
)
15 changes: 5 additions & 10 deletions tests/integration_tests/test_chat_completion.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import asyncio
import logging
import re
from typing import Generator, List

import pytest
from openai import APIError

from tests.integration_tests.base import (
TestCase,
TestDeployments,
TestSuite,
TestSuiteBuilder,
)
from tests.integration_tests.base import TestCase, TestSuite, TestSuiteBuilder
from tests.integration_tests.chat_completion_suites.text import (
text_common,
text_multi_system_messages,
text_stop_sequence,
)
from tests.integration_tests.chat_completion_suites.tools import tools_common
from tests.integration_tests.chat_completion_suites.vision import vision_common
from tests.integration_tests.constants import TEST_DEPLOYMENTS_CONFIG_PATH
from tests.integration_tests.constants import TEST_DEPLOYMENT_CONFIG
from tests.utils.openai import (
ChatCompletionResult,
ExpectedException,
Expand All @@ -32,9 +28,7 @@ def create_test_cases(
builders: List[TestSuiteBuilder],
) -> Generator[TestCase, None, None]:
for streaming in (False, True):
for deployment in TestDeployments.from_config(
TEST_DEPLOYMENTS_CONFIG_PATH
).deployments:
for deployment in TEST_DEPLOYMENT_CONFIG.deployments:
suite = TestSuite(deployment, streaming)
for builder in builders:
builder(suite)
Expand Down Expand Up @@ -78,6 +72,7 @@ async def run_chat_completion() -> ChatCompletionResult:
except APIError as e:
# Somehow, randomly through test, event loop is closing
if e.message == "Event loop is closed":
await asyncio.sleep(5)
logger.warning("Event loop is closed, retrying...")
continue
else:
Expand Down

0 comments on commit 26856d8

Please sign in to comment.