feat: support set openai api host (#1292)

* Docker

* feat: support set openai api host

* fix css

* fix eslint

* use API in backend & put host check in plugin/openai

* fix go-static-checks
This commit is contained in:
Wujiao233
2023-03-06 20:10:53 +08:00
committed by GitHub
parent fd99c5461c
commit 003161ea54
9 changed files with 108 additions and 6 deletions

View File

@ -19,4 +19,6 @@ type SystemStatus struct {
// Customized server profile, including server name and external url.
CustomizedProfile CustomizedProfile `json:"customizedProfile"`
StorageServiceID int `json:"storageServiceId"`
// OpenAI API Host
OpenAIAPIHost string `json:"openAIApiHost"`
}

View File

@ -29,6 +29,8 @@ const (
SystemSettingStorageServiceIDName SystemSettingName = "storageServiceId"
// SystemSettingOpenAIAPIKeyName is the key type of OpenAI API key.
SystemSettingOpenAIAPIKeyName SystemSettingName = "openAIApiKey"
// SystemSettingOpenAIAPIHost is the key type of OpenAI API path.
SystemSettingOpenAIAPIHost SystemSettingName = "openAIApiHost"
)
// CustomizedProfile is the struct definition for SystemSettingCustomizedProfileName system setting item.
@ -67,6 +69,8 @@ func (key SystemSettingName) String() string {
return "storageServiceId"
case SystemSettingOpenAIAPIKeyName:
return "openAIApiKey"
case SystemSettingOpenAIAPIHost:
return "openAIApiHost"
}
return ""
}
@ -171,6 +175,12 @@ func (upsert SystemSettingUpsert) Validate() error {
if err != nil {
return fmt.Errorf("failed to unmarshal system setting openai api key value")
}
} else if upsert.Name == SystemSettingOpenAIAPIHost {
value := ""
err := json.Unmarshal([]byte(upsert.Value), &value)
if err != nil {
return fmt.Errorf("failed to unmarshal system setting openai api host value")
}
} else {
return fmt.Errorf("invalid system setting name")
}