Skip to content

Fix error when locating config.yaml #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions azure/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/stulzq/azure-openai-proxy/util"
"log"
"net/url"
"os"
"path/filepath"
"strings"
)
Expand Down Expand Up @@ -101,6 +102,22 @@ func InitFromConfigFile() error {
configFile = filepath.Join(util.GetWorkdir(), configFile)
}

if _, err := os.Stat(configFile); os.IsNotExist(err) {
log.Printf("config file %s does not exist, falling back to environment variables", configFile)
apiVersion := viper.GetString(constant.ENV_AZURE_OPENAI_API_VER)
endpoint := viper.GetString(constant.ENV_AZURE_OPENAI_ENDPOINT)
openaiModelMapper := viper.GetString(constant.ENV_AZURE_OPENAI_MODEL_MAPPER)
if endpoint != "" && openaiModelMapper != "" {
if apiVersion == "" {
apiVersion = "2023-07-01-preview"
}
InitFromEnvironmentVariables(apiVersion, endpoint, openaiModelMapper)
return nil
} else {
return fmt.Errorf("config file %s does not exist and no environment variables set", configFile)
}
}

viper.SetConfigType("yaml")
viper.SetConfigFile(configFile)
if err := viper.ReadInConfig(); err != nil {
Expand Down