summaryrefslogtreecommitdiff
path: root/internal/controlplane/mutations.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/controlplane/mutations.go')
-rw-r--r--internal/controlplane/mutations.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/internal/controlplane/mutations.go b/internal/controlplane/mutations.go
index a781994..3cedf70 100644
--- a/internal/controlplane/mutations.go
+++ b/internal/controlplane/mutations.go
@@ -176,6 +176,9 @@ func (s *Store) CreateModel(ctx context.Context, input CreateModelInput) (Model,
if input.PublicID == "" || len(input.Routes) == 0 {
return Model{}, 0, errors.New("model requires public_id and at least one route")
}
+ if input.InputPriceMicrosPerMillion < 0 || input.OutputPriceMicrosPerMillion < 0 || input.CacheReadPriceMicrosPerMillion < 0 || input.CacheWritePriceMicrosPerMillion < 0 {
+ return Model{}, 0, errors.New("model prices cannot be negative")
+ }
for i := range input.Routes {
input.Routes[i].ProviderID = strings.TrimSpace(input.Routes[i].ProviderID)
input.Routes[i].UpstreamModel = strings.TrimSpace(input.Routes[i].UpstreamModel)
@@ -193,9 +196,16 @@ func (s *Store) CreateModel(ctx context.Context, input CreateModelInput) (Model,
defer tx.Rollback(ctx)
var result Model
err = tx.QueryRow(ctx, `
- INSERT INTO models (public_id, owned_by) VALUES ($1, $2)
- RETURNING id::text, public_id, owned_by, enabled, created_at`, input.PublicID, input.OwnedBy,
- ).Scan(&result.ID, &result.PublicID, &result.OwnedBy, &result.Enabled, &result.CreatedAt)
+ INSERT INTO models (public_id, owned_by, input_price_micros_per_million, output_price_micros_per_million,
+ cache_read_price_micros_per_million, cache_write_price_micros_per_million)
+ VALUES ($1, $2, $3, $4, $5, $6)
+ RETURNING id::text, public_id, owned_by, input_price_micros_per_million, output_price_micros_per_million,
+ cache_read_price_micros_per_million, cache_write_price_micros_per_million, enabled, created_at`,
+ input.PublicID, input.OwnedBy, input.InputPriceMicrosPerMillion, input.OutputPriceMicrosPerMillion,
+ input.CacheReadPriceMicrosPerMillion, input.CacheWritePriceMicrosPerMillion,
+ ).Scan(&result.ID, &result.PublicID, &result.OwnedBy, &result.InputPriceMicrosPerMillion,
+ &result.OutputPriceMicrosPerMillion, &result.CacheReadPriceMicrosPerMillion,
+ &result.CacheWritePriceMicrosPerMillion, &result.Enabled, &result.CreatedAt)
if err != nil {
return Model{}, 0, fmt.Errorf("create model: %w", err)
}