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,41 @@
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
+ """Shields API protocol and models.
8
+
9
+ This module contains the Shields protocol definition.
10
+ Pydantic models are defined in llama_stack_api.shields.models.
11
+ The FastAPI router is defined in llama_stack_api.shields.fastapi_routes.
12
+ """
13
+
14
+ # Import fastapi_routes for router factory access
15
+ from . import fastapi_routes
16
+
17
+ # Import protocol for re-export
18
+ from .api import Shields
19
+
20
+ # Import models for re-export
21
+ from .models import (
22
+ CommonShieldFields,
23
+ GetShieldRequest,
24
+ ListShieldsResponse,
25
+ RegisterShieldRequest,
26
+ Shield,
27
+ ShieldInput,
28
+ UnregisterShieldRequest,
29
+ )
30
+
31
+ __all__ = [
32
+ "Shields",
33
+ "Shield",
34
+ "ShieldInput",
35
+ "CommonShieldFields",
36
+ "ListShieldsResponse",
37
+ "GetShieldRequest",
38
+ "RegisterShieldRequest",
39
+ "UnregisterShieldRequest",
40
+ "fastapi_routes",
41
+ ]
@@ -0,0 +1,39 @@
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
+ """Shields API protocol definition.
8
+
9
+ This module contains the Shields protocol for managing shield resources.
10
+ """
11
+
12
+ from typing import Protocol, runtime_checkable
13
+
14
+ from .models import (
15
+ GetShieldRequest,
16
+ ListShieldsResponse,
17
+ RegisterShieldRequest,
18
+ Shield,
19
+ UnregisterShieldRequest,
20
+ )
21
+
22
+
23
+ @runtime_checkable
24
+ class Shields(Protocol):
25
+ async def list_shields(self) -> ListShieldsResponse:
26
+ """List all shields."""
27
+ ...
28
+
29
+ async def get_shield(self, request: GetShieldRequest) -> Shield:
30
+ """Get a shield by its identifier."""
31
+ ...
32
+
33
+ async def register_shield(self, request: RegisterShieldRequest) -> Shield:
34
+ """Register a shield."""
35
+ ...
36
+
37
+ async def unregister_shield(self, request: UnregisterShieldRequest) -> None:
38
+ """Unregister a shield."""
39
+ ...
@@ -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 Shields API.
8
+
9
+ This module defines the FastAPI router for the Shields 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_V1
19
+
20
+ from .api import Shields
21
+ from .models import (
22
+ GetShieldRequest,
23
+ ListShieldsResponse,
24
+ RegisterShieldRequest,
25
+ Shield,
26
+ UnregisterShieldRequest,
27
+ )
28
+
29
+ # Automatically generate dependency functions from Pydantic models
30
+ get_get_shield_request = create_path_dependency(GetShieldRequest)
31
+ get_unregister_shield_request = create_path_dependency(UnregisterShieldRequest)
32
+
33
+
34
+ def create_router(impl: Shields) -> APIRouter:
35
+ """Create a FastAPI router for the Shields API.
36
+
37
+ Args:
38
+ impl: The Shields implementation instance
39
+
40
+ Returns:
41
+ APIRouter configured for the Shields API
42
+ """
43
+ router = APIRouter(
44
+ prefix=f"/{LLAMA_STACK_API_V1}",
45
+ tags=["Shields"],
46
+ responses=standard_responses,
47
+ )
48
+
49
+ @router.get(
50
+ "/shields",
51
+ response_model=ListShieldsResponse,
52
+ summary="List all shields.",
53
+ description="List all shields.",
54
+ responses={
55
+ 200: {"description": "A ListShieldsResponse."},
56
+ },
57
+ )
58
+ async def list_shields() -> ListShieldsResponse:
59
+ return await impl.list_shields()
60
+
61
+ @router.get(
62
+ "/shields/{identifier:path}",
63
+ response_model=Shield,
64
+ summary="Get a shield by its identifier.",
65
+ description="Get a shield by its identifier.",
66
+ responses={
67
+ 200: {"description": "A Shield."},
68
+ },
69
+ )
70
+ async def get_shield(
71
+ request: Annotated[GetShieldRequest, Depends(get_get_shield_request)],
72
+ ) -> Shield:
73
+ return await impl.get_shield(request)
74
+
75
+ @router.post(
76
+ "/shields",
77
+ response_model=Shield,
78
+ summary="Register a shield.",
79
+ description="Register a shield.",
80
+ responses={
81
+ 200: {"description": "A Shield."},
82
+ },
83
+ deprecated=True,
84
+ )
85
+ async def register_shield(
86
+ request: Annotated[RegisterShieldRequest, Body(...)],
87
+ ) -> Shield:
88
+ return await impl.register_shield(request)
89
+
90
+ @router.delete(
91
+ "/shields/{identifier:path}",
92
+ summary="Unregister a shield.",
93
+ description="Unregister a shield.",
94
+ responses={
95
+ 200: {"description": "The shield was successfully unregistered."},
96
+ },
97
+ deprecated=True,
98
+ )
99
+ async def unregister_shield(
100
+ request: Annotated[UnregisterShieldRequest, Depends(get_unregister_shield_request)],
101
+ ) -> None:
102
+ return await impl.unregister_shield(request)
103
+
104
+ return router
@@ -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,226 @@
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 enum import Enum
8
+ from typing import Any, Literal, Protocol
9
+
10
+ from pydantic import BaseModel
11
+ from typing_extensions import runtime_checkable
12
+
13
+ from llama_stack_api.common.content_types import URL, InterleavedContent
14
+ from llama_stack_api.resource import Resource, ResourceType
15
+ from llama_stack_api.schema_utils import json_schema_type, webmethod
16
+ from llama_stack_api.version import LLAMA_STACK_API_V1
17
+
18
+
19
+ @json_schema_type
20
+ class ToolDef(BaseModel):
21
+ """Tool definition used in runtime contexts.
22
+
23
+ :param name: Name of the tool
24
+ :param description: (Optional) Human-readable description of what the tool does
25
+ :param input_schema: (Optional) JSON Schema for tool inputs (MCP inputSchema)
26
+ :param output_schema: (Optional) JSON Schema for tool outputs (MCP outputSchema)
27
+ :param metadata: (Optional) Additional metadata about the tool
28
+ :param toolgroup_id: (Optional) ID of the tool group this tool belongs to
29
+ """
30
+
31
+ toolgroup_id: str | None = None
32
+ name: str
33
+ description: str | None = None
34
+ input_schema: dict[str, Any] | None = None
35
+ output_schema: dict[str, Any] | None = None
36
+ metadata: dict[str, Any] | None = None
37
+
38
+
39
+ @json_schema_type
40
+ class ToolGroupInput(BaseModel):
41
+ """Input data for registering a tool group.
42
+
43
+ :param toolgroup_id: Unique identifier for the tool group
44
+ :param provider_id: ID of the provider that will handle this tool group
45
+ :param args: (Optional) Additional arguments to pass to the provider
46
+ :param mcp_endpoint: (Optional) Model Context Protocol endpoint for remote tools
47
+ """
48
+
49
+ toolgroup_id: str
50
+ provider_id: str
51
+ args: dict[str, Any] | None = None
52
+ mcp_endpoint: URL | None = None
53
+
54
+
55
+ @json_schema_type
56
+ class ToolGroup(Resource):
57
+ """A group of related tools managed together.
58
+
59
+ :param type: Type of resource, always 'tool_group'
60
+ :param mcp_endpoint: (Optional) Model Context Protocol endpoint for remote tools
61
+ :param args: (Optional) Additional arguments for the tool group
62
+ """
63
+
64
+ type: Literal[ResourceType.tool_group] = ResourceType.tool_group
65
+ mcp_endpoint: URL | None = None
66
+ args: dict[str, Any] | None = None
67
+
68
+
69
+ @json_schema_type
70
+ class ToolInvocationResult(BaseModel):
71
+ """Result of a tool invocation.
72
+
73
+ :param content: (Optional) The output content from the tool execution
74
+ :param error_message: (Optional) Error message if the tool execution failed
75
+ :param error_code: (Optional) Numeric error code if the tool execution failed
76
+ :param metadata: (Optional) Additional metadata about the tool execution
77
+ """
78
+
79
+ content: InterleavedContent | None = None
80
+ error_message: str | None = None
81
+ error_code: int | None = None
82
+ metadata: dict[str, Any] | None = None
83
+
84
+
85
+ class ToolStore(Protocol):
86
+ async def get_tool(self, tool_name: str) -> ToolDef: ...
87
+ async def get_tool_group(self, toolgroup_id: str) -> ToolGroup: ...
88
+
89
+
90
+ @json_schema_type
91
+ class ListToolGroupsResponse(BaseModel):
92
+ """Response containing a list of tool groups.
93
+
94
+ :param data: List of tool groups
95
+ """
96
+
97
+ data: list[ToolGroup]
98
+
99
+
100
+ @json_schema_type
101
+ class ListToolDefsResponse(BaseModel):
102
+ """Response containing a list of tool definitions.
103
+
104
+ :param data: List of tool definitions
105
+ """
106
+
107
+ data: list[ToolDef]
108
+
109
+
110
+ @runtime_checkable
111
+ class ToolGroups(Protocol):
112
+ @webmethod(route="/toolgroups", method="POST", level=LLAMA_STACK_API_V1, deprecated=True)
113
+ async def register_tool_group(
114
+ self,
115
+ toolgroup_id: str,
116
+ provider_id: str,
117
+ mcp_endpoint: URL | None = None,
118
+ args: dict[str, Any] | None = None,
119
+ ) -> None:
120
+ """Register a tool group.
121
+
122
+ :param toolgroup_id: The ID of the tool group to register.
123
+ :param provider_id: The ID of the provider to use for the tool group.
124
+ :param mcp_endpoint: The MCP endpoint to use for the tool group.
125
+ :param args: A dictionary of arguments to pass to the tool group.
126
+ """
127
+ ...
128
+
129
+ @webmethod(route="/toolgroups/{toolgroup_id:path}", method="GET", level=LLAMA_STACK_API_V1, deprecated=True)
130
+ async def get_tool_group(
131
+ self,
132
+ toolgroup_id: str,
133
+ ) -> ToolGroup:
134
+ """Get a tool group by its ID.
135
+
136
+ :param toolgroup_id: The ID of the tool group to get.
137
+ :returns: A ToolGroup.
138
+ """
139
+ ...
140
+
141
+ @webmethod(route="/toolgroups", method="GET", level=LLAMA_STACK_API_V1, deprecated=True)
142
+ async def list_tool_groups(self) -> ListToolGroupsResponse:
143
+ """List tool groups with optional provider.
144
+
145
+ :returns: A ListToolGroupsResponse.
146
+ """
147
+ ...
148
+
149
+ @webmethod(route="/tools", method="GET", level=LLAMA_STACK_API_V1, deprecated=True)
150
+ async def list_tools(self, toolgroup_id: str | None = None) -> ListToolDefsResponse:
151
+ """List tools with optional tool group.
152
+
153
+ :param toolgroup_id: The ID of the tool group to list tools for.
154
+ :returns: A ListToolDefsResponse.
155
+ """
156
+ ...
157
+
158
+ @webmethod(route="/tools/{tool_name:path}", method="GET", level=LLAMA_STACK_API_V1, deprecated=True)
159
+ async def get_tool(
160
+ self,
161
+ tool_name: str,
162
+ ) -> ToolDef:
163
+ """Get a tool by its name.
164
+
165
+ :param tool_name: The name of the tool to get.
166
+ :returns: A ToolDef.
167
+ """
168
+ ...
169
+
170
+ @webmethod(route="/toolgroups/{toolgroup_id:path}", method="DELETE", level=LLAMA_STACK_API_V1, deprecated=True)
171
+ async def unregister_toolgroup(
172
+ self,
173
+ toolgroup_id: str,
174
+ ) -> None:
175
+ """Unregister a tool group.
176
+
177
+ :param toolgroup_id: The ID of the tool group to unregister.
178
+ """
179
+ ...
180
+
181
+
182
+ class SpecialToolGroup(Enum):
183
+ """Special tool groups with predefined functionality.
184
+
185
+ :cvar rag_tool: Retrieval-Augmented Generation tool group for document search and retrieval
186
+ """
187
+
188
+ rag_tool = "rag_tool"
189
+
190
+
191
+ @runtime_checkable
192
+ class ToolRuntime(Protocol):
193
+ tool_store: ToolStore | None = None
194
+
195
+ # TODO: This needs to be renamed once OPEN API generator name conflict issue is fixed.
196
+ @webmethod(route="/tool-runtime/list-tools", method="GET", level=LLAMA_STACK_API_V1, deprecated=True)
197
+ async def list_runtime_tools(
198
+ self,
199
+ tool_group_id: str | None = None,
200
+ mcp_endpoint: URL | None = None,
201
+ authorization: str | None = None,
202
+ ) -> ListToolDefsResponse:
203
+ """List all tools in the runtime.
204
+
205
+ :param tool_group_id: The ID of the tool group to list tools for.
206
+ :param mcp_endpoint: The MCP endpoint to use for the tool group.
207
+ :param authorization: (Optional) OAuth access token for authenticating with the MCP server.
208
+ :returns: A ListToolDefsResponse.
209
+ """
210
+ ...
211
+
212
+ @webmethod(route="/tool-runtime/invoke", method="POST", level=LLAMA_STACK_API_V1, deprecated=True)
213
+ async def invoke_tool(
214
+ self,
215
+ tool_name: str,
216
+ kwargs: dict[str, Any],
217
+ authorization: str | None = None,
218
+ ) -> ToolInvocationResult:
219
+ """Run a tool with the given arguments.
220
+
221
+ :param tool_name: The name of the tool to invoke.
222
+ :param kwargs: A dictionary of arguments to pass to the tool.
223
+ :param authorization: (Optional) OAuth access token for authenticating with the MCP server.
224
+ :returns: A ToolInvocationResult.
225
+ """
226
+ ...
@@ -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
+ ]