Skip to content

Commit

Permalink
fix: openai model validator
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed Jan 29, 2024
1 parent db832d0 commit da2c6d8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/src/views/preference/OpenAISettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const errors: Record<string, Record<string, string>> = inject('errors') as Recor
<AFormItem
:label="$gettext('API Token')"
:validate-status="errors?.openai?.token ? 'error' : ''"
:help="errors?.openai?.token === 'alphanumdash'
:help="errors?.openai?.token === 'alpha_num_dash_dot'
? $gettext('Token is not valid')
: ''"
>
Expand Down
10 changes: 10 additions & 0 deletions internal/validation/alpha_num_dash_dot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package validation

import (
val "github.com/go-playground/validator/v10"
"regexp"
)

func alphaNumDashDot(fl val.FieldLevel) bool {
return regexp.MustCompile(`^[a-zA-Z0-9-.]+$`).MatchString(fl.Field().String())
}
10 changes: 0 additions & 10 deletions internal/validation/alphanumdash.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func Init() {
logger.Fatal("binding validator engine is not initialized")
}

err := v.RegisterValidation("alphanumdash", alphaNumDash)
err := v.RegisterValidation("alpha_num_dash_dot", alphaNumDashDot)

if err != nil {
logger.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions settings/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package settings

type OpenAI struct {
BaseUrl string `json:"base_url" binding:"omitempty,url"`
Token string `json:"token" binding:"omitempty,alphanumdash"`
Token string `json:"token" binding:"omitempty,alpha_num_dash_dot"`
Proxy string `json:"proxy" binding:"omitempty,url"`
Model string `json:"model" binding:"omitempty,alphanumdash"`
Model string `json:"model" binding:"omitempty,alpha_num_dash_dot"`
}

var OpenAISettings = OpenAI{}

0 comments on commit da2c6d8

Please sign in to comment.