| 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | # All rights reserved. |
| 3 | # |
| 4 | # This source code is licensed under the terms described in the LICENSE file in |
| 5 | # the root directory of this source tree. |
| 6 | |
| 7 | from typing import Union |
| 8 | |
| 9 | from .config import InferenceAPIImplConfig, InferenceEndpointImplConfig, TGIImplConfig |
| 10 | from .tgi import InferenceAPIAdapter, InferenceEndpointAdapter, TGIAdapter |
| 11 | |
| 12 | |
| 13 | async def get_adapter_impl( |
| 14 | config: Union[InferenceAPIImplConfig, InferenceEndpointImplConfig, TGIImplConfig], |
| 15 | _deps, |
| 16 | ): |
| 17 | if isinstance(config, TGIImplConfig): |
| 18 | impl = TGIAdapter() |
| 19 | elif isinstance(config, InferenceAPIImplConfig): |
| 20 | impl = InferenceAPIAdapter() |
| 21 | elif isinstance(config, InferenceEndpointImplConfig): |
| 22 | impl = InferenceEndpointAdapter() |
| 23 | else: |
| 24 | raise ValueError( |
| 25 | f"Invalid configuration. Expected 'TGIAdapter', 'InferenceAPIImplConfig' or 'InferenceEndpointImplConfig'. Got {type(config)}." |
| 26 | ) |
| 27 | |
| 28 | await impl.initialize(config) |
| 29 | return impl |