llama-stack-api 0.4.3__py3-none-any.whl → 0.5.0rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. llama_stack_api/__init__.py +1100 -0
  2. llama_stack_api/admin/__init__.py +45 -0
  3. llama_stack_api/admin/api.py +72 -0
  4. llama_stack_api/admin/fastapi_routes.py +117 -0
  5. llama_stack_api/admin/models.py +113 -0
  6. llama_stack_api/agents/__init__.py +38 -0
  7. llama_stack_api/agents/api.py +52 -0
  8. llama_stack_api/agents/fastapi_routes.py +268 -0
  9. llama_stack_api/agents/models.py +181 -0
  10. llama_stack_api/batches/__init__.py +40 -0
  11. llama_stack_api/batches/api.py +53 -0
  12. llama_stack_api/batches/fastapi_routes.py +113 -0
  13. llama_stack_api/batches/models.py +78 -0
  14. llama_stack_api/benchmarks/__init__.py +43 -0
  15. llama_stack_api/benchmarks/api.py +39 -0
  16. llama_stack_api/benchmarks/fastapi_routes.py +109 -0
  17. llama_stack_api/benchmarks/models.py +109 -0
  18. llama_stack_api/common/__init__.py +5 -0
  19. llama_stack_api/common/content_types.py +101 -0
  20. llama_stack_api/common/errors.py +110 -0
  21. llama_stack_api/common/job_types.py +38 -0
  22. llama_stack_api/common/responses.py +77 -0
  23. llama_stack_api/common/training_types.py +47 -0
  24. llama_stack_api/common/type_system.py +146 -0
  25. llama_stack_api/connectors/__init__.py +38 -0
  26. llama_stack_api/connectors/api.py +50 -0
  27. llama_stack_api/connectors/fastapi_routes.py +103 -0
  28. llama_stack_api/connectors/models.py +103 -0
  29. llama_stack_api/conversations/__init__.py +61 -0
  30. llama_stack_api/conversations/api.py +44 -0
  31. llama_stack_api/conversations/fastapi_routes.py +177 -0
  32. llama_stack_api/conversations/models.py +245 -0
  33. llama_stack_api/datasetio/__init__.py +34 -0
  34. llama_stack_api/datasetio/api.py +42 -0
  35. llama_stack_api/datasetio/fastapi_routes.py +94 -0
  36. llama_stack_api/datasetio/models.py +48 -0
  37. llama_stack_api/datasets/__init__.py +61 -0
  38. llama_stack_api/datasets/api.py +35 -0
  39. llama_stack_api/datasets/fastapi_routes.py +104 -0
  40. llama_stack_api/datasets/models.py +152 -0
  41. llama_stack_api/datatypes.py +373 -0
  42. llama_stack_api/eval/__init__.py +55 -0
  43. llama_stack_api/eval/api.py +51 -0
  44. llama_stack_api/eval/compat.py +300 -0
  45. llama_stack_api/eval/fastapi_routes.py +126 -0
  46. llama_stack_api/eval/models.py +141 -0
  47. llama_stack_api/file_processors/__init__.py +27 -0
  48. llama_stack_api/file_processors/api.py +64 -0
  49. llama_stack_api/file_processors/fastapi_routes.py +78 -0
  50. llama_stack_api/file_processors/models.py +42 -0
  51. llama_stack_api/files/__init__.py +35 -0
  52. llama_stack_api/files/api.py +51 -0
  53. llama_stack_api/files/fastapi_routes.py +124 -0
  54. llama_stack_api/files/models.py +107 -0
  55. llama_stack_api/inference/__init__.py +207 -0
  56. llama_stack_api/inference/api.py +93 -0
  57. llama_stack_api/inference/fastapi_routes.py +243 -0
  58. llama_stack_api/inference/models.py +1035 -0
  59. llama_stack_api/inspect_api/__init__.py +37 -0
  60. llama_stack_api/inspect_api/api.py +25 -0
  61. llama_stack_api/inspect_api/fastapi_routes.py +76 -0
  62. llama_stack_api/inspect_api/models.py +28 -0
  63. llama_stack_api/internal/__init__.py +9 -0
  64. llama_stack_api/internal/kvstore.py +28 -0
  65. llama_stack_api/internal/sqlstore.py +81 -0
  66. llama_stack_api/models/__init__.py +47 -0
  67. llama_stack_api/models/api.py +38 -0
  68. llama_stack_api/models/fastapi_routes.py +104 -0
  69. llama_stack_api/models/models.py +157 -0
  70. llama_stack_api/openai_responses.py +1494 -0
  71. llama_stack_api/post_training/__init__.py +73 -0
  72. llama_stack_api/post_training/api.py +36 -0
  73. llama_stack_api/post_training/fastapi_routes.py +116 -0
  74. llama_stack_api/post_training/models.py +339 -0
  75. llama_stack_api/prompts/__init__.py +47 -0
  76. llama_stack_api/prompts/api.py +44 -0
  77. llama_stack_api/prompts/fastapi_routes.py +163 -0
  78. llama_stack_api/prompts/models.py +177 -0
  79. llama_stack_api/providers/__init__.py +33 -0
  80. llama_stack_api/providers/api.py +16 -0
  81. llama_stack_api/providers/fastapi_routes.py +57 -0
  82. llama_stack_api/providers/models.py +24 -0
  83. llama_stack_api/rag_tool.py +168 -0
  84. llama_stack_api/resource.py +36 -0
  85. llama_stack_api/router_utils.py +160 -0
  86. llama_stack_api/safety/__init__.py +37 -0
  87. llama_stack_api/safety/api.py +29 -0
  88. llama_stack_api/safety/datatypes.py +83 -0
  89. llama_stack_api/safety/fastapi_routes.py +55 -0
  90. llama_stack_api/safety/models.py +38 -0
  91. llama_stack_api/schema_utils.py +251 -0
  92. llama_stack_api/scoring/__init__.py +66 -0
  93. llama_stack_api/scoring/api.py +35 -0
  94. llama_stack_api/scoring/fastapi_routes.py +67 -0
  95. llama_stack_api/scoring/models.py +81 -0
  96. llama_stack_api/scoring_functions/__init__.py +50 -0
  97. llama_stack_api/scoring_functions/api.py +39 -0
  98. llama_stack_api/scoring_functions/fastapi_routes.py +108 -0
  99. llama_stack_api/scoring_functions/models.py +214 -0
  100. llama_stack_api/shields/__init__.py +41 -0
  101. llama_stack_api/shields/api.py +39 -0
  102. llama_stack_api/shields/fastapi_routes.py +104 -0
  103. llama_stack_api/shields/models.py +74 -0
  104. llama_stack_api/tools.py +226 -0
  105. llama_stack_api/validators.py +46 -0
  106. llama_stack_api/vector_io/__init__.py +88 -0
  107. llama_stack_api/vector_io/api.py +234 -0
  108. llama_stack_api/vector_io/fastapi_routes.py +447 -0
  109. llama_stack_api/vector_io/models.py +663 -0
  110. llama_stack_api/vector_stores.py +53 -0
  111. llama_stack_api/version.py +9 -0
  112. {llama_stack_api-0.4.3.dist-info → llama_stack_api-0.5.0rc1.dist-info}/METADATA +1 -1
  113. llama_stack_api-0.5.0rc1.dist-info/RECORD +115 -0
  114. llama_stack_api-0.5.0rc1.dist-info/top_level.txt +1 -0
  115. llama_stack_api-0.4.3.dist-info/RECORD +0 -4
  116. llama_stack_api-0.4.3.dist-info/top_level.txt +0 -1
  117. {llama_stack_api-0.4.3.dist-info → llama_stack_api-0.5.0rc1.dist-info}/WHEEL +0 -0
@@ -0,0 +1,61 @@
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
+ """Datasets API protocol and models.
8
+
9
+ This module contains the Datasets protocol definition.
10
+ Pydantic models are defined in llama_stack_api.datasets.models.
11
+ The FastAPI router is defined in llama_stack_api.datasets.fastapi_routes.
12
+ """
13
+
14
+ # Import fastapi_routes for router factory access
15
+ from . import fastapi_routes
16
+
17
+ # Import new protocol for FastAPI router
18
+ from .api import Datasets
19
+
20
+ # Import models for re-export
21
+ from .models import (
22
+ CommonDatasetFields,
23
+ Dataset,
24
+ DatasetPurpose,
25
+ DatasetType,
26
+ DataSource,
27
+ GetDatasetRequest,
28
+ ListDatasetsResponse,
29
+ RegisterDatasetRequest,
30
+ RowsDataSource,
31
+ UnregisterDatasetRequest,
32
+ URIDataSource,
33
+ )
34
+
35
+
36
+ # Define DatasetInput for backward compatibility
37
+ class DatasetInput(CommonDatasetFields):
38
+ """Input parameters for dataset operations.
39
+
40
+ :param dataset_id: Unique identifier for the dataset
41
+ """
42
+
43
+ dataset_id: str
44
+
45
+
46
+ __all__ = [
47
+ "Datasets",
48
+ "Dataset",
49
+ "CommonDatasetFields",
50
+ "DatasetPurpose",
51
+ "DataSource",
52
+ "DatasetInput",
53
+ "DatasetType",
54
+ "RowsDataSource",
55
+ "URIDataSource",
56
+ "ListDatasetsResponse",
57
+ "RegisterDatasetRequest",
58
+ "GetDatasetRequest",
59
+ "UnregisterDatasetRequest",
60
+ "fastapi_routes",
61
+ ]
@@ -0,0 +1,35 @@
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
+ """Datasets API protocol definition.
8
+
9
+ This module contains the Datasets protocol definition.
10
+ Pydantic models are defined in llama_stack_api.datasets.models.
11
+ The FastAPI router is defined in llama_stack_api.datasets.fastapi_routes.
12
+ """
13
+
14
+ from typing import Protocol, runtime_checkable
15
+
16
+ from .models import (
17
+ Dataset,
18
+ GetDatasetRequest,
19
+ ListDatasetsResponse,
20
+ RegisterDatasetRequest,
21
+ UnregisterDatasetRequest,
22
+ )
23
+
24
+
25
+ @runtime_checkable
26
+ class Datasets(Protocol):
27
+ """Protocol for dataset management operations."""
28
+
29
+ async def register_dataset(self, request: RegisterDatasetRequest) -> Dataset: ...
30
+
31
+ async def get_dataset(self, request: GetDatasetRequest) -> Dataset: ...
32
+
33
+ async def list_datasets(self) -> ListDatasetsResponse: ...
34
+
35
+ async def unregister_dataset(self, request: UnregisterDatasetRequest) -> None: ...
@@ -0,0 +1,104 @@
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
+ """FastAPI router for the Datasets API.
8
+
9
+ This module defines the FastAPI router for the Datasets API using standard
10
+ FastAPI route decorators.
11
+ """
12
+
13
+ from typing import Annotated
14
+
15
+ from fastapi import APIRouter, Body, Depends
16
+
17
+ from llama_stack_api.router_utils import create_path_dependency, standard_responses
18
+ from llama_stack_api.version import LLAMA_STACK_API_V1BETA
19
+
20
+ from .api import Datasets
21
+ from .models import (
22
+ Dataset,
23
+ GetDatasetRequest,
24
+ ListDatasetsResponse,
25
+ RegisterDatasetRequest,
26
+ UnregisterDatasetRequest,
27
+ )
28
+
29
+ # Path parameter dependencies for single-field models
30
+ get_dataset_request = create_path_dependency(GetDatasetRequest)
31
+ unregister_dataset_request = create_path_dependency(UnregisterDatasetRequest)
32
+
33
+
34
+ def create_router(impl: Datasets) -> APIRouter:
35
+ """Create a FastAPI router for the Datasets API.
36
+
37
+ Args:
38
+ impl: The Datasets implementation instance
39
+
40
+ Returns:
41
+ APIRouter configured for the Datasets API
42
+ """
43
+ router = APIRouter(
44
+ prefix=f"/{LLAMA_STACK_API_V1BETA}",
45
+ tags=["Datasets"],
46
+ responses=standard_responses,
47
+ )
48
+
49
+ @router.post(
50
+ "/datasets",
51
+ response_model=Dataset,
52
+ summary="Register a new dataset.",
53
+ description="Register a new dataset.",
54
+ responses={
55
+ 200: {"description": "The registered dataset object."},
56
+ },
57
+ deprecated=True,
58
+ )
59
+ async def register_dataset(
60
+ request: Annotated[RegisterDatasetRequest, Body(...)],
61
+ ) -> Dataset:
62
+ return await impl.register_dataset(request)
63
+
64
+ @router.get(
65
+ "/datasets/{dataset_id:path}",
66
+ response_model=Dataset,
67
+ summary="Get a dataset by its ID.",
68
+ description="Get a dataset by its ID.",
69
+ responses={
70
+ 200: {"description": "The dataset object."},
71
+ },
72
+ )
73
+ async def get_dataset(
74
+ request: Annotated[GetDatasetRequest, Depends(get_dataset_request)],
75
+ ) -> Dataset:
76
+ return await impl.get_dataset(request)
77
+
78
+ @router.get(
79
+ "/datasets",
80
+ response_model=ListDatasetsResponse,
81
+ summary="List all datasets.",
82
+ description="List all datasets.",
83
+ responses={
84
+ 200: {"description": "A list of dataset objects."},
85
+ },
86
+ )
87
+ async def list_datasets() -> ListDatasetsResponse:
88
+ return await impl.list_datasets()
89
+
90
+ @router.delete(
91
+ "/datasets/{dataset_id:path}",
92
+ summary="Unregister a dataset by its ID.",
93
+ description="Unregister a dataset by its ID.",
94
+ responses={
95
+ 200: {"description": "The dataset was successfully unregistered."},
96
+ },
97
+ deprecated=True,
98
+ )
99
+ async def unregister_dataset(
100
+ request: Annotated[UnregisterDatasetRequest, Depends(unregister_dataset_request)],
101
+ ) -> None:
102
+ return await impl.unregister_dataset(request)
103
+
104
+ return router
@@ -0,0 +1,152 @@
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
+ """Pydantic models for Datasets API requests and responses.
8
+
9
+ This module defines the request and response models for the Datasets API
10
+ using Pydantic with Field descriptions for OpenAPI schema generation.
11
+ """
12
+
13
+ from enum import Enum, StrEnum
14
+ from typing import Annotated, Any, Literal
15
+
16
+ from pydantic import BaseModel, Field
17
+
18
+ from llama_stack_api.resource import Resource, ResourceType
19
+ from llama_stack_api.schema_utils import json_schema_type, register_schema
20
+
21
+
22
+ class DatasetPurpose(StrEnum):
23
+ """Purpose of the dataset. Each purpose has a required input data schema."""
24
+
25
+ post_training_messages = "post-training/messages"
26
+ """The dataset contains messages used for post-training."""
27
+ eval_question_answer = "eval/question-answer"
28
+ """The dataset contains a question column and an answer column."""
29
+ eval_messages_answer = "eval/messages-answer"
30
+ """The dataset contains a messages column with list of messages and an answer column."""
31
+
32
+
33
+ class DatasetType(Enum):
34
+ """Type of the dataset source."""
35
+
36
+ uri = "uri"
37
+ """The dataset can be obtained from a URI."""
38
+ rows = "rows"
39
+ """The dataset is stored in rows."""
40
+
41
+
42
+ @json_schema_type
43
+ class URIDataSource(BaseModel):
44
+ """A dataset that can be obtained from a URI."""
45
+
46
+ type: Literal["uri"] = Field(default="uri", description="The type of data source.")
47
+ uri: str = Field(
48
+ ...,
49
+ description='The dataset can be obtained from a URI. E.g. "https://mywebsite.com/mydata.jsonl", "lsfs://mydata.jsonl", "data:csv;base64,{base64_content}"',
50
+ )
51
+
52
+
53
+ @json_schema_type
54
+ class RowsDataSource(BaseModel):
55
+ """A dataset stored in rows."""
56
+
57
+ type: Literal["rows"] = Field(default="rows", description="The type of data source.")
58
+ rows: list[dict[str, Any]] = Field(
59
+ ...,
60
+ description='The dataset is stored in rows. E.g. [{"messages": [{"role": "user", "content": "Hello, world!"}, {"role": "assistant", "content": "Hello, world!"}]}]',
61
+ )
62
+
63
+
64
+ DataSource = Annotated[
65
+ URIDataSource | RowsDataSource,
66
+ Field(discriminator="type"),
67
+ ]
68
+ register_schema(DataSource, name="DataSource")
69
+
70
+
71
+ class CommonDatasetFields(BaseModel):
72
+ """Common fields for a dataset."""
73
+
74
+ purpose: DatasetPurpose = Field(..., description="Purpose of the dataset indicating its intended use")
75
+ source: DataSource = Field(..., description="Data source configuration for the dataset")
76
+ metadata: dict[str, Any] = Field(
77
+ default_factory=dict,
78
+ description="Any additional metadata for this dataset",
79
+ )
80
+
81
+
82
+ @json_schema_type
83
+ class Dataset(CommonDatasetFields, Resource):
84
+ """Dataset resource for storing and accessing training or evaluation data."""
85
+
86
+ type: Literal[ResourceType.dataset] = Field(
87
+ default=ResourceType.dataset,
88
+ description="Type of resource, always 'dataset' for datasets",
89
+ )
90
+
91
+ @property
92
+ def dataset_id(self) -> str:
93
+ return self.identifier
94
+
95
+ @property
96
+ def provider_dataset_id(self) -> str | None:
97
+ return self.provider_resource_id
98
+
99
+
100
+ @json_schema_type
101
+ class ListDatasetsResponse(BaseModel):
102
+ """Response from listing datasets."""
103
+
104
+ data: list[Dataset] = Field(..., description="List of datasets")
105
+
106
+
107
+ # Request models for each endpoint
108
+
109
+
110
+ @json_schema_type
111
+ class RegisterDatasetRequest(BaseModel):
112
+ """Request model for registering a dataset."""
113
+
114
+ purpose: DatasetPurpose = Field(..., description="The purpose of the dataset.")
115
+ source: DataSource = Field(..., description="The data source of the dataset.")
116
+ metadata: dict[str, Any] | None = Field(
117
+ default=None,
118
+ description="The metadata for the dataset.",
119
+ )
120
+ dataset_id: str | None = Field(
121
+ default=None,
122
+ description="The ID of the dataset. If not provided, an ID will be generated.",
123
+ )
124
+
125
+
126
+ @json_schema_type
127
+ class GetDatasetRequest(BaseModel):
128
+ """Request model for getting a dataset by ID."""
129
+
130
+ dataset_id: str = Field(..., description="The ID of the dataset to get.")
131
+
132
+
133
+ @json_schema_type
134
+ class UnregisterDatasetRequest(BaseModel):
135
+ """Request model for unregistering a dataset."""
136
+
137
+ dataset_id: str = Field(..., description="The ID of the dataset to unregister.")
138
+
139
+
140
+ __all__ = [
141
+ "CommonDatasetFields",
142
+ "Dataset",
143
+ "DatasetPurpose",
144
+ "DatasetType",
145
+ "DataSource",
146
+ "RowsDataSource",
147
+ "URIDataSource",
148
+ "ListDatasetsResponse",
149
+ "RegisterDatasetRequest",
150
+ "GetDatasetRequest",
151
+ "UnregisterDatasetRequest",
152
+ ]