llama-stack-api 0.4.4__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 (79) hide show
  1. llama_stack_api/__init__.py +175 -20
  2. llama_stack_api/agents/__init__.py +38 -0
  3. llama_stack_api/agents/api.py +52 -0
  4. llama_stack_api/agents/fastapi_routes.py +268 -0
  5. llama_stack_api/agents/models.py +181 -0
  6. llama_stack_api/common/errors.py +15 -0
  7. llama_stack_api/connectors/__init__.py +38 -0
  8. llama_stack_api/connectors/api.py +50 -0
  9. llama_stack_api/connectors/fastapi_routes.py +103 -0
  10. llama_stack_api/connectors/models.py +103 -0
  11. llama_stack_api/conversations/__init__.py +61 -0
  12. llama_stack_api/conversations/api.py +44 -0
  13. llama_stack_api/conversations/fastapi_routes.py +177 -0
  14. llama_stack_api/conversations/models.py +245 -0
  15. llama_stack_api/datasetio/__init__.py +34 -0
  16. llama_stack_api/datasetio/api.py +42 -0
  17. llama_stack_api/datasetio/fastapi_routes.py +94 -0
  18. llama_stack_api/datasetio/models.py +48 -0
  19. llama_stack_api/eval/__init__.py +55 -0
  20. llama_stack_api/eval/api.py +51 -0
  21. llama_stack_api/eval/compat.py +300 -0
  22. llama_stack_api/eval/fastapi_routes.py +126 -0
  23. llama_stack_api/eval/models.py +141 -0
  24. llama_stack_api/inference/__init__.py +207 -0
  25. llama_stack_api/inference/api.py +93 -0
  26. llama_stack_api/inference/fastapi_routes.py +243 -0
  27. llama_stack_api/inference/models.py +1035 -0
  28. llama_stack_api/models/__init__.py +47 -0
  29. llama_stack_api/models/api.py +38 -0
  30. llama_stack_api/models/fastapi_routes.py +104 -0
  31. llama_stack_api/{models.py → models/models.py} +65 -79
  32. llama_stack_api/openai_responses.py +32 -6
  33. llama_stack_api/post_training/__init__.py +73 -0
  34. llama_stack_api/post_training/api.py +36 -0
  35. llama_stack_api/post_training/fastapi_routes.py +116 -0
  36. llama_stack_api/{post_training.py → post_training/models.py} +55 -86
  37. llama_stack_api/prompts/__init__.py +47 -0
  38. llama_stack_api/prompts/api.py +44 -0
  39. llama_stack_api/prompts/fastapi_routes.py +163 -0
  40. llama_stack_api/prompts/models.py +177 -0
  41. llama_stack_api/resource.py +0 -1
  42. llama_stack_api/safety/__init__.py +37 -0
  43. llama_stack_api/safety/api.py +29 -0
  44. llama_stack_api/safety/datatypes.py +83 -0
  45. llama_stack_api/safety/fastapi_routes.py +55 -0
  46. llama_stack_api/safety/models.py +38 -0
  47. llama_stack_api/schema_utils.py +47 -4
  48. llama_stack_api/scoring/__init__.py +66 -0
  49. llama_stack_api/scoring/api.py +35 -0
  50. llama_stack_api/scoring/fastapi_routes.py +67 -0
  51. llama_stack_api/scoring/models.py +81 -0
  52. llama_stack_api/scoring_functions/__init__.py +50 -0
  53. llama_stack_api/scoring_functions/api.py +39 -0
  54. llama_stack_api/scoring_functions/fastapi_routes.py +108 -0
  55. llama_stack_api/{scoring_functions.py → scoring_functions/models.py} +67 -64
  56. llama_stack_api/shields/__init__.py +41 -0
  57. llama_stack_api/shields/api.py +39 -0
  58. llama_stack_api/shields/fastapi_routes.py +104 -0
  59. llama_stack_api/shields/models.py +74 -0
  60. llama_stack_api/validators.py +46 -0
  61. llama_stack_api/vector_io/__init__.py +88 -0
  62. llama_stack_api/vector_io/api.py +234 -0
  63. llama_stack_api/vector_io/fastapi_routes.py +447 -0
  64. llama_stack_api/{vector_io.py → vector_io/models.py} +99 -377
  65. {llama_stack_api-0.4.4.dist-info → llama_stack_api-0.5.0rc1.dist-info}/METADATA +1 -1
  66. llama_stack_api-0.5.0rc1.dist-info/RECORD +115 -0
  67. llama_stack_api/agents.py +0 -173
  68. llama_stack_api/connectors.py +0 -146
  69. llama_stack_api/conversations.py +0 -270
  70. llama_stack_api/datasetio.py +0 -55
  71. llama_stack_api/eval.py +0 -137
  72. llama_stack_api/inference.py +0 -1169
  73. llama_stack_api/prompts.py +0 -203
  74. llama_stack_api/safety.py +0 -132
  75. llama_stack_api/scoring.py +0 -93
  76. llama_stack_api/shields.py +0 -93
  77. llama_stack_api-0.4.4.dist-info/RECORD +0 -70
  78. {llama_stack_api-0.4.4.dist-info → llama_stack_api-0.5.0rc1.dist-info}/WHEEL +0 -0
  79. {llama_stack_api-0.4.4.dist-info → llama_stack_api-0.5.0rc1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,74 @@
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 Shields API requests and responses.
8
+
9
+ This module defines the request and response models for the Shields API
10
+ using Pydantic with Field descriptions for OpenAPI schema generation.
11
+ """
12
+
13
+ from typing import Any, Literal
14
+
15
+ from pydantic import BaseModel, Field
16
+
17
+ from llama_stack_api.resource import Resource, ResourceType
18
+ from llama_stack_api.schema_utils import json_schema_type
19
+
20
+
21
+ class CommonShieldFields(BaseModel):
22
+ params: dict[str, Any] | None = None
23
+
24
+
25
+ @json_schema_type
26
+ class Shield(CommonShieldFields, Resource):
27
+ """A safety shield resource that can be used to check content."""
28
+
29
+ type: Literal[ResourceType.shield] = ResourceType.shield
30
+
31
+ @property
32
+ def shield_id(self) -> str:
33
+ return self.identifier
34
+
35
+ @property
36
+ def provider_shield_id(self) -> str | None:
37
+ return self.provider_resource_id
38
+
39
+
40
+ class ShieldInput(CommonShieldFields):
41
+ shield_id: str
42
+ provider_id: str | None = None
43
+ provider_shield_id: str | None = None
44
+
45
+
46
+ @json_schema_type
47
+ class ListShieldsResponse(BaseModel):
48
+ """Response containing a list of all shields."""
49
+
50
+ data: list[Shield] = Field(..., description="List of shield objects")
51
+
52
+
53
+ @json_schema_type
54
+ class GetShieldRequest(BaseModel):
55
+ """Request model for getting a shield by identifier."""
56
+
57
+ identifier: str = Field(..., description="The identifier of the shield to get.")
58
+
59
+
60
+ @json_schema_type
61
+ class RegisterShieldRequest(BaseModel):
62
+ """Request model for registering a shield."""
63
+
64
+ shield_id: str = Field(..., description="The identifier of the shield to register.")
65
+ provider_shield_id: str | None = Field(None, description="The identifier of the shield in the provider.")
66
+ provider_id: str | None = Field(None, description="The identifier of the provider.")
67
+ params: dict[str, Any] | None = Field(None, description="The parameters of the shield.")
68
+
69
+
70
+ @json_schema_type
71
+ class UnregisterShieldRequest(BaseModel):
72
+ """Request model for unregistering a shield."""
73
+
74
+ identifier: str = Field(..., description="The identifier of the shield to unregister.")
@@ -0,0 +1,46 @@
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
+ """Validators for API request parameters.
8
+
9
+ This module contains validation functions used by providers to validate
10
+ request parameters that cannot be easily validated using Pydantic alone.
11
+ """
12
+
13
+ from llama_stack_api.inference import OpenAIEmbeddingsRequestWithExtraBody
14
+
15
+
16
+ def validate_embeddings_input_is_text(
17
+ params: OpenAIEmbeddingsRequestWithExtraBody,
18
+ ) -> None:
19
+ """
20
+ Validate that embeddings input contains only text strings, not token arrays.
21
+
22
+ Token arrays (list[int] and list[list[int]]) are a newer OpenAI feature
23
+ that is not universally supported across all embedding providers. This
24
+ validator should be called by providers that only support text input (str or list[str]).
25
+
26
+ :param params: The OpenAI embeddings request parameters
27
+ :raises ValueError: If input contains token arrays
28
+ """
29
+ # Valid: string input
30
+ if isinstance(params.input, str):
31
+ return
32
+
33
+ # Valid: list of strings
34
+ if isinstance(params.input, list) and isinstance(params.input[0], str):
35
+ return
36
+
37
+ # If we get here, input is a token array (list[int] or list[list[int]])
38
+ raise ValueError(
39
+ f"Model '{params.model}' does not support token arrays. "
40
+ f"Please provide text input as a string or list of strings instead."
41
+ )
42
+
43
+
44
+ __all__ = [
45
+ "validate_embeddings_input_is_text",
46
+ ]
@@ -0,0 +1,88 @@
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
+ """VectorIO API module.
8
+
9
+ This module provides the VectorIO API for vector database operations.
10
+ Protocol definitions are in api.py, Pydantic models are in models.py,
11
+ and FastAPI routes are in fastapi_routes.py.
12
+ """
13
+
14
+ # Re-export Protocol classes from api.py
15
+ from . import fastapi_routes
16
+ from .api import VectorIO, VectorStoreTable
17
+
18
+ # Re-export all Pydantic models from models.py
19
+ from .models import (
20
+ Chunk,
21
+ ChunkMetadata,
22
+ EmbeddedChunk,
23
+ OpenAICreateVectorStoreFileBatchRequestWithExtraBody,
24
+ OpenAICreateVectorStoreRequestWithExtraBody,
25
+ QueryChunksResponse,
26
+ SearchRankingOptions,
27
+ VectorStoreChunkingStrategy,
28
+ VectorStoreChunkingStrategyAuto,
29
+ VectorStoreChunkingStrategyStatic,
30
+ VectorStoreChunkingStrategyStaticConfig,
31
+ VectorStoreContent,
32
+ VectorStoreCreateRequest,
33
+ VectorStoreDeleteResponse,
34
+ VectorStoreFileAttributes,
35
+ VectorStoreFileBatchObject,
36
+ VectorStoreFileContentResponse,
37
+ VectorStoreFileCounts,
38
+ VectorStoreFileDeleteResponse,
39
+ VectorStoreFileLastError,
40
+ VectorStoreFileObject,
41
+ VectorStoreFilesListInBatchResponse,
42
+ VectorStoreFileStatus,
43
+ VectorStoreListFilesResponse,
44
+ VectorStoreListResponse,
45
+ VectorStoreModifyRequest,
46
+ VectorStoreObject,
47
+ VectorStoreSearchRequest,
48
+ VectorStoreSearchResponse,
49
+ VectorStoreSearchResponsePage,
50
+ )
51
+
52
+ __all__ = [
53
+ # Protocol classes
54
+ "VectorIO",
55
+ "VectorStoreTable",
56
+ # Pydantic models
57
+ "Chunk",
58
+ "ChunkMetadata",
59
+ "EmbeddedChunk",
60
+ "OpenAICreateVectorStoreFileBatchRequestWithExtraBody",
61
+ "OpenAICreateVectorStoreRequestWithExtraBody",
62
+ "QueryChunksResponse",
63
+ "SearchRankingOptions",
64
+ "VectorStoreChunkingStrategy",
65
+ "VectorStoreChunkingStrategyAuto",
66
+ "VectorStoreChunkingStrategyStatic",
67
+ "VectorStoreChunkingStrategyStaticConfig",
68
+ "VectorStoreContent",
69
+ "VectorStoreCreateRequest",
70
+ "VectorStoreDeleteResponse",
71
+ "VectorStoreFileAttributes",
72
+ "VectorStoreFileBatchObject",
73
+ "VectorStoreFileContentResponse",
74
+ "VectorStoreFileCounts",
75
+ "VectorStoreFileDeleteResponse",
76
+ "VectorStoreFileLastError",
77
+ "VectorStoreFileObject",
78
+ "VectorStoreFileStatus",
79
+ "VectorStoreFilesListInBatchResponse",
80
+ "VectorStoreListFilesResponse",
81
+ "VectorStoreListResponse",
82
+ "VectorStoreModifyRequest",
83
+ "VectorStoreObject",
84
+ "VectorStoreSearchRequest",
85
+ "VectorStoreSearchResponse",
86
+ "VectorStoreSearchResponsePage",
87
+ "fastapi_routes",
88
+ ]
@@ -0,0 +1,234 @@
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
+ """VectorIO API protocol definition.
8
+
9
+ This module contains the VectorIO protocol definition.
10
+ Pydantic models are defined in llama_stack_api.vector_io.models.
11
+ The FastAPI router is defined in llama_stack_api.vector_io.fastapi_routes.
12
+ """
13
+
14
+ from typing import Annotated, Any, Protocol, runtime_checkable
15
+
16
+ from fastapi import Body, Query
17
+
18
+ from llama_stack_api.inference import InterleavedContent
19
+ from llama_stack_api.vector_stores import VectorStore
20
+
21
+ from .models import (
22
+ EmbeddedChunk,
23
+ OpenAICreateVectorStoreFileBatchRequestWithExtraBody,
24
+ OpenAICreateVectorStoreRequestWithExtraBody,
25
+ QueryChunksResponse,
26
+ SearchRankingOptions,
27
+ VectorStoreChunkingStrategy,
28
+ VectorStoreDeleteResponse,
29
+ VectorStoreFileBatchObject,
30
+ VectorStoreFileContentResponse,
31
+ VectorStoreFileDeleteResponse,
32
+ VectorStoreFileObject,
33
+ VectorStoreFilesListInBatchResponse,
34
+ VectorStoreFileStatus,
35
+ VectorStoreListFilesResponse,
36
+ VectorStoreListResponse,
37
+ VectorStoreObject,
38
+ VectorStoreSearchResponsePage,
39
+ )
40
+
41
+
42
+ class VectorStoreTable(Protocol):
43
+ def get_vector_store(self, vector_store_id: str) -> VectorStore | None: ...
44
+
45
+
46
+ @runtime_checkable
47
+ class VectorIO(Protocol):
48
+ vector_store_table: VectorStoreTable | None = None
49
+
50
+ # this will just block now until chunks are inserted, but it should
51
+ # probably return a Job instance which can be polled for completion
52
+ async def insert_chunks(
53
+ self,
54
+ vector_store_id: str,
55
+ chunks: list[EmbeddedChunk],
56
+ ttl_seconds: int | None = None,
57
+ ) -> None:
58
+ """Insert embedded chunks into a vector database."""
59
+ ...
60
+
61
+ async def query_chunks(
62
+ self,
63
+ vector_store_id: str,
64
+ query: InterleavedContent,
65
+ params: dict[str, Any] | None = None,
66
+ ) -> QueryChunksResponse:
67
+ """Query chunks from a vector database."""
68
+ ...
69
+
70
+ # OpenAI Vector Stores API endpoints
71
+ async def openai_create_vector_store(
72
+ self,
73
+ params: Annotated[OpenAICreateVectorStoreRequestWithExtraBody, Body(...)],
74
+ ) -> VectorStoreObject:
75
+ """Creates a vector store.
76
+
77
+ Generate an OpenAI-compatible vector store with the given parameters.
78
+ """
79
+ ...
80
+
81
+ async def openai_list_vector_stores(
82
+ self,
83
+ limit: int | None = 20,
84
+ order: str | None = "desc",
85
+ after: str | None = None,
86
+ before: str | None = None,
87
+ ) -> VectorStoreListResponse:
88
+ """Returns a list of vector stores."""
89
+ ...
90
+
91
+ async def openai_retrieve_vector_store(
92
+ self,
93
+ vector_store_id: str,
94
+ ) -> VectorStoreObject:
95
+ """Retrieves a vector store."""
96
+ ...
97
+
98
+ async def openai_update_vector_store(
99
+ self,
100
+ vector_store_id: str,
101
+ name: str | None = None,
102
+ expires_after: dict[str, Any] | None = None,
103
+ metadata: dict[str, Any] | None = None,
104
+ ) -> VectorStoreObject:
105
+ """Updates a vector store."""
106
+ ...
107
+
108
+ async def openai_delete_vector_store(
109
+ self,
110
+ vector_store_id: str,
111
+ ) -> VectorStoreDeleteResponse:
112
+ """Delete a vector store."""
113
+ ...
114
+
115
+ async def openai_search_vector_store(
116
+ self,
117
+ vector_store_id: str,
118
+ query: str | list[str],
119
+ filters: dict[str, Any] | None = None,
120
+ max_num_results: int | None = 10,
121
+ ranking_options: SearchRankingOptions | None = None,
122
+ rewrite_query: bool | None = False,
123
+ search_mode: (
124
+ str | None
125
+ ) = "vector", # Using str instead of Literal due to OpenAPI schema generator limitations
126
+ ) -> VectorStoreSearchResponsePage:
127
+ """Search for chunks in a vector store.
128
+
129
+ Searches a vector store for relevant chunks based on a query and optional file attribute filters.
130
+ """
131
+ ...
132
+
133
+ async def openai_attach_file_to_vector_store(
134
+ self,
135
+ vector_store_id: str,
136
+ file_id: str,
137
+ attributes: dict[str, Any] | None = None,
138
+ chunking_strategy: VectorStoreChunkingStrategy | None = None,
139
+ ) -> VectorStoreFileObject:
140
+ """Attach a file to a vector store."""
141
+ ...
142
+
143
+ async def openai_list_files_in_vector_store(
144
+ self,
145
+ vector_store_id: str,
146
+ limit: int | None = 20,
147
+ order: str | None = "desc",
148
+ after: str | None = None,
149
+ before: str | None = None,
150
+ filter: VectorStoreFileStatus | None = None,
151
+ ) -> VectorStoreListFilesResponse:
152
+ """List files in a vector store."""
153
+ ...
154
+
155
+ async def openai_retrieve_vector_store_file(
156
+ self,
157
+ vector_store_id: str,
158
+ file_id: str,
159
+ ) -> VectorStoreFileObject:
160
+ """Retrieves a vector store file."""
161
+ ...
162
+
163
+ async def openai_retrieve_vector_store_file_contents(
164
+ self,
165
+ vector_store_id: str,
166
+ file_id: str,
167
+ include_embeddings: Annotated[bool | None, Query()] = False,
168
+ include_metadata: Annotated[bool | None, Query()] = False,
169
+ ) -> VectorStoreFileContentResponse:
170
+ """Retrieves the contents of a vector store file."""
171
+ ...
172
+
173
+ async def openai_update_vector_store_file(
174
+ self,
175
+ vector_store_id: str,
176
+ file_id: str,
177
+ attributes: dict[str, Any],
178
+ ) -> VectorStoreFileObject:
179
+ """Updates a vector store file."""
180
+ ...
181
+
182
+ async def openai_delete_vector_store_file(
183
+ self,
184
+ vector_store_id: str,
185
+ file_id: str,
186
+ ) -> VectorStoreFileDeleteResponse:
187
+ """Delete a vector store file."""
188
+ ...
189
+
190
+ async def openai_create_vector_store_file_batch(
191
+ self,
192
+ vector_store_id: str,
193
+ params: Annotated[OpenAICreateVectorStoreFileBatchRequestWithExtraBody, Body(...)],
194
+ ) -> VectorStoreFileBatchObject:
195
+ """Create a vector store file batch.
196
+
197
+ Generate an OpenAI-compatible vector store file batch for the given vector store.
198
+ """
199
+ ...
200
+
201
+ async def openai_retrieve_vector_store_file_batch(
202
+ self,
203
+ batch_id: str,
204
+ vector_store_id: str,
205
+ ) -> VectorStoreFileBatchObject:
206
+ """Retrieve a vector store file batch."""
207
+ ...
208
+
209
+ async def openai_list_files_in_vector_store_file_batch(
210
+ self,
211
+ batch_id: str,
212
+ vector_store_id: str,
213
+ after: str | None = None,
214
+ before: str | None = None,
215
+ filter: str | None = None,
216
+ limit: int | None = 20,
217
+ order: str | None = "desc",
218
+ ) -> VectorStoreFilesListInBatchResponse:
219
+ """Returns a list of vector store files in a batch."""
220
+ ...
221
+
222
+ async def openai_cancel_vector_store_file_batch(
223
+ self,
224
+ batch_id: str,
225
+ vector_store_id: str,
226
+ ) -> VectorStoreFileBatchObject:
227
+ """Cancels a vector store file batch."""
228
+ ...
229
+
230
+
231
+ __all__ = [
232
+ "VectorIO",
233
+ "VectorStoreTable",
234
+ ]