-
Notifications
You must be signed in to change notification settings - Fork 73
fix(llm-transformer): remove unwanted template params from guardrail policies #1689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -269,14 +269,10 @@ func (t *LLMProviderTransformer) transformProxy(proxy *api.LLMProxyConfiguration | |
| operationRegistry[targetKey] = targetOp | ||
| } | ||
|
|
||
| templateParams, err := buildTemplateParams(tmpl, targetPath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to build template params: %w", err) | ||
| } | ||
| pol := api.Policy{ | ||
| Name: llmPol.Name, | ||
| Version: llmPol.Version, | ||
| Params: mergeParams(pathEntry.Params, templateParams), | ||
| Params: copyParams(pathEntry.Params), | ||
| } | ||
| appendOperationPolicy(targetOp, pol) | ||
| attachedPolicyPaths[targetPath] = true | ||
|
|
@@ -510,14 +506,10 @@ func (t *LLMProviderTransformer) transformProvider(provider *api.LLMProviderConf | |
| continue | ||
| } | ||
|
|
||
| templateParams, err := buildTemplateParams(tmpl, targetPath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to build template params: %w", err) | ||
| } | ||
| pol := api.Policy{ | ||
| Name: llmPol.Name, | ||
| Version: llmPol.Version, | ||
| Params: mergeParams(pathEntry.Params, templateParams), | ||
| Params: copyParams(pathEntry.Params), | ||
| } | ||
| appendOperationPolicy(targetOp, pol) | ||
| attachedPolicyPaths[targetPath] = true | ||
|
|
@@ -615,14 +607,10 @@ func (t *LLMProviderTransformer) transformProvider(provider *api.LLMProviderConf | |
| operationRegistry[targetKey] = targetOp | ||
| } | ||
|
|
||
| templateParams, err := buildTemplateParams(tmpl, targetPath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to build template params: %w", err) | ||
| } | ||
| pol := api.Policy{ | ||
| Name: llmPol.Name, | ||
| Version: llmPol.Version, | ||
| Params: mergeParams(pathEntry.Params, templateParams), | ||
| Params: copyParams(pathEntry.Params), | ||
| } | ||
| appendOperationPolicy(targetOp, pol) | ||
| attachedPolicyPaths[targetPath] = true | ||
|
|
@@ -793,6 +781,19 @@ func mergeParams(base map[string]interface{}, extra map[string]interface{}) *map | |
| return &merged | ||
| } | ||
|
|
||
| // copyParams creates a shallow copy of the parameters map and returns a pointer to it. | ||
| // Returns nil if the input map is nil or empty. | ||
| func copyParams(params map[string]interface{}) *map[string]interface{} { | ||
| if len(params) == 0 { | ||
| return nil | ||
| } | ||
| copied := make(map[string]interface{}, len(params)) | ||
| for k, v := range params { | ||
| copied[k] = v | ||
| } | ||
| return &copied | ||
| } | ||
|
Comment on lines
+784
to
+795
|
||
|
|
||
| func appendOperationPolicy(op *api.Operation, pol api.Policy) { | ||
| if op.Policies == nil { | ||
| op.Policies = &[]api.Policy{pol} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.