Skip to content

Commit

Permalink
Adds schema
Browse files Browse the repository at this point in the history
Signed-off-by: Takeshi Yoneda <[email protected]>
  • Loading branch information
mathetake committed Dec 3, 2024
1 parent 6cee7bc commit 897fb3b
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 1 deletion.
49 changes: 48 additions & 1 deletion api/v1alpha1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
//
// This serves as a way to define a "unified" LLM API for a Gateway which allows downstream
// clients to use a single schema API to interact with multiple LLM backends.
//
// The InputSchema is used to determine the structure of the requests that the Gateway will
// receive. And then the Gateway will route the traffic to the appropriate LLMBackend based
// on the output schema of the LLMBackend while doing the other necessary jobs like rate limit, etc.
type LLMRoute struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -29,6 +33,10 @@ type LLMRouteList struct {

// LLMRouteSpec details the LLMRoute configuration.
type LLMRouteSpec struct {
// APISchema specifies the API schema of the input that the target Gateway(s) will receive.
// Based on this schema, the ai-gateway will perform the necessary transformation to the
// output schema specified in the selected LLMBackend during the routing process.
APISchema LLMAPISchema `json:"inputSchema"`
// TargetRefs are the names of the Gateway resources this policy is being attached to.
// The namespace is "local", i.e. the same namespace as the LLMRoute.
//
Expand Down Expand Up @@ -69,4 +77,43 @@ type LLMBackendList struct {
}

// LLMBackendSpec details the LLMBackend configuration.
type LLMBackendSpec struct{}
type LLMBackendSpec struct {
// APISchema specifies the API schema of the output that this LLMBackend can accept.
// Based on this schema, the ai-gateway will perform the necessary transformation for
// the pair of LLMRoute.APISchema and LLMBackend.APISchema.
//
// This is required to be set.
APISchema LLMAPISchema `json:"outputSchema"`
}

// LLMAPISchema defines the API schema of either LLMRoute (the input) or LLMBackend (the output).
//
// This allows the ai-gateway to understand the input and perform the necessary transformation
// depending on the API schema pair (input, output).
//
// Note that this is vendor specific, and the compatibility of the input and output API schema
// is determined by them.
type LLMAPISchema struct {
// Schema is the API schema of the LLMRoute or LLMBackend.
//
// +kubebuilder:validation:Enum=OpenAI;AWSBedrock
Schema APISchema `json:"schema"`

// Version is the version of the API schema.
// This will be used to determine the compatibility of the input and output API schema.
Version string `json:"version,omitempty"`
}

// APISchema defines the API schema.
type APISchema string

const (
// APISchemaOpenAI is the OpenAI schema.
//
// https://platform.openai.com/docs/overview
APISchemaOpenAI APISchema = "OpenAI"
// APISchemaAWSBedrock is the AWS Bedrock schema.
//
// https://docs.aws.amazon.com/bedrock/latest/APIReference/API_Operations_Amazon_Bedrock_Runtime.html
APISchemaAWSBedrock APISchema = "AWSBedrock"
)
17 changes: 17 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ spec:
type: object
spec:
description: Spec defines the details of the LLM policy.
properties:
outputSchema:
description: |-
APISchema specifies the API schema of the output that this LLMBackend can accept.
Based on this schema, the ai-gateway will perform the necessary transformation for
the pair of LLMRoute.APISchema and LLMBackend.APISchema.
This is required to be set.
properties:
schema:
description: Schema is the API schema of the LLMRoute or LLMBackend.
enum:
- OpenAI
- AWSBedrock
type: string
version:
description: |-
Version is the version of the API schema.
This will be used to determine the compatibility of the input and output API schema.
type: string
required:
- schema
type: object
required:
- outputSchema
type: object
type: object
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ spec:
This serves as a way to define a "unified" LLM API for a Gateway which allows downstream
clients to use a single schema API to interact with multiple LLM backends.
The InputSchema is used to determine the structure of the requests that the Gateway will
receive. And then the Gateway will route the traffic to the appropriate LLMBackend based
on the output schema of the LLMBackend while doing the other necessary jobs like rate limit, etc.
properties:
apiVersion:
description: |-
Expand Down Expand Up @@ -60,6 +64,26 @@ spec:
type: object
maxItems: 128
type: array
inputSchema:
description: |-
APISchema specifies the API schema of the input that the target Gateway(s) will receive.
Based on this schema, the ai-gateway will perform the necessary transformation to the
output schema specified in the selected LLMBackend during the routing process.
properties:
schema:
description: Schema is the API schema of the LLMRoute or LLMBackend.
enum:
- OpenAI
- AWSBedrock
type: string
version:
description: |-
Version is the version of the API schema.
This will be used to determine the compatibility of the input and output API schema.
type: string
required:
- schema
type: object
targetRefs:
description: |-
TargetRefs are the names of the Gateway resources this policy is being attached to.
Expand Down Expand Up @@ -116,6 +140,8 @@ spec:
type: object
maxItems: 128
type: array
required:
- inputSchema
type: object
type: object
served: true
Expand Down

0 comments on commit 897fb3b

Please sign in to comment.