Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
fadf2ae
initial release, with chat completions, files, and limited apps API …
Oct 8, 2024
5a24d97
update lockfile, try to fix pipeline
Oct 8, 2024
67bb3ae
fix makefile, one more attempt to fix pipeline
Oct 8, 2024
c67a419
fix ort pipeline
Oct 8, 2024
37586e5
add new account to code owners
Oct 8, 2024
c646f81
fix ort one more time
Oct 8, 2024
1fcc22b
fixes due to pr comments
Oct 8, 2024
863adb3
remove examples from ort
Oct 8, 2024
4e6d38d
Fix typing of FileContent
Oct 11, 2024
398caf2
remove typing ignore for files
Oct 11, 2024
8a26c63
add aiofiles parametrization for tests
Oct 11, 2024
7d50314
refactor auth function/naming, use assert never for unreachable
Oct 11, 2024
ecb5f4c
One more minor refactor of auth
Oct 11, 2024
d5c2bd0
refactor auth one more time, refactor client interface
Oct 11, 2024
82d83eb
refactor my_bucket for clients
Oct 11, 2024
293c116
Remove redundant cast
Oct 11, 2024
cedac60
fix for appdata return type
Oct 11, 2024
374ebb5
Another bunch of refactor for helpers
Oct 11, 2024
7de45fe
Bunch of refactoring, fix unit tests
Oct 11, 2024
1a7edd7
More refactoring
Oct 11, 2024
199b8ad
remove dead code
Oct 11, 2024
5e261c2
another naming refactor
Oct 11, 2024
6b146bc
Remove formatting error as chunk during streaming
Oct 11, 2024
878184e
Remove formatting error as chunk during streaming (forgotten part)
Oct 11, 2024
1f18bb8
Minor refactor
Oct 11, 2024
8f7f911
Refactor, rename exceptions with `error` postfix
Oct 11, 2024
41b225c
Minor linter fix
Oct 11, 2024
5d6df56
Refactoring for metadata type, avoid pydantic warnings
Oct 11, 2024
b7406e3
Fix compatibility with pydantic v2
Oct 11, 2024
58d0757
Minor fix
Oct 11, 2024
6f46d09
rework storage resource parser
Oct 11, 2024
86e68e4
Fix test case, when url is like `/files...`, add unit test for that
Oct 11, 2024
3aa5b6a
Minor refactor
Oct 11, 2024
3c54eb3
Minor refactor
Oct 11, 2024
646abf3
naming refactor
Oct 11, 2024
6b74f0c
refactor of deployments, test fix
Oct 11, 2024
fe8218a
One more interface change for deployments - remove `get_raw`
Oct 11, 2024
a082db2
Minor comment fix
Oct 11, 2024
b2a03ec
fix integration tests (`deployment.get()`)
Oct 11, 2024
c63070e
Bump github workflow
Oct 11, 2024
945a360
Fix linter
Oct 11, 2024
bd3b409
forgotten commit - relax aiofiles dependency
Oct 11, 2024
ef57a54
update poetry lock
Oct 11, 2024
b437cd1
add test for attachments
Oct 11, 2024
88a200a
relax aiofiles dependency even more
Oct 11, 2024
fbeb565
update noxfile to test lower version of aiofiles
Oct 11, 2024
ae84bb0
update noxfile one more time, remove few typing ignores
Oct 11, 2024
436e07e
refactor appdata for client
Oct 11, 2024
d38844e
narrow down allowed link in storage resource parser
Oct 11, 2024
b49005b
naming refactor
Oct 11, 2024
0b22a77
add test for metadata
Oct 11, 2024
bc127ca
Fix metadata, improve tests
Oct 11, 2024
d2d1e95
Fix naming of internal http client
Oct 14, 2024
71822a1
Replace docstring with just comment
Oct 14, 2024
64deba4
Refactor _my_appdata property, use NOT_GIVEN for it
Oct 14, 2024
21acd43
Fix client pool test
Oct 14, 2024
1457f55
Refine storage resource helpers, introduce new exception `NotDialURLE…
Oct 14, 2024
3d35f36
More refactoring, fix minor bug with storage resource
Oct 14, 2024
65da79b
fix ort ignore rule
Oct 14, 2024
90867df
Minor refactor
Oct 14, 2024
ca193a0
Refactor error naming
Oct 14, 2024
b2da8a6
refactor - make is_directory private
Oct 14, 2024
3839de3
Refactor docstring
Oct 14, 2024
6d3ad48
Refactor: capitalize `url` to `URL` in error message
Oct 14, 2024
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
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# E203 whitespace before ':' (triggered on list slices like xs[i : i + 5])
# E704 multiple statements on one line (def)
ignore = E501, W503, E203, E704
max-line-length = 80
exclude =
.git,
.tmp,
Expand Down
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
* @adubovik
* @adubovik @roman-romanov-o
/.github/ @nepalevov @alexey-ban
2 changes: 1 addition & 1 deletion .github/workflows/pr-title-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ on:

jobs:
pr-title-check:
uses: epam/ai-dial-ci/.github/workflows/pr-title-check.yml@1.9.0
uses: epam/ai-dial-ci/.github/workflows/pr-title-check.yml@1.9.1
secrets:
ACTIONS_BOT_TOKEN: ${{ secrets.ACTIONS_BOT_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
run_tests:
uses: epam/ai-dial-ci/.github/workflows/python_package_pr.yml@1.9.0
uses: epam/ai-dial-ci/.github/workflows/python_package_pr.yml@1.9.1
secrets: inherit
with:
python_version: 3.8
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
release:
uses: epam/ai-dial-ci/.github/workflows/python_package_release.yml@1.9.0
uses: epam/ai-dial-ci/.github/workflows/python_package_release.yml@1.9.1
secrets: inherit
with:
python_version: 3.8
Expand Down
9 changes: 3 additions & 6 deletions .ort.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
---
excludes:
paths:
- pattern: "examples/**"
reason: "EXAMPLE_OF"
scopes:
- pattern: "lint"
reason: "DEV_DEPENDENCY_OF"
Expand All @@ -12,9 +9,9 @@ excludes:
comment: "Packages for testing only."
resolutions:
rule_violations:
- message: ".*PyPI::httpcore:0\\.18\\.0.*"
- message: ".*PyPI::httpcore:1\\.0\\.5.*"
reason: "CANT_FIX_EXCEPTION"
comment: "BSD 3-Clause New or Revised License: https://github.com/encode/httpcore/blob/0.18.0/LICENSE.md"
- message: ".*PyPI::httpx:0\\.25\\.0.*"
comment: "BSD 3-Clause New or Revised License: https://github.com/encode/httpcore/blob/1.0.5/LICENSE.md"
- message: ".*PyPI::httpx:0\\.25\\.2.*"
reason: "CANT_FIX_EXCEPTION"
comment: "BSD 3-Clause New or Revised License: https://github.com/encode/httpx/blob/0.25.0/LICENSE.md"
34 changes: 18 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
all: build
.PHONY: all install clean lint format test spell_check

install:
poetry install --all-extras
all: build

build: install
poetry build

clean:
rm -rf $$(poetry env info --path)
rm -rf .nox
rm -rf .pytest_cache
rm -rf dist
find . -type d -name __pycache__ | xargs rm -r
install:
poetry install

publish: build
poetry publish -u __token__ -p ${PYPI_TOKEN} --skip-existing
clean:
poetry run clean
poetry env remove --all

lint: install
poetry run nox -s lint
Expand All @@ -25,14 +21,20 @@ format: install
test: install
poetry run nox -s test $(if $(PYTHON),--python=$(PYTHON),)

integration_test: install
poetry run nox -s integration_test $(if $(PYTHON),--python=$(PYTHON),)

coverage: install
poetry run nox -s coverage

publish: build
poetry publish -u __token__ -p ${PYPI_TOKEN} --skip-existing

help:
@echo '===================='
@echo 'build - build the library'
@echo 'install - install virtual env and dependencies'
@echo 'clean - clean virtual env and build artifacts'
@echo 'publish - publish the library to Pypi'
@echo '-- LINTING --'
@echo 'format - run code formatters'
@echo 'lint - run linters'
@echo '-- TESTS --'
@echo 'test - run unit tests'
@echo 'test PYTHON=<python_version> - run unit tests with the specific python version'
@echo 'spell_check - run spell check'
24 changes: 24 additions & 0 deletions aidial_client/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from aidial_client._auth import AsyncAuthValue, AuthType, SyncAuthValue
from aidial_client._client import AsyncDial, Dial
from aidial_client._client_pool import AsyncDialClientPool, DialClientPool
from aidial_client._exception import (
DialException,
InvalidDialURLError,
InvalidRequestError,
ParsingDataError,
)

__all__ = [
"Dial",
"AsyncDial",
"DialClientPool",
"AsyncDialClientPool",
"AuthType",
"SyncAuthValue",
"AsyncAuthValue",
# Exceptions
Comment thread
adubovik marked this conversation as resolved.
"DialException",
"InvalidDialURLError",
"InvalidRequestError",
"ParsingDataError",
]
99 changes: 99 additions & 0 deletions aidial_client/_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
from enum import Enum
from inspect import isawaitable
from typing import (
Awaitable,
Callable,
Dict,
Optional,
Tuple,
TypeVar,
Union,
overload,
)

from typing_extensions import assert_never


class AuthType(Enum):
API_KEY = "API_KEY"
BEARER = "BEARER"


SyncAuthValue = Union[str, Callable[[], str]]
AsyncAuthValue = Union[SyncAuthValue, Callable[[], Awaitable[str]]]

AuthValueT = TypeVar(
"AuthValueT",
bound=Union[SyncAuthValue, AsyncAuthValue],
Comment thread
adubovik marked this conversation as resolved.
)


@overload
def get_auth_value(auth_value: SyncAuthValue) -> str: ...


@overload
def get_auth_value(
auth_value: AsyncAuthValue,
) -> Union[str, Awaitable[str]]: ...


def get_auth_value(
auth_value: Union[SyncAuthValue, AsyncAuthValue]
) -> Union[str, Awaitable[str]]:
if isinstance(auth_value, str):
return auth_value
elif callable(auth_value):
return auth_value()
else:
assert_never(auth_value)


async def aget_auth_value(auth_value: AsyncAuthValue) -> str:
processed_auth_value = get_auth_value(auth_value)
if isawaitable(processed_auth_value):
return await processed_auth_value
return processed_auth_value


def _get_auth_headers(auth_type: AuthType, auth_value: str) -> Dict[str, str]:
if auth_type == AuthType.API_KEY:
return {"api-key": auth_value}
elif auth_type == AuthType.BEARER:
return {"Authorization": f"Bearer {auth_value}"}
else:
assert_never(auth_type)


def get_auth_headers(
*,
auth_value: SyncAuthValue,
auth_type: AuthType,
) -> Dict[str, str]:
processed_auth_value = get_auth_value(auth_value)
return _get_auth_headers(auth_type, processed_auth_value)


async def aget_auth_headers(
auth_value: AsyncAuthValue,
auth_type: AuthType,
) -> Dict[str, str]:
processed_auth_value = await aget_auth_value(auth_value)
return _get_auth_headers(auth_type, processed_auth_value)


def process_auth(
*,
api_key: Optional[AuthValueT] = None,
bearer_token: Optional[AuthValueT] = None,
) -> Tuple[AuthType, AuthValueT]:
if api_key and bearer_token:
raise ValueError(
"Either api_key or bearer_token must be provided, but not both"
)
elif api_key:
return AuthType.API_KEY, api_key
elif bearer_token:
return AuthType.BEARER, bearer_token
else:
raise ValueError("Either api_key or bearer_token must be provided")
Loading