Skip to content

Commit

Permalink
rebase# This is a combination of 20 commits.
Browse files Browse the repository at this point in the history
fix some other schema names to be consistent

Signed-off-by: Alexa Griffith <[email protected]>

gitignore idea

Signed-off-by: Alexa Griffith <[email protected]>

fix missing name change

Signed-off-by: Alexa Griffith <[email protected]>

fix filterconfig

Signed-off-by: Alexa Griffith <[email protected]>

fix test

Signed-off-by: Alexa Griffith <[email protected]>

renaming

Signed-off-by: Alexa Griffith <[email protected]>

fix

Signed-off-by: Alexa Griffith <[email protected]>

fix sink test naming

Signed-off-by: Alexa Griffith <[email protected]>

fix controller test

Signed-off-by: Alexa Griffith <[email protected]>

add name rule

Signed-off-by: Alexa Griffith <[email protected]>

fix rule

Signed-off-by: Alexa Griffith <[email protected]>

rename klog pkg

Signed-off-by: Alexa Griffith <[email protected]>

fix cel tests

Signed-off-by: Alexa Griffith <[email protected]>

re-add openai pkg

Signed-off-by: Alexa Griffith <[email protected]>

fix llm backend yaml

Signed-off-by: Alexa Griffith <[email protected]>

fix backend

Signed-off-by: Alexa Griffith <[email protected]>

fix the code style

Signed-off-by: Alexa Griffith <[email protected]>

fix order

Signed-off-by: Alexa Griffith <[email protected]>

fix

Signed-off-by: Alexa Griffith <[email protected]>

lint

Signed-off-by: Alexa Griffith <[email protected]>
  • Loading branch information
alexagriffith committed Jan 15, 2025
1 parent 13b72d6 commit 068ce0e
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ out/
.DS_Store
.terraform
*for_tests.yaml
.idea/

# Files and directories to ignore in the site directory
# dependencies
Expand Down
14 changes: 7 additions & 7 deletions api/v1alpha1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type LLMRouteSpec struct {
// Currently, the only supported schema is OpenAI as the input schema.
//
// +kubebuilder:validation:Required
// +kubebuilder:validation:XValidation:rule="self.schema == 'OpenAI'"
// +kubebuilder:validation:XValidation:rule="self.name == 'OpenAI'"
APISchema LLMAPISchema `json:"schema"`
// Rules is the list of LLMRouteRule that this LLMRoute will match the traffic to.
// Each rule is a subset of the HTTPRoute in the Gateway API (https://gateway-api.sigs.k8s.io/api-types/httproute/).
Expand Down Expand Up @@ -183,27 +183,27 @@ type LLMBackendSpec struct {
// Note that this is vendor specific, and the stability of the API schema is not guaranteed by
// the ai-gateway, but by the vendor via proper versioning.
type LLMAPISchema struct {
// Schema is the API schema of the LLMRoute or LLMBackend.
// Name is the name of the API schema of the LLMRoute or LLMBackend.
//
// +kubebuilder:validation:Enum=OpenAI;AWSBedrock
Schema APISchema `json:"schema"`
Name APISchemaName `json:"name"`

// Version is the version of the API schema.
Version string `json:"version,omitempty"`
}

// APISchema defines the API schema.
type APISchema string
// APISchemaName defines the name of the API schema.
type APISchemaName string

const (
// APISchemaOpenAI is the OpenAI schema.
//
// https://github.com/openai/openai-openapi
APISchemaOpenAI APISchema = "OpenAI"
APISchemaOpenAI APISchemaName = "OpenAI"
// APISchemaAWSBedrock is the AWS Bedrock schema.
//
// https://docs.aws.amazon.com/bedrock/latest/APIReference/API_Operations_Amazon_Bedrock_Runtime.html
APISchemaAWSBedrock APISchema = "AWSBedrock"
APISchemaAWSBedrock APISchemaName = "AWSBedrock"
)

const (
Expand Down
20 changes: 10 additions & 10 deletions filterconfig/filterconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// fallback when the configuration is not explicitly provided.
const DefaultConfig = `
schema:
schema: OpenAI
name: OpenAI
selectedBackendHeaderKey: x-envoy-ai-gateway-selected-backend
modelNameHeaderKey: x-envoy-ai-gateway-model
`
Expand All @@ -30,7 +30,7 @@ modelNameHeaderKey: x-envoy-ai-gateway-model
// # Example configuration:
//
// schema:
// schema: OpenAI
// name: OpenAI
// selectedBackendHeaderKey: x-envoy-ai-gateway-selected-backend
// modelNameHeaderKey: x-envoy-ai-gateway-model
// tokenUsageMetadata:
Expand All @@ -41,18 +41,18 @@ modelNameHeaderKey: x-envoy-ai-gateway-model
// - name: kserve
// weight: 1
// schema:
// schema: OpenAI
// name: OpenAI
// - name: awsbedrock
// weight: 10
// schema:
// schema: AWSBedrock
// name: AWSBedrock
// headers:
// - name: x-envoy-ai-gateway-model
// value: llama3.3333
// - backends:
// - name: openai
// schema:
// schema: OpenAI
// name: OpenAI
// headers:
// - name: x-envoy-ai-gateway-model
// value: gpt4.4444
Expand Down Expand Up @@ -97,17 +97,17 @@ type TokenUsageMetadata struct {
// VersionedAPISchema corresponds to LLMAPISchema in api/v1alpha1/api.go.
type VersionedAPISchema struct {
// Name is the name of the API schema.
Name APISchema `yaml:"name"`
Name APISchemaName `yaml:"name"`
// Version is the version of the API schema. Optional.
Version string `yaml:"version,omitempty"`
}

// APISchema corresponds to APISchema in api/v1alpha1/api.go.
type APISchema string
// APISchemaName corresponds to APISchemaName in api/v1alpha1/api.go.
type APISchemaName string

const (
APISchemaOpenAI APISchema = "OpenAI"
APISchemaAWSBedrock APISchema = "AWSBedrock"
APISchemaOpenAI APISchemaName = "OpenAI"
APISchemaAWSBedrock APISchemaName = "AWSBedrock"
)

// HeaderMatch is an alias for HTTPHeaderMatch of the Gateway API.
Expand Down
2 changes: 1 addition & 1 deletion filterconfig/filterconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestUnmarshalConfigYaml(t *testing.T) {
configPath := path.Join(t.TempDir(), "config.yaml")
const config = `
schema:
schema: OpenAI
name: OpenAI
selectedBackendHeaderKey: x-envoy-ai-gateway-selected-backend
modelNameHeaderKey: x-envoy-ai-gateway-model
tokenUsageMetadata:
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (c *configSink) updateExtProcConfigMap(llmRoute *aigv1a1.LLMRoute) error {
ec := &filterconfig.Config{}
spec := &llmRoute.Spec

ec.Schema.Name = filterconfig.APISchema(spec.APISchema.Name)
ec.Schema.Name = filterconfig.APISchemaName(spec.APISchema.Name)
ec.Schema.Version = spec.APISchema.Version
ec.ModelNameHeaderKey = aigv1a1.LLMModelHeaderKey
ec.SelectedBackendHeaderKey = selectedBackendHeaderKey
Expand All @@ -242,7 +242,7 @@ func (c *configSink) updateExtProcConfigMap(llmRoute *aigv1a1.LLMRoute) error {
err = fmt.Errorf("backend %s not found", key)
return err
} else {
ec.Rules[i].Backends[j].Schema.Name = filterconfig.APISchema(backendObj.Spec.APISchema.Name)
ec.Rules[i].Backends[j].Schema.Name = filterconfig.APISchemaName(backendObj.Spec.APISchema.Name)
ec.Rules[i].Backends[j].Schema.Version = backendObj.Spec.APISchema.Version
}
}
Expand Down
14 changes: 7 additions & 7 deletions internal/controller/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestConfigSink_init(t *testing.T) {
BackendRef: egv1a1.BackendRef{
BackendObjectReference: gwapiv1.BackendObjectReference{Name: "some-backend1", Namespace: ptr.To[gwapiv1.Namespace]("ns1")},
},
APISchema: aigv1a1.LLMAPISchema{Schema: aigv1a1.APISchemaOpenAI},
APISchema: aigv1a1.LLMAPISchema{Name: aigv1a1.APISchemaOpenAI},
},
},
{
Expand All @@ -87,7 +87,7 @@ func TestConfigSink_init(t *testing.T) {
BackendRef: egv1a1.BackendRef{
BackendObjectReference: gwapiv1.BackendObjectReference{Name: "some-backend2", Namespace: ptr.To[gwapiv1.Namespace]("ns1")},
},
APISchema: aigv1a1.LLMAPISchema{Schema: aigv1a1.APISchemaAWSBedrock},
APISchema: aigv1a1.LLMAPISchema{Name: aigv1a1.APISchemaAWSBedrock},
},
},
{
Expand All @@ -96,7 +96,7 @@ func TestConfigSink_init(t *testing.T) {
BackendRef: egv1a1.BackendRef{
BackendObjectReference: gwapiv1.BackendObjectReference{Name: "some-backend3", Namespace: ptr.To[gwapiv1.Namespace]("ns1")},
},
APISchema: aigv1a1.LLMAPISchema{Schema: aigv1a1.APISchemaOpenAI},
APISchema: aigv1a1.LLMAPISchema{Name: aigv1a1.APISchemaOpenAI},
},
},
{
Expand All @@ -105,7 +105,7 @@ func TestConfigSink_init(t *testing.T) {
BackendRef: egv1a1.BackendRef{
BackendObjectReference: gwapiv1.BackendObjectReference{Name: "some-backend4", Namespace: ptr.To[gwapiv1.Namespace]("ns1")},
},
APISchema: aigv1a1.LLMAPISchema{Schema: aigv1a1.APISchemaOpenAI},
APISchema: aigv1a1.LLMAPISchema{Name: aigv1a1.APISchemaOpenAI},
},
},
} {
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestConfigSink_syncLLMRoute(t *testing.T) {
BackendRefs: []aigv1a1.LLMRouteRuleBackendRef{{Name: "apple", Weight: 1}, {Name: "orange", Weight: 1}},
},
},
APISchema: aigv1a1.LLMAPISchema{Schema: aigv1a1.APISchemaOpenAI, Version: "v123"},
APISchema: aigv1a1.LLMAPISchema{Name: aigv1a1.APISchemaOpenAI, Version: "v123"},
},
}
err := fakeClient.Create(context.Background(), route, &client.CreateOptions{})
Expand Down Expand Up @@ -389,7 +389,7 @@ func Test_updateExtProcConfigMap(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "apple", Namespace: "ns"},
Spec: aigv1a1.LLMBackendSpec{
APISchema: aigv1a1.LLMAPISchema{
Schema: aigv1a1.APISchemaAWSBedrock,
Name: aigv1a1.APISchemaAWSBedrock,
},
BackendRef: egv1a1.BackendRef{
BackendObjectReference: gwapiv1.BackendObjectReference{Name: "some-backend1", Namespace: ptr.To[gwapiv1.Namespace]("ns")},
Expand Down Expand Up @@ -425,7 +425,7 @@ func Test_updateExtProcConfigMap(t *testing.T) {
route: &aigv1a1.LLMRoute{
ObjectMeta: metav1.ObjectMeta{Name: "myroute", Namespace: "ns"},
Spec: aigv1a1.LLMRouteSpec{
APISchema: aigv1a1.LLMAPISchema{Schema: aigv1a1.APISchemaOpenAI, Version: "v123"},
APISchema: aigv1a1.LLMAPISchema{Name: aigv1a1.APISchemaOpenAI, Version: "v123"},
Rules: []aigv1a1.LLMRouteRule{
{
BackendRefs: []aigv1a1.LLMRouteRuleBackendRef{
Expand Down
2 changes: 1 addition & 1 deletion internal/extproc/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestProcessor_ProcessRequestBody(t *testing.T) {
p := &Processor{config: &processorConfig{
bodyParser: rbp.impl, router: rt,
factories: map[filterconfig.VersionedAPISchema]translator.Factory{
{Schema: "some-schema", Version: "v10.0"}: factory.impl,
{Name: "some-schema", Version: "v10.0"}: factory.impl,
},
}, requestHeaders: headers}
_, err := p.ProcessRequestBody(context.Background(), &extprocv3.HttpBody{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ spec:
This is required to be set.
properties:
schema:
description: Schema is the API schema of the LLMRoute or LLMBackend.
name:
description: Name is the name of the API schema of the LLMRoute
or LLMBackend.
enum:
- OpenAI
- AWSBedrock
Expand All @@ -179,7 +180,7 @@ spec:
description: Version is the version of the API schema.
type: string
required:
- schema
- name
type: object
required:
- backendRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ spec:
Currently, the only supported schema is OpenAI as the input schema.
properties:
schema:
description: Schema is the API schema of the LLMRoute or LLMBackend.
name:
description: Name is the name of the API schema of the LLMRoute
or LLMBackend.
enum:
- OpenAI
- AWSBedrock
Expand All @@ -193,10 +194,10 @@ spec:
description: Version is the version of the API schema.
type: string
required:
- schema
- name
type: object
x-kubernetes-validations:
- rule: self.schema == 'OpenAI'
- rule: self.name == 'OpenAI'
targetRefs:
description: TargetRefs are the names of the Gateway resources this
LLMRoute is being attached to.
Expand Down
2 changes: 1 addition & 1 deletion tests/cel-validation/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestLLMRoutes(t *testing.T) {
{name: "basic.yaml"},
{
name: "non_openai_schema.yaml",
expErr: `spec.schema: Invalid value: "object": failed rule: self.schema == 'OpenAI'`,
expErr: `spec.schema: Invalid value: "object": failed rule: self.name == 'OpenAI'`,
},
{
name: "unknown_schema.yaml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
namespace: default
spec:
schema:
schema: AWSBedrock
name: AWSBedrock
backendRef:
name: eg-backend
kind: Backend
Expand Down
2 changes: 1 addition & 1 deletion tests/cel-validation/testdata/llmbackends/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
namespace: default
spec:
schema:
schema: AWSBedrock
name: AWSBedrock
backendRef:
name: dog-service
kind: Service
Expand Down
4 changes: 2 additions & 2 deletions tests/cel-validation/testdata/llmbackends/unknown_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ metadata:
namespace: default
spec:
schema:
# Schema must be one of the known schemas, so this is invalid.
schema: SomeRandomVendor
# Name must be one of the known schemas, so this is invalid.
name: SomeRandomVendor
2 changes: 1 addition & 1 deletion tests/cel-validation/testdata/llmroutes/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
namespace: default
spec:
schema:
schema: OpenAI
name: OpenAI
rules:
- matches:
- headers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ metadata:
namespace: default
spec:
schema:
# Input must be OpenAI schema at the moment, so this is invalid.
schema: AWSBedrock
# Schema name must be OpenAI schema at the moment, so this is invalid.
name: AWSBedrock
rules:
- matches:
- headers:
Expand Down
4 changes: 2 additions & 2 deletions tests/cel-validation/testdata/llmroutes/unknown_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ metadata:
namespace: default
spec:
schema:
# Schema must be OpenAI schema at the moment, so this is invalid.
schema: SomeRandomVendor
# Schema name must be OpenAI schema at the moment, so this is invalid.
name: SomeRandomVendor
rules:
- matches:
- headers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
namespace: default
spec:
schema:
schema: OpenAI
name: OpenAI
rules:
- matches:
- headers:
Expand Down
4 changes: 2 additions & 2 deletions tests/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/go-logr/logr"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
klog "k8s.io/klog/v2"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -30,7 +30,7 @@ import (
"github.com/envoyproxy/ai-gateway/tests"
)

var defaultSchema = aigv1a1.LLMAPISchema{Schema: aigv1a1.APISchemaOpenAI, Version: "v1"}
var defaultSchema = aigv1a1.LLMAPISchema{Name: aigv1a1.APISchemaOpenAI, Version: "v1"}

func extProcName(llmRouteName string) string {
return fmt.Sprintf("ai-gateway-llm-route-extproc-%s", llmRouteName)
Expand Down
2 changes: 1 addition & 1 deletion tests/extproc/extproc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"testing"
"time"

"github.com/openai/openai-go"
openai "github.com/openai/openai-go"
"github.com/openai/openai-go/option"
"github.com/stretchr/testify/require"
"sigs.k8s.io/yaml"
Expand Down

0 comments on commit 068ce0e

Please sign in to comment.