llama-stack-api 0.4.2__py3-none-any.whl → 0.4.4__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 (72) hide show
  1. llama_stack_api/__init__.py +945 -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.py +173 -0
  7. llama_stack_api/batches/__init__.py +40 -0
  8. llama_stack_api/batches/api.py +53 -0
  9. llama_stack_api/batches/fastapi_routes.py +113 -0
  10. llama_stack_api/batches/models.py +78 -0
  11. llama_stack_api/benchmarks/__init__.py +43 -0
  12. llama_stack_api/benchmarks/api.py +39 -0
  13. llama_stack_api/benchmarks/fastapi_routes.py +109 -0
  14. llama_stack_api/benchmarks/models.py +109 -0
  15. llama_stack_api/common/__init__.py +5 -0
  16. llama_stack_api/common/content_types.py +101 -0
  17. llama_stack_api/common/errors.py +95 -0
  18. llama_stack_api/common/job_types.py +38 -0
  19. llama_stack_api/common/responses.py +77 -0
  20. llama_stack_api/common/training_types.py +47 -0
  21. llama_stack_api/common/type_system.py +146 -0
  22. llama_stack_api/connectors.py +146 -0
  23. llama_stack_api/conversations.py +270 -0
  24. llama_stack_api/datasetio.py +55 -0
  25. llama_stack_api/datasets/__init__.py +61 -0
  26. llama_stack_api/datasets/api.py +35 -0
  27. llama_stack_api/datasets/fastapi_routes.py +104 -0
  28. llama_stack_api/datasets/models.py +152 -0
  29. llama_stack_api/datatypes.py +373 -0
  30. llama_stack_api/eval.py +137 -0
  31. llama_stack_api/file_processors/__init__.py +27 -0
  32. llama_stack_api/file_processors/api.py +64 -0
  33. llama_stack_api/file_processors/fastapi_routes.py +78 -0
  34. llama_stack_api/file_processors/models.py +42 -0
  35. llama_stack_api/files/__init__.py +35 -0
  36. llama_stack_api/files/api.py +51 -0
  37. llama_stack_api/files/fastapi_routes.py +124 -0
  38. llama_stack_api/files/models.py +107 -0
  39. llama_stack_api/inference.py +1169 -0
  40. llama_stack_api/inspect_api/__init__.py +37 -0
  41. llama_stack_api/inspect_api/api.py +25 -0
  42. llama_stack_api/inspect_api/fastapi_routes.py +76 -0
  43. llama_stack_api/inspect_api/models.py +28 -0
  44. llama_stack_api/internal/__init__.py +9 -0
  45. llama_stack_api/internal/kvstore.py +28 -0
  46. llama_stack_api/internal/sqlstore.py +81 -0
  47. llama_stack_api/models.py +171 -0
  48. llama_stack_api/openai_responses.py +1468 -0
  49. llama_stack_api/post_training.py +370 -0
  50. llama_stack_api/prompts.py +203 -0
  51. llama_stack_api/providers/__init__.py +33 -0
  52. llama_stack_api/providers/api.py +16 -0
  53. llama_stack_api/providers/fastapi_routes.py +57 -0
  54. llama_stack_api/providers/models.py +24 -0
  55. llama_stack_api/rag_tool.py +168 -0
  56. llama_stack_api/resource.py +37 -0
  57. llama_stack_api/router_utils.py +160 -0
  58. llama_stack_api/safety.py +132 -0
  59. llama_stack_api/schema_utils.py +208 -0
  60. llama_stack_api/scoring.py +93 -0
  61. llama_stack_api/scoring_functions.py +211 -0
  62. llama_stack_api/shields.py +93 -0
  63. llama_stack_api/tools.py +226 -0
  64. llama_stack_api/vector_io.py +941 -0
  65. llama_stack_api/vector_stores.py +53 -0
  66. llama_stack_api/version.py +9 -0
  67. {llama_stack_api-0.4.2.dist-info → llama_stack_api-0.4.4.dist-info}/METADATA +1 -1
  68. llama_stack_api-0.4.4.dist-info/RECORD +70 -0
  69. {llama_stack_api-0.4.2.dist-info → llama_stack_api-0.4.4.dist-info}/WHEEL +1 -1
  70. llama_stack_api-0.4.4.dist-info/top_level.txt +1 -0
  71. llama_stack_api-0.4.2.dist-info/RECORD +0 -4
  72. llama_stack_api-0.4.2.dist-info/top_level.txt +0 -1
@@ -0,0 +1,38 @@
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
+ from enum import Enum
7
+
8
+ from pydantic import BaseModel
9
+
10
+ from llama_stack_api.schema_utils import json_schema_type
11
+
12
+
13
+ class JobStatus(Enum):
14
+ """Status of a job execution.
15
+ :cvar completed: Job has finished successfully
16
+ :cvar in_progress: Job is currently running
17
+ :cvar failed: Job has failed during execution
18
+ :cvar scheduled: Job is scheduled but not yet started
19
+ :cvar cancelled: Job was cancelled before completion
20
+ """
21
+
22
+ completed = "completed"
23
+ in_progress = "in_progress"
24
+ failed = "failed"
25
+ scheduled = "scheduled"
26
+ cancelled = "cancelled"
27
+
28
+
29
+ @json_schema_type
30
+ class Job(BaseModel):
31
+ """A job execution instance with status tracking.
32
+
33
+ :param job_id: Unique identifier for the job
34
+ :param status: Current execution status of the job
35
+ """
36
+
37
+ job_id: str
38
+ status: JobStatus
@@ -0,0 +1,77 @@
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
9
+
10
+ from pydantic import BaseModel
11
+
12
+ from llama_stack_api.schema_utils import json_schema_type
13
+
14
+
15
+ class Order(Enum):
16
+ """Sort order for paginated responses.
17
+ :cvar asc: Ascending order
18
+ :cvar desc: Descending order
19
+ """
20
+
21
+ asc = "asc"
22
+ desc = "desc"
23
+
24
+
25
+ @json_schema_type
26
+ class PaginatedResponse(BaseModel):
27
+ """A generic paginated response that follows a simple format.
28
+
29
+ :param data: The list of items for the current page
30
+ :param has_more: Whether there are more items available after this set
31
+ :param url: The URL for accessing this list
32
+ """
33
+
34
+ data: list[dict[str, Any]]
35
+ has_more: bool
36
+ url: str | None = None
37
+
38
+
39
+ # This is a short term solution to allow inference API to return metrics
40
+ # The ideal way to do this is to have a way for all response types to include metrics
41
+ # and all metric events logged to the telemetry API to be included with the response
42
+ # To do this, we will need to augment all response types with a metrics field.
43
+ # We have hit a blocker from stainless SDK that prevents us from doing this.
44
+ # The blocker is that if we were to augment the response types that have a data field
45
+ # in them like so
46
+ # class ListModelsResponse(BaseModel):
47
+ # metrics: Optional[List[MetricEvent]] = None
48
+ # data: List[Models]
49
+ # ...
50
+ # The client SDK will need to access the data by using a .data field, which is not
51
+ # ergonomic. Stainless SDK does support unwrapping the response type, but it
52
+ # requires that the response type to only have a single field.
53
+
54
+ # We will need a way in the client SDK to signal that the metrics are needed
55
+ # and if they are needed, the client SDK has to return the full response type
56
+ # without unwrapping it.
57
+
58
+
59
+ @json_schema_type
60
+ class MetricInResponse(BaseModel):
61
+ """A metric value included in API responses.
62
+ :param metric: The name of the metric
63
+ :param value: The numeric value of the metric
64
+ :param unit: (Optional) The unit of measurement for the metric value
65
+ """
66
+
67
+ metric: str
68
+ value: int | float
69
+ unit: str | None = None
70
+
71
+
72
+ class MetricResponseMixin(BaseModel):
73
+ """Mixin class for API responses that can include metrics.
74
+ :param metrics: (Optional) List of metrics associated with the API response
75
+ """
76
+
77
+ metrics: list[MetricInResponse] | None = None
@@ -0,0 +1,47 @@
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 datetime import datetime
8
+
9
+ from pydantic import BaseModel
10
+
11
+ from llama_stack_api.schema_utils import json_schema_type
12
+
13
+
14
+ @json_schema_type
15
+ class PostTrainingMetric(BaseModel):
16
+ """Training metrics captured during post-training jobs.
17
+
18
+ :param epoch: Training epoch number
19
+ :param train_loss: Loss value on the training dataset
20
+ :param validation_loss: Loss value on the validation dataset
21
+ :param perplexity: Perplexity metric indicating model confidence
22
+ """
23
+
24
+ epoch: int
25
+ train_loss: float
26
+ validation_loss: float
27
+ perplexity: float
28
+
29
+
30
+ @json_schema_type
31
+ class Checkpoint(BaseModel):
32
+ """Checkpoint created during training runs.
33
+
34
+ :param identifier: Unique identifier for the checkpoint
35
+ :param created_at: Timestamp when the checkpoint was created
36
+ :param epoch: Training epoch when the checkpoint was saved
37
+ :param post_training_job_id: Identifier of the training job that created this checkpoint
38
+ :param path: File system path where the checkpoint is stored
39
+ :param training_metrics: (Optional) Training metrics associated with this checkpoint
40
+ """
41
+
42
+ identifier: str
43
+ created_at: datetime
44
+ epoch: int
45
+ post_training_job_id: str
46
+ path: str
47
+ training_metrics: PostTrainingMetric | None = None
@@ -0,0 +1,146 @@
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 typing import Annotated, Literal
8
+
9
+ from pydantic import BaseModel, Field
10
+
11
+ from llama_stack_api.schema_utils import json_schema_type, register_schema
12
+
13
+
14
+ @json_schema_type
15
+ class StringType(BaseModel):
16
+ """Parameter type for string values.
17
+
18
+ :param type: Discriminator type. Always "string"
19
+ """
20
+
21
+ type: Literal["string"] = "string"
22
+
23
+
24
+ @json_schema_type
25
+ class NumberType(BaseModel):
26
+ """Parameter type for numeric values.
27
+
28
+ :param type: Discriminator type. Always "number"
29
+ """
30
+
31
+ type: Literal["number"] = "number"
32
+
33
+
34
+ @json_schema_type
35
+ class BooleanType(BaseModel):
36
+ """Parameter type for boolean values.
37
+
38
+ :param type: Discriminator type. Always "boolean"
39
+ """
40
+
41
+ type: Literal["boolean"] = "boolean"
42
+
43
+
44
+ @json_schema_type
45
+ class ArrayType(BaseModel):
46
+ """Parameter type for array values.
47
+
48
+ :param type: Discriminator type. Always "array"
49
+ """
50
+
51
+ type: Literal["array"] = "array"
52
+
53
+
54
+ @json_schema_type
55
+ class ObjectType(BaseModel):
56
+ """Parameter type for object values.
57
+
58
+ :param type: Discriminator type. Always "object"
59
+ """
60
+
61
+ type: Literal["object"] = "object"
62
+
63
+
64
+ @json_schema_type
65
+ class JsonType(BaseModel):
66
+ """Parameter type for JSON values.
67
+
68
+ :param type: Discriminator type. Always "json"
69
+ """
70
+
71
+ type: Literal["json"] = "json"
72
+
73
+
74
+ @json_schema_type
75
+ class UnionType(BaseModel):
76
+ """Parameter type for union values.
77
+
78
+ :param type: Discriminator type. Always "union"
79
+ """
80
+
81
+ type: Literal["union"] = "union"
82
+
83
+
84
+ @json_schema_type
85
+ class ChatCompletionInputType(BaseModel):
86
+ """Parameter type for chat completion input.
87
+
88
+ :param type: Discriminator type. Always "chat_completion_input"
89
+ """
90
+
91
+ # expects List[Message] for messages
92
+ type: Literal["chat_completion_input"] = "chat_completion_input"
93
+
94
+
95
+ @json_schema_type
96
+ class CompletionInputType(BaseModel):
97
+ """Parameter type for completion input.
98
+
99
+ :param type: Discriminator type. Always "completion_input"
100
+ """
101
+
102
+ # expects InterleavedTextMedia for content
103
+ type: Literal["completion_input"] = "completion_input"
104
+
105
+
106
+ @json_schema_type
107
+ class DialogType(BaseModel):
108
+ """Parameter type for dialog data with semantic output labels.
109
+
110
+ :param type: Discriminator type. Always "dialog"
111
+ """
112
+
113
+ # expects List[Message] for messages
114
+ # this type semantically contains the output label whereas ChatCompletionInputType does not
115
+ type: Literal["dialog"] = "dialog"
116
+
117
+
118
+ ParamType = Annotated[
119
+ StringType
120
+ | NumberType
121
+ | BooleanType
122
+ | ArrayType
123
+ | ObjectType
124
+ | JsonType
125
+ | UnionType
126
+ | ChatCompletionInputType
127
+ | CompletionInputType,
128
+ Field(discriminator="type"),
129
+ ]
130
+ register_schema(ParamType, name="ParamType")
131
+
132
+ """
133
+ # TODO: recursive definition of ParamType in these containers
134
+ # will cause infinite recursion in OpenAPI generation script
135
+ # since we are going with ChatCompletionInputType and CompletionInputType
136
+ # we don't need to worry about ArrayType/ObjectType/UnionType for now
137
+ ArrayType.model_rebuild()
138
+ ObjectType.model_rebuild()
139
+ UnionType.model_rebuild()
140
+
141
+
142
+ class CustomType(BaseModel):
143
+ pylint: disable=syntax-error
144
+ type: Literal["custom"] = "custom"
145
+ validator_class: str
146
+ """
@@ -0,0 +1,146 @@
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 StrEnum
8
+ from typing import Literal, Protocol
9
+
10
+ from pydantic import BaseModel, Field
11
+ from typing_extensions import runtime_checkable
12
+
13
+ from llama_stack_api.resource import Resource, ResourceType
14
+ from llama_stack_api.schema_utils import json_schema_type, webmethod
15
+ from llama_stack_api.tools import ToolDef
16
+ from llama_stack_api.version import LLAMA_STACK_API_V1ALPHA
17
+
18
+
19
+ @json_schema_type
20
+ class ConnectorType(StrEnum):
21
+ """Type of connector."""
22
+
23
+ MCP = "mcp"
24
+
25
+
26
+ class CommonConnectorFields(BaseModel):
27
+ """Common fields for all connectors.
28
+
29
+ :param connector_type: Type of connector
30
+ :param connector_id: Identifier for the connector
31
+ :param url: URL of the connector
32
+ :param server_label: (Optional) Label of the server
33
+ """
34
+
35
+ connector_type: ConnectorType = Field(default=ConnectorType.MCP)
36
+ connector_id: str = Field(..., description="Identifier for the connector")
37
+ url: str = Field(..., description="URL of the connector")
38
+ server_label: str | None = Field(default=None, description="Label of the server")
39
+
40
+
41
+ @json_schema_type
42
+ class Connector(CommonConnectorFields, Resource):
43
+ """A connector resource representing a connector registered in Llama Stack.
44
+
45
+ :param type: Type of resource, always 'connector' for connectors
46
+ :param server_name: (Optional) Name of the server
47
+ :param server_description: (Optional) Description of the server
48
+ """
49
+
50
+ model_config = {"populate_by_name": True}
51
+ type: Literal[ResourceType.connector] = ResourceType.connector
52
+ server_name: str | None = Field(default=None, description="Name of the server")
53
+ server_description: str | None = Field(default=None, description="Description of the server")
54
+
55
+
56
+ @json_schema_type
57
+ class ConnectorInput(CommonConnectorFields):
58
+ """Input for creating a connector
59
+
60
+ :param type: Type of resource, always 'connector' for connectors
61
+ """
62
+
63
+ type: Literal[ResourceType.connector] = ResourceType.connector
64
+
65
+
66
+ @json_schema_type
67
+ class ListConnectorsResponse(BaseModel):
68
+ """Response containing a list of connectors.
69
+
70
+ :param data: List of connectors
71
+ """
72
+
73
+ data: list[Connector]
74
+
75
+
76
+ @json_schema_type
77
+ class ListToolsResponse(BaseModel):
78
+ """Response containing a list of tools.
79
+
80
+ :param data: List of tools
81
+ """
82
+
83
+ data: list[ToolDef]
84
+
85
+
86
+ @runtime_checkable
87
+ class Connectors(Protocol):
88
+ # NOTE: Route order matters! More specific routes must come before less specific ones.
89
+ # Routes with {param:path} are greedy and will match everything including slashes.
90
+
91
+ @webmethod(route="/connectors", method="GET", level=LLAMA_STACK_API_V1ALPHA)
92
+ async def list_connectors(
93
+ self,
94
+ ) -> ListConnectorsResponse:
95
+ """List all configured connectors.
96
+
97
+ :returns: A ListConnectorsResponse.
98
+ """
99
+ ...
100
+
101
+ @webmethod(route="/connectors/{connector_id}/tools/{tool_name}", method="GET", level=LLAMA_STACK_API_V1ALPHA)
102
+ async def get_connector_tool(
103
+ self,
104
+ connector_id: str,
105
+ tool_name: str,
106
+ authorization: str | None = None,
107
+ ) -> ToolDef:
108
+ """Get a tool definition by its name from a connector.
109
+
110
+ :param connector_id: The ID of the connector to get the tool from.
111
+ :param tool_name: The name of the tool to get.
112
+ :param authorization: (Optional) OAuth access token for authenticating with the MCP server.
113
+
114
+ :returns: A ToolDef.
115
+ """
116
+ ...
117
+
118
+ @webmethod(route="/connectors/{connector_id}/tools", method="GET", level=LLAMA_STACK_API_V1ALPHA)
119
+ async def list_connector_tools(
120
+ self,
121
+ connector_id: str,
122
+ authorization: str | None = None,
123
+ ) -> ListToolsResponse:
124
+ """List tools available from a connector.
125
+
126
+ :param connector_id: The ID of the connector to list tools for.
127
+ :param authorization: (Optional) OAuth access token for authenticating with the MCP server.
128
+
129
+ :returns: A ListToolsResponse.
130
+ """
131
+ ...
132
+
133
+ @webmethod(route="/connectors/{connector_id}", method="GET", level=LLAMA_STACK_API_V1ALPHA)
134
+ async def get_connector(
135
+ self,
136
+ connector_id: str,
137
+ authorization: str | None = None,
138
+ ) -> Connector:
139
+ """Get a connector by its ID.
140
+
141
+ :param connector_id: The ID of the connector to get.
142
+ :param authorization: (Optional) OAuth access token for authenticating with the MCP server.
143
+
144
+ :returns: A Connector.
145
+ """
146
+ ...