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.
- llama_stack_api/__init__.py +1100 -0
- llama_stack_api/admin/__init__.py +45 -0
- llama_stack_api/admin/api.py +72 -0
- llama_stack_api/admin/fastapi_routes.py +117 -0
- llama_stack_api/admin/models.py +113 -0
- llama_stack_api/agents/__init__.py +38 -0
- llama_stack_api/agents/api.py +52 -0
- llama_stack_api/agents/fastapi_routes.py +268 -0
- llama_stack_api/agents/models.py +181 -0
- llama_stack_api/batches/__init__.py +40 -0
- llama_stack_api/batches/api.py +53 -0
- llama_stack_api/batches/fastapi_routes.py +113 -0
- llama_stack_api/batches/models.py +78 -0
- llama_stack_api/benchmarks/__init__.py +43 -0
- llama_stack_api/benchmarks/api.py +39 -0
- llama_stack_api/benchmarks/fastapi_routes.py +109 -0
- llama_stack_api/benchmarks/models.py +109 -0
- llama_stack_api/common/__init__.py +5 -0
- llama_stack_api/common/content_types.py +101 -0
- llama_stack_api/common/errors.py +110 -0
- llama_stack_api/common/job_types.py +38 -0
- llama_stack_api/common/responses.py +77 -0
- llama_stack_api/common/training_types.py +47 -0
- llama_stack_api/common/type_system.py +146 -0
- llama_stack_api/connectors/__init__.py +38 -0
- llama_stack_api/connectors/api.py +50 -0
- llama_stack_api/connectors/fastapi_routes.py +103 -0
- llama_stack_api/connectors/models.py +103 -0
- llama_stack_api/conversations/__init__.py +61 -0
- llama_stack_api/conversations/api.py +44 -0
- llama_stack_api/conversations/fastapi_routes.py +177 -0
- llama_stack_api/conversations/models.py +245 -0
- llama_stack_api/datasetio/__init__.py +34 -0
- llama_stack_api/datasetio/api.py +42 -0
- llama_stack_api/datasetio/fastapi_routes.py +94 -0
- llama_stack_api/datasetio/models.py +48 -0
- llama_stack_api/datasets/__init__.py +61 -0
- llama_stack_api/datasets/api.py +35 -0
- llama_stack_api/datasets/fastapi_routes.py +104 -0
- llama_stack_api/datasets/models.py +152 -0
- llama_stack_api/datatypes.py +373 -0
- llama_stack_api/eval/__init__.py +55 -0
- llama_stack_api/eval/api.py +51 -0
- llama_stack_api/eval/compat.py +300 -0
- llama_stack_api/eval/fastapi_routes.py +126 -0
- llama_stack_api/eval/models.py +141 -0
- llama_stack_api/file_processors/__init__.py +27 -0
- llama_stack_api/file_processors/api.py +64 -0
- llama_stack_api/file_processors/fastapi_routes.py +78 -0
- llama_stack_api/file_processors/models.py +42 -0
- llama_stack_api/files/__init__.py +35 -0
- llama_stack_api/files/api.py +51 -0
- llama_stack_api/files/fastapi_routes.py +124 -0
- llama_stack_api/files/models.py +107 -0
- llama_stack_api/inference/__init__.py +207 -0
- llama_stack_api/inference/api.py +93 -0
- llama_stack_api/inference/fastapi_routes.py +243 -0
- llama_stack_api/inference/models.py +1035 -0
- llama_stack_api/inspect_api/__init__.py +37 -0
- llama_stack_api/inspect_api/api.py +25 -0
- llama_stack_api/inspect_api/fastapi_routes.py +76 -0
- llama_stack_api/inspect_api/models.py +28 -0
- llama_stack_api/internal/__init__.py +9 -0
- llama_stack_api/internal/kvstore.py +28 -0
- llama_stack_api/internal/sqlstore.py +81 -0
- llama_stack_api/models/__init__.py +47 -0
- llama_stack_api/models/api.py +38 -0
- llama_stack_api/models/fastapi_routes.py +104 -0
- llama_stack_api/models/models.py +157 -0
- llama_stack_api/openai_responses.py +1494 -0
- llama_stack_api/post_training/__init__.py +73 -0
- llama_stack_api/post_training/api.py +36 -0
- llama_stack_api/post_training/fastapi_routes.py +116 -0
- llama_stack_api/post_training/models.py +339 -0
- llama_stack_api/prompts/__init__.py +47 -0
- llama_stack_api/prompts/api.py +44 -0
- llama_stack_api/prompts/fastapi_routes.py +163 -0
- llama_stack_api/prompts/models.py +177 -0
- llama_stack_api/providers/__init__.py +33 -0
- llama_stack_api/providers/api.py +16 -0
- llama_stack_api/providers/fastapi_routes.py +57 -0
- llama_stack_api/providers/models.py +24 -0
- llama_stack_api/rag_tool.py +168 -0
- llama_stack_api/resource.py +36 -0
- llama_stack_api/router_utils.py +160 -0
- llama_stack_api/safety/__init__.py +37 -0
- llama_stack_api/safety/api.py +29 -0
- llama_stack_api/safety/datatypes.py +83 -0
- llama_stack_api/safety/fastapi_routes.py +55 -0
- llama_stack_api/safety/models.py +38 -0
- llama_stack_api/schema_utils.py +251 -0
- llama_stack_api/scoring/__init__.py +66 -0
- llama_stack_api/scoring/api.py +35 -0
- llama_stack_api/scoring/fastapi_routes.py +67 -0
- llama_stack_api/scoring/models.py +81 -0
- llama_stack_api/scoring_functions/__init__.py +50 -0
- llama_stack_api/scoring_functions/api.py +39 -0
- llama_stack_api/scoring_functions/fastapi_routes.py +108 -0
- llama_stack_api/scoring_functions/models.py +214 -0
- llama_stack_api/shields/__init__.py +41 -0
- llama_stack_api/shields/api.py +39 -0
- llama_stack_api/shields/fastapi_routes.py +104 -0
- llama_stack_api/shields/models.py +74 -0
- llama_stack_api/tools.py +226 -0
- llama_stack_api/validators.py +46 -0
- llama_stack_api/vector_io/__init__.py +88 -0
- llama_stack_api/vector_io/api.py +234 -0
- llama_stack_api/vector_io/fastapi_routes.py +447 -0
- llama_stack_api/vector_io/models.py +663 -0
- llama_stack_api/vector_stores.py +53 -0
- llama_stack_api/version.py +9 -0
- {llama_stack_api-0.4.3.dist-info → llama_stack_api-0.5.0rc1.dist-info}/METADATA +1 -1
- llama_stack_api-0.5.0rc1.dist-info/RECORD +115 -0
- llama_stack_api-0.5.0rc1.dist-info/top_level.txt +1 -0
- llama_stack_api-0.4.3.dist-info/RECORD +0 -4
- llama_stack_api-0.4.3.dist-info/top_level.txt +0 -1
- {llama_stack_api-0.4.3.dist-info → llama_stack_api-0.5.0rc1.dist-info}/WHEEL +0 -0
|
@@ -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
|
+
]
|
|
@@ -0,0 +1,447 @@
|
|
|
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 VectorIO API.
|
|
8
|
+
|
|
9
|
+
This module defines the FastAPI router for the VectorIO API using standard
|
|
10
|
+
FastAPI route decorators.
|
|
11
|
+
|
|
12
|
+
It replaces the legacy @webmethod-driven route discovery for VectorIO.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import Annotated, Any, NoReturn, cast
|
|
18
|
+
|
|
19
|
+
from fastapi import APIRouter, Body, HTTPException, Path, Query, Request, Response, status
|
|
20
|
+
from pydantic import BaseModel, Field
|
|
21
|
+
|
|
22
|
+
from llama_stack_api.common.content_types import InterleavedContent
|
|
23
|
+
from llama_stack_api.router_utils import standard_responses
|
|
24
|
+
from llama_stack_api.version import LLAMA_STACK_API_V1
|
|
25
|
+
|
|
26
|
+
from .api import VectorIO
|
|
27
|
+
from .models import (
|
|
28
|
+
EmbeddedChunk,
|
|
29
|
+
OpenAICreateVectorStoreFileBatchRequestWithExtraBody,
|
|
30
|
+
OpenAICreateVectorStoreRequestWithExtraBody,
|
|
31
|
+
QueryChunksResponse,
|
|
32
|
+
SearchRankingOptions,
|
|
33
|
+
VectorStoreChunkingStrategy,
|
|
34
|
+
VectorStoreDeleteResponse,
|
|
35
|
+
VectorStoreFileBatchObject,
|
|
36
|
+
VectorStoreFileContentResponse,
|
|
37
|
+
VectorStoreFileDeleteResponse,
|
|
38
|
+
VectorStoreFileObject,
|
|
39
|
+
VectorStoreFilesListInBatchResponse,
|
|
40
|
+
VectorStoreFileStatus,
|
|
41
|
+
VectorStoreListFilesResponse,
|
|
42
|
+
VectorStoreListResponse,
|
|
43
|
+
VectorStoreObject,
|
|
44
|
+
VectorStoreSearchResponsePage,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class InsertChunksRequest(BaseModel):
|
|
49
|
+
"""Request body for inserting chunks into a vector store."""
|
|
50
|
+
|
|
51
|
+
vector_store_id: str = Field(description="The ID of the vector store to insert chunks into.")
|
|
52
|
+
chunks: list[EmbeddedChunk] = Field(description="The list of embedded chunks to insert.")
|
|
53
|
+
ttl_seconds: int | None = Field(default=None, description="Time-to-live in seconds for the inserted chunks.")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class QueryChunksRequest(BaseModel):
|
|
57
|
+
"""Request body for querying chunks from a vector store."""
|
|
58
|
+
|
|
59
|
+
vector_store_id: str = Field(description="The ID of the vector store to query.")
|
|
60
|
+
query: InterleavedContent = Field(description="The query content to search for.")
|
|
61
|
+
params: dict[str, Any] | None = Field(default=None, description="Additional query parameters.")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class OpenAIUpdateVectorStoreRequest(BaseModel):
|
|
65
|
+
"""Request body for updating a vector store."""
|
|
66
|
+
|
|
67
|
+
name: str | None = Field(default=None, description="The new name for the vector store.")
|
|
68
|
+
expires_after: dict[str, Any] | None = Field(default=None, description="Expiration policy for the vector store.")
|
|
69
|
+
metadata: dict[str, Any] | None = Field(default=None, description="Metadata to associate with the vector store.")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class OpenAISearchVectorStoreRequest(BaseModel):
|
|
73
|
+
"""Request body for searching a vector store."""
|
|
74
|
+
|
|
75
|
+
query: str | list[str] = Field(description="The search query string or list of query strings.")
|
|
76
|
+
filters: dict[str, Any] | None = Field(default=None, description="Filters to apply to the search.")
|
|
77
|
+
max_num_results: int | None = Field(default=10, description="Maximum number of results to return.")
|
|
78
|
+
ranking_options: SearchRankingOptions | None = Field(default=None, description="Options for ranking results.")
|
|
79
|
+
rewrite_query: bool | None = Field(default=False, description="Whether to rewrite the query for better results.")
|
|
80
|
+
search_mode: str | None = Field(default="vector", description="The search mode to use (e.g., 'vector', 'keyword').")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class OpenAIAttachFileRequest(BaseModel):
|
|
84
|
+
"""Request body for attaching a file to a vector store."""
|
|
85
|
+
|
|
86
|
+
file_id: str = Field(description="The ID of the file to attach.")
|
|
87
|
+
attributes: dict[str, Any] | None = Field(default=None, description="Attributes to associate with the file.")
|
|
88
|
+
chunking_strategy: VectorStoreChunkingStrategy | None = Field(
|
|
89
|
+
default=None, description="Strategy for chunking the file content."
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class OpenAIUpdateVectorStoreFileRequest(BaseModel):
|
|
94
|
+
"""Request body for updating a vector store file."""
|
|
95
|
+
|
|
96
|
+
attributes: dict[str, Any] = Field(description="The new attributes for the file.")
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def create_router(impl: VectorIO) -> APIRouter:
|
|
100
|
+
router = APIRouter(
|
|
101
|
+
prefix=f"/{LLAMA_STACK_API_V1}",
|
|
102
|
+
tags=["VectorIO"],
|
|
103
|
+
responses=standard_responses,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
@router.post(
|
|
107
|
+
"/vector-io/insert",
|
|
108
|
+
status_code=status.HTTP_204_NO_CONTENT,
|
|
109
|
+
response_class=Response,
|
|
110
|
+
summary="Insert embedded chunks into a vector database.",
|
|
111
|
+
description="Insert embedded chunks into a vector database.",
|
|
112
|
+
responses={204: {"description": "Chunks were inserted."}},
|
|
113
|
+
)
|
|
114
|
+
async def insert_chunks(request: Annotated[InsertChunksRequest, Body(...)]) -> None:
|
|
115
|
+
await impl.insert_chunks(
|
|
116
|
+
vector_store_id=request.vector_store_id,
|
|
117
|
+
chunks=request.chunks,
|
|
118
|
+
ttl_seconds=request.ttl_seconds,
|
|
119
|
+
)
|
|
120
|
+
return None
|
|
121
|
+
|
|
122
|
+
@router.post(
|
|
123
|
+
"/vector-io/query",
|
|
124
|
+
response_model=QueryChunksResponse,
|
|
125
|
+
summary="Query chunks from a vector database.",
|
|
126
|
+
description="Query chunks from a vector database.",
|
|
127
|
+
responses={200: {"description": "A QueryChunksResponse."}},
|
|
128
|
+
)
|
|
129
|
+
async def query_chunks(request: Annotated[QueryChunksRequest, Body(...)]) -> QueryChunksResponse:
|
|
130
|
+
return await impl.query_chunks(
|
|
131
|
+
vector_store_id=request.vector_store_id,
|
|
132
|
+
query=request.query,
|
|
133
|
+
params=request.params,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
@router.post(
|
|
137
|
+
"/vector_stores",
|
|
138
|
+
response_model=VectorStoreObject,
|
|
139
|
+
summary="Create a vector store (OpenAI-compatible).",
|
|
140
|
+
description="Create a vector store (OpenAI-compatible).",
|
|
141
|
+
responses={200: {"description": "The created vector store."}},
|
|
142
|
+
)
|
|
143
|
+
async def openai_create_vector_store(
|
|
144
|
+
params: Annotated[OpenAICreateVectorStoreRequestWithExtraBody, Body(...)],
|
|
145
|
+
) -> VectorStoreObject:
|
|
146
|
+
return await impl.openai_create_vector_store(params)
|
|
147
|
+
|
|
148
|
+
@router.get(
|
|
149
|
+
"/vector_stores",
|
|
150
|
+
response_model=VectorStoreListResponse,
|
|
151
|
+
summary="List vector stores (OpenAI-compatible).",
|
|
152
|
+
description="List vector stores (OpenAI-compatible).",
|
|
153
|
+
responses={200: {"description": "A list of vector stores."}},
|
|
154
|
+
)
|
|
155
|
+
async def openai_list_vector_stores(
|
|
156
|
+
limit: Annotated[int | None, Query(description="Maximum number of vector stores to return.")] = 20,
|
|
157
|
+
order: Annotated[str | None, Query(description="Sort order by created_at: asc or desc.")] = "desc",
|
|
158
|
+
after: Annotated[
|
|
159
|
+
str | None,
|
|
160
|
+
Query(
|
|
161
|
+
description="Pagination cursor (after).",
|
|
162
|
+
),
|
|
163
|
+
] = None,
|
|
164
|
+
before: Annotated[
|
|
165
|
+
str | None,
|
|
166
|
+
Query(
|
|
167
|
+
description="Pagination cursor (before).",
|
|
168
|
+
),
|
|
169
|
+
] = None,
|
|
170
|
+
) -> VectorStoreListResponse:
|
|
171
|
+
return await impl.openai_list_vector_stores(limit=limit, order=order, after=after, before=before)
|
|
172
|
+
|
|
173
|
+
@router.get(
|
|
174
|
+
"/vector_stores/{vector_store_id}",
|
|
175
|
+
response_model=VectorStoreObject,
|
|
176
|
+
summary="Retrieve a vector store (OpenAI-compatible).",
|
|
177
|
+
description="Retrieve a vector store (OpenAI-compatible).",
|
|
178
|
+
responses={200: {"description": "The vector store."}},
|
|
179
|
+
)
|
|
180
|
+
async def openai_retrieve_vector_store(
|
|
181
|
+
vector_store_id: Annotated[str, Path(description="The vector store identifier.")],
|
|
182
|
+
) -> VectorStoreObject:
|
|
183
|
+
return await impl.openai_retrieve_vector_store(vector_store_id=vector_store_id)
|
|
184
|
+
|
|
185
|
+
@router.post(
|
|
186
|
+
"/vector_stores/{vector_store_id}",
|
|
187
|
+
response_model=VectorStoreObject,
|
|
188
|
+
summary="Update a vector store (OpenAI-compatible).",
|
|
189
|
+
description="Update a vector store (OpenAI-compatible).",
|
|
190
|
+
responses={200: {"description": "The updated vector store."}},
|
|
191
|
+
)
|
|
192
|
+
async def openai_update_vector_store(
|
|
193
|
+
vector_store_id: Annotated[str, Path(description="The vector store identifier.")],
|
|
194
|
+
request: Annotated[OpenAIUpdateVectorStoreRequest, Body(...)],
|
|
195
|
+
) -> VectorStoreObject:
|
|
196
|
+
return await impl.openai_update_vector_store(
|
|
197
|
+
vector_store_id=vector_store_id,
|
|
198
|
+
name=request.name,
|
|
199
|
+
expires_after=request.expires_after,
|
|
200
|
+
metadata=request.metadata,
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
@router.delete(
|
|
204
|
+
"/vector_stores/{vector_store_id}",
|
|
205
|
+
response_model=VectorStoreDeleteResponse,
|
|
206
|
+
summary="Delete a vector store (OpenAI-compatible).",
|
|
207
|
+
description="Delete a vector store (OpenAI-compatible).",
|
|
208
|
+
responses={200: {"description": "Vector store deleted."}},
|
|
209
|
+
)
|
|
210
|
+
async def openai_delete_vector_store(
|
|
211
|
+
vector_store_id: Annotated[str, Path(description="The vector store identifier.")],
|
|
212
|
+
) -> VectorStoreDeleteResponse:
|
|
213
|
+
return await impl.openai_delete_vector_store(vector_store_id=vector_store_id)
|
|
214
|
+
|
|
215
|
+
@router.post(
|
|
216
|
+
"/vector_stores/{vector_store_id}/search",
|
|
217
|
+
response_model=VectorStoreSearchResponsePage,
|
|
218
|
+
summary="Search a vector store (OpenAI-compatible).",
|
|
219
|
+
description="Search a vector store (OpenAI-compatible).",
|
|
220
|
+
responses={200: {"description": "Search results."}},
|
|
221
|
+
)
|
|
222
|
+
async def openai_search_vector_store(
|
|
223
|
+
vector_store_id: Annotated[str, Path(description="The vector store identifier.")],
|
|
224
|
+
request: Annotated[OpenAISearchVectorStoreRequest, Body(...)],
|
|
225
|
+
) -> VectorStoreSearchResponsePage:
|
|
226
|
+
return await impl.openai_search_vector_store(
|
|
227
|
+
vector_store_id=vector_store_id,
|
|
228
|
+
query=request.query,
|
|
229
|
+
filters=request.filters,
|
|
230
|
+
max_num_results=request.max_num_results,
|
|
231
|
+
ranking_options=request.ranking_options,
|
|
232
|
+
rewrite_query=request.rewrite_query,
|
|
233
|
+
search_mode=request.search_mode,
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
@router.post(
|
|
237
|
+
"/vector_stores/{vector_store_id}/files",
|
|
238
|
+
response_model=VectorStoreFileObject,
|
|
239
|
+
summary="Attach a file to a vector store (OpenAI-compatible).",
|
|
240
|
+
description="Attach a file to a vector store (OpenAI-compatible).",
|
|
241
|
+
responses={200: {"description": "The attached file."}},
|
|
242
|
+
)
|
|
243
|
+
async def openai_attach_file_to_vector_store(
|
|
244
|
+
vector_store_id: Annotated[str, Path(description="The vector store identifier.")],
|
|
245
|
+
request: Annotated[OpenAIAttachFileRequest, Body(...)],
|
|
246
|
+
) -> VectorStoreFileObject:
|
|
247
|
+
return await impl.openai_attach_file_to_vector_store(
|
|
248
|
+
vector_store_id=vector_store_id,
|
|
249
|
+
file_id=request.file_id,
|
|
250
|
+
attributes=request.attributes,
|
|
251
|
+
chunking_strategy=request.chunking_strategy,
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
@router.get(
|
|
255
|
+
"/vector_stores/{vector_store_id}/files",
|
|
256
|
+
response_model=VectorStoreListFilesResponse,
|
|
257
|
+
summary="List files in a vector store (OpenAI-compatible).",
|
|
258
|
+
description="List files in a vector store (OpenAI-compatible).",
|
|
259
|
+
responses={200: {"description": "A list of files in the vector store."}},
|
|
260
|
+
)
|
|
261
|
+
async def openai_list_files_in_vector_store(
|
|
262
|
+
vector_store_id: Annotated[str, Path(description="The vector store identifier.")],
|
|
263
|
+
limit: Annotated[int | None, Query(description="Maximum number of files to return.")] = 20,
|
|
264
|
+
order: Annotated[str | None, Query(description="Sort order by created_at: asc or desc.")] = "desc",
|
|
265
|
+
after: Annotated[
|
|
266
|
+
str | None,
|
|
267
|
+
Query(
|
|
268
|
+
description="Pagination cursor (after).",
|
|
269
|
+
),
|
|
270
|
+
] = None,
|
|
271
|
+
before: Annotated[
|
|
272
|
+
str | None,
|
|
273
|
+
Query(
|
|
274
|
+
description="Pagination cursor (before).",
|
|
275
|
+
),
|
|
276
|
+
] = None,
|
|
277
|
+
filter: Annotated[VectorStoreFileStatus | None, Query(description="Filter by file status.")] = None,
|
|
278
|
+
) -> VectorStoreListFilesResponse:
|
|
279
|
+
return await impl.openai_list_files_in_vector_store(
|
|
280
|
+
vector_store_id=vector_store_id,
|
|
281
|
+
limit=limit,
|
|
282
|
+
order=order,
|
|
283
|
+
after=after,
|
|
284
|
+
before=before,
|
|
285
|
+
filter=filter,
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
@router.get(
|
|
289
|
+
"/vector_stores/{vector_store_id}/files/{file_id}",
|
|
290
|
+
response_model=VectorStoreFileObject,
|
|
291
|
+
summary="Retrieve a vector store file (OpenAI-compatible).",
|
|
292
|
+
description="Retrieve a vector store file (OpenAI-compatible).",
|
|
293
|
+
responses={200: {"description": "The vector store file."}},
|
|
294
|
+
)
|
|
295
|
+
async def openai_retrieve_vector_store_file(
|
|
296
|
+
vector_store_id: Annotated[str, Path(description="The vector store identifier.")],
|
|
297
|
+
file_id: Annotated[str, Path(description="The file identifier.")],
|
|
298
|
+
) -> VectorStoreFileObject:
|
|
299
|
+
return await impl.openai_retrieve_vector_store_file(vector_store_id=vector_store_id, file_id=file_id)
|
|
300
|
+
|
|
301
|
+
@router.get(
|
|
302
|
+
"/vector_stores/{vector_store_id}/files/{file_id}/content",
|
|
303
|
+
response_model=VectorStoreFileContentResponse,
|
|
304
|
+
summary="Retrieve vector store file contents (OpenAI-compatible).",
|
|
305
|
+
description="Retrieve vector store file contents (OpenAI-compatible).",
|
|
306
|
+
responses={200: {"description": "The vector store file contents."}},
|
|
307
|
+
)
|
|
308
|
+
async def openai_retrieve_vector_store_file_contents(
|
|
309
|
+
vector_store_id: Annotated[str, Path(description="The vector store identifier.")],
|
|
310
|
+
file_id: Annotated[str, Path(description="The file identifier.")],
|
|
311
|
+
include_embeddings: Annotated[bool | None, Query(description="Include embedding vectors.")] = False,
|
|
312
|
+
include_metadata: Annotated[bool | None, Query(description="Include chunk metadata.")] = False,
|
|
313
|
+
) -> VectorStoreFileContentResponse:
|
|
314
|
+
return await impl.openai_retrieve_vector_store_file_contents(
|
|
315
|
+
vector_store_id=vector_store_id,
|
|
316
|
+
file_id=file_id,
|
|
317
|
+
include_embeddings=include_embeddings,
|
|
318
|
+
include_metadata=include_metadata,
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
@router.post(
|
|
322
|
+
"/vector_stores/{vector_store_id}/files/{file_id}",
|
|
323
|
+
response_model=VectorStoreFileObject,
|
|
324
|
+
summary="Update a vector store file (OpenAI-compatible).",
|
|
325
|
+
description="Update a vector store file (OpenAI-compatible).",
|
|
326
|
+
responses={200: {"description": "The updated vector store file."}},
|
|
327
|
+
)
|
|
328
|
+
async def openai_update_vector_store_file(
|
|
329
|
+
vector_store_id: Annotated[str, Path(description="The vector store identifier.")],
|
|
330
|
+
file_id: Annotated[str, Path(description="The file identifier.")],
|
|
331
|
+
request: Annotated[OpenAIUpdateVectorStoreFileRequest, Body(...)],
|
|
332
|
+
) -> VectorStoreFileObject:
|
|
333
|
+
return await impl.openai_update_vector_store_file(
|
|
334
|
+
vector_store_id=vector_store_id,
|
|
335
|
+
file_id=file_id,
|
|
336
|
+
attributes=request.attributes,
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
@router.delete(
|
|
340
|
+
"/vector_stores/{vector_store_id}/files/{file_id}",
|
|
341
|
+
response_model=VectorStoreFileDeleteResponse,
|
|
342
|
+
summary="Delete a vector store file (OpenAI-compatible).",
|
|
343
|
+
description="Delete a vector store file (OpenAI-compatible).",
|
|
344
|
+
responses={200: {"description": "The vector store file was deleted."}},
|
|
345
|
+
)
|
|
346
|
+
async def openai_delete_vector_store_file(
|
|
347
|
+
vector_store_id: Annotated[str, Path(description="The vector store identifier.")],
|
|
348
|
+
file_id: Annotated[str, Path(description="The file identifier.")],
|
|
349
|
+
) -> VectorStoreFileDeleteResponse:
|
|
350
|
+
return await impl.openai_delete_vector_store_file(vector_store_id=vector_store_id, file_id=file_id)
|
|
351
|
+
|
|
352
|
+
@router.post(
|
|
353
|
+
"/vector_stores/{vector_store_id}/file_batches",
|
|
354
|
+
response_model=VectorStoreFileBatchObject,
|
|
355
|
+
summary="Create a vector store file batch (OpenAI-compatible).",
|
|
356
|
+
description="Create a vector store file batch (OpenAI-compatible).",
|
|
357
|
+
responses={200: {"description": "The created file batch."}},
|
|
358
|
+
)
|
|
359
|
+
async def openai_create_vector_store_file_batch(
|
|
360
|
+
vector_store_id: Annotated[str, Path(description="The vector store identifier.")],
|
|
361
|
+
params: Annotated[OpenAICreateVectorStoreFileBatchRequestWithExtraBody, Body(...)],
|
|
362
|
+
request: Request = _MISSING_REQUEST,
|
|
363
|
+
) -> VectorStoreFileBatchObject:
|
|
364
|
+
try:
|
|
365
|
+
return await impl.openai_create_vector_store_file_batch(vector_store_id=vector_store_id, params=params)
|
|
366
|
+
except ValueError as exc:
|
|
367
|
+
_raise_or_http_400_for_value_error(request, exc)
|
|
368
|
+
|
|
369
|
+
@router.get(
|
|
370
|
+
"/vector_stores/{vector_store_id}/file_batches/{batch_id}",
|
|
371
|
+
response_model=VectorStoreFileBatchObject,
|
|
372
|
+
summary="Retrieve a vector store file batch (OpenAI-compatible).",
|
|
373
|
+
description="Retrieve a vector store file batch (OpenAI-compatible).",
|
|
374
|
+
responses={200: {"description": "The file batch."}},
|
|
375
|
+
)
|
|
376
|
+
async def openai_retrieve_vector_store_file_batch(
|
|
377
|
+
vector_store_id: Annotated[str, Path(description="The vector store identifier.")],
|
|
378
|
+
batch_id: Annotated[str, Path(description="The file batch identifier.")],
|
|
379
|
+
request: Request = _MISSING_REQUEST,
|
|
380
|
+
) -> VectorStoreFileBatchObject:
|
|
381
|
+
try:
|
|
382
|
+
return await impl.openai_retrieve_vector_store_file_batch(
|
|
383
|
+
batch_id=batch_id, vector_store_id=vector_store_id
|
|
384
|
+
)
|
|
385
|
+
except ValueError as exc:
|
|
386
|
+
_raise_or_http_400_for_value_error(request, exc)
|
|
387
|
+
|
|
388
|
+
@router.get(
|
|
389
|
+
"/vector_stores/{vector_store_id}/file_batches/{batch_id}/files",
|
|
390
|
+
response_model=VectorStoreFilesListInBatchResponse,
|
|
391
|
+
summary="List files in a vector store file batch (OpenAI-compatible).",
|
|
392
|
+
description="List files in a vector store file batch (OpenAI-compatible).",
|
|
393
|
+
responses={200: {"description": "A list of files in the file batch."}},
|
|
394
|
+
)
|
|
395
|
+
async def openai_list_files_in_vector_store_file_batch(
|
|
396
|
+
vector_store_id: Annotated[str, Path(description="The vector store identifier.")],
|
|
397
|
+
batch_id: Annotated[str, Path(description="The file batch identifier.")],
|
|
398
|
+
after: Annotated[
|
|
399
|
+
str | None,
|
|
400
|
+
Query(
|
|
401
|
+
description="Pagination cursor (after).",
|
|
402
|
+
),
|
|
403
|
+
] = None,
|
|
404
|
+
before: Annotated[
|
|
405
|
+
str | None,
|
|
406
|
+
Query(
|
|
407
|
+
description="Pagination cursor (before).",
|
|
408
|
+
),
|
|
409
|
+
] = None,
|
|
410
|
+
filter: Annotated[str | None, Query(description="Filter by file status.")] = None,
|
|
411
|
+
limit: Annotated[int | None, Query(description="Maximum number of files to return.")] = 20,
|
|
412
|
+
order: Annotated[str | None, Query(description="Sort order by created_at: asc or desc.")] = "desc",
|
|
413
|
+
) -> VectorStoreFilesListInBatchResponse:
|
|
414
|
+
return await impl.openai_list_files_in_vector_store_file_batch(
|
|
415
|
+
batch_id=batch_id,
|
|
416
|
+
vector_store_id=vector_store_id,
|
|
417
|
+
after=after,
|
|
418
|
+
before=before,
|
|
419
|
+
filter=filter,
|
|
420
|
+
limit=limit,
|
|
421
|
+
order=order,
|
|
422
|
+
)
|
|
423
|
+
|
|
424
|
+
@router.post(
|
|
425
|
+
"/vector_stores/{vector_store_id}/file_batches/{batch_id}/cancel",
|
|
426
|
+
response_model=VectorStoreFileBatchObject,
|
|
427
|
+
summary="Cancel a vector store file batch (OpenAI-compatible).",
|
|
428
|
+
description="Cancel a vector store file batch (OpenAI-compatible).",
|
|
429
|
+
responses={200: {"description": "The cancelled file batch."}},
|
|
430
|
+
)
|
|
431
|
+
async def openai_cancel_vector_store_file_batch(
|
|
432
|
+
vector_store_id: Annotated[str, Path(description="The vector store identifier.")],
|
|
433
|
+
batch_id: Annotated[str, Path(description="The file batch identifier.")],
|
|
434
|
+
) -> VectorStoreFileBatchObject:
|
|
435
|
+
return await impl.openai_cancel_vector_store_file_batch(batch_id=batch_id, vector_store_id=vector_store_id)
|
|
436
|
+
|
|
437
|
+
return router
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
_MISSING_REQUEST: Request = cast(Request, None)
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
def _raise_or_http_400_for_value_error(request: Request, exc: ValueError) -> NoReturn:
|
|
444
|
+
# In library mode, FastAPI doesn't inject a Request.
|
|
445
|
+
if request is _MISSING_REQUEST:
|
|
446
|
+
raise
|
|
447
|
+
raise HTTPException(status_code=400, detail=str(exc)) from exc
|