MCPcopy Index your code
hub / github.com/coder/coder / validateChatModelCallConfig

Function validateChatModelCallConfig

coderd/exp_chats.go:7421–7447  ·  view source on GitHub ↗
(modelConfig *codersdk.ChatModelCallConfig)

Source from the content-addressed store, hash-verified

7419}
7420
7421func validateChatModelCallConfig(modelConfig *codersdk.ChatModelCallConfig) error {
7422 if modelConfig == nil {
7423 return nil
7424 }
7425
7426 costConfig := codersdk.ModelCostConfig{}
7427 if modelConfig.Cost != nil {
7428 costConfig = *modelConfig.Cost
7429 }
7430
7431 pricingFields := []struct {
7432 name string
7433 value *decimal.Decimal
7434 }{
7435 {name: "cost.input_price_per_million_tokens", value: costConfig.InputPricePerMillionTokens},
7436 {name: "cost.output_price_per_million_tokens", value: costConfig.OutputPricePerMillionTokens},
7437 {name: "cost.cache_read_price_per_million_tokens", value: costConfig.CacheReadPricePerMillionTokens},
7438 {name: "cost.cache_write_price_per_million_tokens", value: costConfig.CacheWritePricePerMillionTokens},
7439 }
7440 for _, field := range pricingFields {
7441 if err := validateNonNegativeDecimalField(field.name, field.value); err != nil {
7442 return err
7443 }
7444 }
7445
7446 return nil
7447}
7448
7449func validateNonNegativeDecimalField(name string, value *decimal.Decimal) error {
7450 if value == nil {

Callers 1

Calls 1

Tested by

no test coverage detected