generate openapi spec

This commit is contained in:
Dinesh Yeduguru 2025-02-05 11:03:37 -08:00
parent 77c2418a9c
commit 9be83920ef
3 changed files with 87 additions and 6 deletions

View file

@ -898,6 +898,49 @@
"schema": { "schema": {
"type": "string" "type": "string"
} }
},
{
"name": "start_time",
"in": "query",
"required": true,
"schema": {
"type": "integer"
}
},
{
"name": "end_time",
"in": "query",
"required": false,
"schema": {
"type": "integer"
}
},
{
"name": "step",
"in": "query",
"required": false,
"schema": {
"type": "string"
}
},
{
"name": "query_type",
"in": "query",
"required": true,
"schema": {
"$ref": "#/components/schemas/MetricQueryType"
}
},
{
"name": "label_matchers",
"in": "query",
"required": false,
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MetricLabelMatcher"
}
}
} }
] ]
} }
@ -3559,6 +3602,12 @@
"CompletionResponse": { "CompletionResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"metrics": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metric"
}
},
"content": { "content": {
"type": "string", "type": "string",
"description": "The generated completion text" "description": "The generated completion text"
@ -3926,6 +3975,12 @@
"CompletionResponseStreamChunk": { "CompletionResponseStreamChunk": {
"type": "object", "type": "object",
"properties": { "properties": {
"metrics": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metric"
}
},
"delta": { "delta": {
"type": "string", "type": "string",
"description": "New content generated since last chunk. This can be one or more tokens." "description": "New content generated since last chunk. This can be one or more tokens."
@ -5092,6 +5147,12 @@
"EmbeddingsResponse": { "EmbeddingsResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"metrics": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metric"
}
},
"embeddings": { "embeddings": {
"type": "array", "type": "array",
"items": { "items": {

View file

@ -2236,6 +2236,10 @@ components:
CompletionResponse: CompletionResponse:
type: object type: object
properties: properties:
metrics:
type: array
items:
$ref: '#/components/schemas/Metric'
content: content:
type: string type: string
description: The generated completion text description: The generated completion text
@ -2554,6 +2558,10 @@ components:
CompletionResponseStreamChunk: CompletionResponseStreamChunk:
type: object type: object
properties: properties:
metrics:
type: array
items:
$ref: '#/components/schemas/Metric'
delta: delta:
type: string type: string
description: >- description: >-
@ -3341,6 +3349,10 @@ components:
EmbeddingsResponse: EmbeddingsResponse:
type: object type: object
properties: properties:
metrics:
type: array
items:
$ref: '#/components/schemas/Metric'
embeddings: embeddings:
type: array type: array
items: items:

View file

@ -235,15 +235,23 @@ class MetricsMixin(BaseModel):
@json_schema_type @json_schema_type
class MetricQueryType(Enum): class MetricQueryType(Enum):
RANGE = "range" # Returns data points over time range RANGE = "range"
INSTANT = "instant" # Returns single data point INSTANT = "instant"
@json_schema_type
class MetricLabelOperator(Enum):
EQUALS = "="
NOT_EQUALS = "!="
REGEX_MATCH = "=~"
REGEX_NOT_MATCH = "!~"
@json_schema_type @json_schema_type
class MetricLabelMatcher(BaseModel): class MetricLabelMatcher(BaseModel):
name: str name: str
value: str value: str
operator: Literal["=", "!=", "=~", "!~"] = "=" # Prometheus-style operators operator: MetricLabelOperator = MetricLabelOperator.EQUALS
@json_schema_type @json_schema_type
@ -313,9 +321,9 @@ class Telemetry(Protocol):
async def get_metrics( async def get_metrics(
self, self,
metric_name: str, metric_name: str,
start_time: int, # Unix timestamp in seconds start_time: int,
end_time: Optional[int] = None, # Unix timestamp in seconds end_time: Optional[int] = None,
step: Optional[str] = "1m", # Prometheus-style duration: 1m, 5m, 1h, etc. step: Optional[str] = "1m",
query_type: MetricQueryType = MetricQueryType.RANGE, query_type: MetricQueryType = MetricQueryType.RANGE,
label_matchers: Optional[List[MetricLabelMatcher]] = None, label_matchers: Optional[List[MetricLabelMatcher]] = None,
) -> GetMetricsResponse: ... ) -> GetMetricsResponse: ...