Replies: 3 comments 4 replies
-
|
Cool, i think i got to understand the motivation and use case. Thank you for initiating the discussion! @tiswanso I would rather make this called So, i am thinking about the change like the below diff --git a/api/v1alpha1/ai_service_backend.go b/api/v1alpha1/ai_service_backend.go
index a99450ad..850416ab 100644
--- a/api/v1alpha1/ai_service_backend.go
+++ b/api/v1alpha1/ai_service_backend.go
@@ -6,6 +6,7 @@
package v1alpha1
import (
+ "github.com/envoyproxy/gateway/api/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)
@@ -67,10 +68,19 @@ type AIServiceBackendSpec struct {
// +optional
HeaderMutation *HTTPHeaderMutation `json:"headerMutation,omitempty"`
+ // BodyMutation defines the mutation of HTTP body that will be applied to the request
+ // before sending it to the backend.
+ // +optional
+ BodyMutation *HTTPBodyMutation `json:"bodyMutation,omitempty"`
+
// TODO: maybe add backend-level LLMRequestCost configuration that overrides the AIGatewayRoute-level LLMRequestCost.
// That may be useful for the backend that has a different cost calculation logic.
}
+type HTTPBodyMutation struct {
+ JSONPatches []v1alpha1.JSONPatchOperation `json:"jsonPatches,omitempty"`
+}
+
// HTTPHeaderMutation defines the mutation of HTTP headers that will be applied to the request
type HTTPHeaderMutation struct {
// Set overwrites/adds the request with the given header (name, value)wdyt? |
Beta Was this translation helpful? Give feedback.
-
|
I think the existence of this feature would allow folks to have a configuration path to create bodyMutations that functionally do the same as something like: #1396 NOTE: my comment is not in any opposition to adding model specific functionality as more first class config. It's to point out the power of the approach for exposing config for custom bodyMutations using jsonpatches as @mathetake describes. |
Beta Was this translation helpful? Give feedback.
-
|
anyways i think we can add this body mutation stuff! The application of jsonpatches should happen after the translation is done at the later stage of request body processing |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi ai-gateway devs,
Great job so far on this project! Very cool to see the progress and implementation details! After experimenting with the project to solve a specific use-case, I am wondering if there's any proposal yet to allow setting model args via an AIServiceBackend config (similar to
headerMutation)?From an analogous functionality at the client SDK level, this follows a similar pattern as
model_kwargs: https://python.langchain.com/api_reference/openai/llms/langchain_openai.llms.base.OpenAI.html#langchain_openai.llms.base.OpenAI.model_kwargsThis functionality would be essential to enable the use of unmodified agents with various models they weren't originally implemented with exposing the myriad of exact client SDK options.
Is this type of functionality part of any existing proposed or in-progress work?
Detailed Thoughts/Proposal
Proposed API change
new
modelArgMutationfield in AIServicesBackend (similar toheaderMutation)Use-case Background
In a use-case I was trying to see if I could get working out of the box with ai-gateway, I need to set a model arg for a specific model backend. The model backend is an corporate internal service wrapping access to a specific openAI compatible model but requires setting the model argument
user:. I need to make setting this transparent to existing agents to enable them to use this internal model. I've done this type of thing in the past with hacky envoy Lua filters but was hoping setting model args would already be part of the ai-gateway project :-) -- unfortunately not the case.However, it was easy to quickly follow the handling of the model name override in the extproc/translator code to see how the RequestBody methods can be enhanced to set model args in the bodyMutation.
Proof-of-concept
Quick PoC diff showing setting a
user:argThe model arg can be seen when tested with the quickstart
envoy-ai-gateway-basic-testupstreammock model... and similar functionality with a hardcoded value inextproc/translator/openai_azureopenai.go.Beta Was this translation helpful? Give feedback.
All reactions