Skip to content

Commit 840ad75

Browse files
authored
feat: split API and provider specs into separate llama-stack-api pkg (#3895)
# What does this PR do? Extract API definitions and provider specifications into a standalone llama-stack-api package that can be published to PyPI independently of the main llama-stack server. see: #2978 and #2978 (comment) Motivation External providers currently import from llama-stack, which overrides the installed version and causes dependency conflicts. This separation allows external providers to: - Install only the type definitions they need without server dependencies - Avoid version conflicts with the installed llama-stack package - Be versioned and released independently This enables us to re-enable external provider module tests that were previously blocked by these import conflicts. Changes - Created llama-stack-api package with minimal dependencies (pydantic, jsonschema) - Moved APIs, providers datatypes, strong_typing, and schema_utils - Updated all imports from llama_stack.* to llama_stack_api.* - Configured local editable install for development workflow - Updated linting and type-checking configuration for both packages Next Steps - Publish llama-stack-api to PyPI - Update external provider dependencies - Re-enable external provider module tests Pre-cursor PRs to this one: - #4093 - #3954 - #4064 These PRs moved key pieces _out_ of the Api pkg, limiting the scope of change here. relates to #3237 ## Test Plan Package builds successfully and can be imported independently. All pre-commit hooks pass with expected exclusions maintained. --------- Signed-off-by: Charlie Doern <cdoern@redhat.com>
1 parent ceb716b commit 840ad75

File tree

358 files changed

+2331
-1418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

358 files changed

+2331
-1418
lines changed

.github/workflows/python-build-test.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ jobs:
3030
activate-environment: true
3131
version: 0.7.6
3232

33+
- name: Build Llama Stack API package
34+
working-directory: src/llama-stack-api
35+
run: uv build
36+
3337
- name: Build Llama Stack package
34-
run: |
35-
uv build
38+
run: uv build
3639

37-
- name: Install Llama Stack package
40+
- name: Install Llama Stack package (with api stubs from local build)
3841
run: |
39-
uv pip install dist/*.whl
42+
uv pip install --find-links src/llama-stack-api/dist dist/*.whl
4043
4144
- name: Verify Llama Stack package
4245
run: |

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ repos:
4242
hooks:
4343
- id: ruff
4444
args: [ --fix ]
45-
exclude: ^src/llama_stack/strong_typing/.*$
45+
exclude: ^(src/llama_stack/strong_typing/.*|src/llama-stack-api/llama_stack_api/strong_typing/.*)$
4646
- id: ruff-format
4747

4848
- repo: https://github.com/adamchainz/blacken-docs

docs/docs/concepts/apis/external.mdx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ External APIs must expose a `available_providers()` function in their module tha
5858

5959
```python
6060
# llama_stack_api_weather/api.py
61-
from llama_stack.providers.datatypes import Api, InlineProviderSpec, ProviderSpec
61+
from llama_stack_api import Api, InlineProviderSpec, ProviderSpec
6262
6363
6464
def available_providers() -> list[ProviderSpec]:
@@ -79,7 +79,7 @@ A Protocol class like so:
7979
# llama_stack_api_weather/api.py
8080
from typing import Protocol
8181
82-
from llama_stack.schema_utils import webmethod
82+
from llama_stack_api import webmethod
8383
8484
8585
class WeatherAPI(Protocol):
@@ -151,13 +151,12 @@ __all__ = ["WeatherAPI", "available_providers"]
151151
# llama-stack-api-weather/src/llama_stack_api_weather/weather.py
152152
from typing import Protocol
153153
154-
from llama_stack.providers.datatypes import (
154+
from llama_stack_api import (
155155
Api,
156156
ProviderSpec,
157157
RemoteProviderSpec,
158+
webmethod,
158159
)
159-
from llama_stack.schema_utils import webmethod
160-
161160
162161
def available_providers() -> list[ProviderSpec]:
163162
return [

docs/docs/distributions/building_distro.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ external_providers_dir: /workspace/providers.d
6565
Inside `providers.d/custom_ollama/provider.py`, define `get_provider_spec()` so the CLI can discover dependencies:
6666

6767
```python
68-
from llama_stack.providers.datatypes import ProviderSpec
68+
from llama_stack_api.providers.datatypes import ProviderSpec
6969
7070
7171
def get_provider_spec() -> ProviderSpec:

docs/docs/providers/external/external-providers-guide.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ container_image: custom-vector-store:latest # optional
8080
All providers must contain a `get_provider_spec` function in their `provider` module. This is a standardized structure that Llama Stack expects and is necessary for getting things such as the config class. The `get_provider_spec` method returns a structure identical to the `adapter`. An example function may look like:
8181

8282
```python
83-
from llama_stack.providers.datatypes import (
83+
from llama_stack_api.providers.datatypes import (
8484
ProviderSpec,
8585
Api,
8686
RemoteProviderSpec,

docs/docs/providers/vector_io/inline_sqlite-vec.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ description: |
153153
Example using RAGQueryConfig with different search modes:
154154
155155
```python
156-
from llama_stack.apis.tools import RAGQueryConfig, RRFRanker, WeightedRanker
156+
from llama_stack_api import RAGQueryConfig, RRFRanker, WeightedRanker
157157
158158
# Vector search
159159
config = RAGQueryConfig(mode="vector", max_chunks=5)
@@ -358,7 +358,7 @@ Two ranker types are supported:
358358
Example using RAGQueryConfig with different search modes:
359359

360360
```python
361-
from llama_stack.apis.tools import RAGQueryConfig, RRFRanker, WeightedRanker
361+
from llama_stack_api import RAGQueryConfig, RRFRanker, WeightedRanker
362362

363363
# Vector search
364364
config = RAGQueryConfig(mode="vector", max_chunks=5)

docs/openapi_generator/generate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import fire
1717
import ruamel.yaml as yaml
1818

19-
from llama_stack.apis.version import LLAMA_STACK_API_V1 # noqa: E402
19+
from llama_stack_api import LLAMA_STACK_API_V1 # noqa: E402
2020
from llama_stack.core.stack import LlamaStack # noqa: E402
2121

2222
from .pyopenapi.options import Options # noqa: E402

docs/openapi_generator/pyopenapi/generator.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@
1616

1717
from fastapi import UploadFile
1818

19-
from llama_stack.apis.datatypes import Error
20-
from llama_stack.strong_typing.core import JsonType
21-
from llama_stack.strong_typing.docstring import Docstring, parse_type
22-
from llama_stack.strong_typing.inspection import (
19+
from llama_stack_api import (
20+
Docstring,
21+
Error,
22+
JsonSchemaGenerator,
23+
JsonType,
24+
Schema,
25+
SchemaOptions,
26+
get_schema_identifier,
2327
is_generic_list,
2428
is_type_optional,
2529
is_type_union,
2630
is_unwrapped_body_param,
31+
json_dump_string,
32+
object_to_json,
33+
parse_type,
34+
python_type_to_name,
35+
register_schema,
2736
unwrap_generic_list,
2837
unwrap_optional_type,
2938
unwrap_union_types,
3039
)
31-
from llama_stack.strong_typing.name import python_type_to_name
32-
from llama_stack.strong_typing.schema import (
33-
get_schema_identifier,
34-
JsonSchemaGenerator,
35-
register_schema,
36-
Schema,
37-
SchemaOptions,
38-
)
39-
from llama_stack.strong_typing.serialization import json_dump_string, object_to_json
4040
from pydantic import BaseModel
4141

4242
from .operations import (

docs/openapi_generator/pyopenapi/operations.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@
1111
from dataclasses import dataclass
1212
from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Union
1313

14-
from llama_stack.apis.version import LLAMA_STACK_API_V1, LLAMA_STACK_API_V1BETA, LLAMA_STACK_API_V1ALPHA
15-
1614
from termcolor import colored
1715

18-
from llama_stack.strong_typing.inspection import get_signature
19-
2016
from typing import get_origin, get_args
2117

2218
from fastapi import UploadFile
2319
from fastapi.params import File, Form
2420
from typing import Annotated
2521

26-
from llama_stack.schema_utils import ExtraBodyField
22+
from llama_stack_api import (
23+
ExtraBodyField,
24+
LLAMA_STACK_API_V1,
25+
LLAMA_STACK_API_V1ALPHA,
26+
LLAMA_STACK_API_V1BETA,
27+
get_signature,
28+
)
2729

2830

2931
def split_prefix(

docs/openapi_generator/pyopenapi/specification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from dataclasses import dataclass
1010
from typing import Any, ClassVar, Dict, List, Optional, Union
1111

12-
from llama_stack.strong_typing.schema import JsonType, Schema, StrictJsonType
12+
from llama_stack_api import JsonType, Schema, StrictJsonType
1313

1414
URL = str
1515

0 commit comments

Comments
 (0)