fix(provision): reconcile channel pricing and hosted access
This commit is contained in:
@@ -48,12 +48,41 @@ func flexibleIDSliceValues(raw []string) []any {
|
||||
}
|
||||
|
||||
func (r CreateChannelRequest) MarshalJSON() ([]byte, error) {
|
||||
modelMapping := map[string]map[string]string{}
|
||||
platform := strings.TrimSpace(r.Platform)
|
||||
if platform == "" {
|
||||
platform = "openai"
|
||||
}
|
||||
if len(r.ModelMapping) > 0 {
|
||||
inner := make(map[string]string, len(r.ModelMapping))
|
||||
for key, value := range r.ModelMapping {
|
||||
inner[key] = value
|
||||
}
|
||||
modelMapping[platform] = inner
|
||||
}
|
||||
modelPricing := make([]ChannelModelPricing, 0, len(r.ModelPricing))
|
||||
for _, entry := range r.ModelPricing {
|
||||
pricing := entry
|
||||
if strings.TrimSpace(pricing.Platform) == "" {
|
||||
pricing.Platform = platform
|
||||
}
|
||||
modelPricing = append(modelPricing, pricing)
|
||||
}
|
||||
|
||||
return json.Marshal(struct {
|
||||
Name string `json:"name"`
|
||||
GroupIDs []any `json:"group_ids"`
|
||||
Name string `json:"name"`
|
||||
GroupIDs []any `json:"group_ids"`
|
||||
ModelMapping map[string]map[string]string `json:"model_mapping,omitempty"`
|
||||
ModelPricing []ChannelModelPricing `json:"model_pricing,omitempty"`
|
||||
RestrictModels bool `json:"restrict_models,omitempty"`
|
||||
BillingModelSource string `json:"billing_model_source,omitempty"`
|
||||
}{
|
||||
Name: r.Name,
|
||||
GroupIDs: flexibleIDSliceValues(r.GroupIDs),
|
||||
Name: r.Name,
|
||||
GroupIDs: flexibleIDSliceValues(r.GroupIDs),
|
||||
ModelMapping: modelMapping,
|
||||
ModelPricing: modelPricing,
|
||||
RestrictModels: r.RestrictModels,
|
||||
BillingModelSource: r.BillingModelSource,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user