resolveOpenAIKey attempts to find an OpenAI key quickly without extra config. resolveOpenAIKey reads the key from OPENAI_API_KEY and caches it for reuse.
(context.Context)
| 2870 | // resolveOpenAIKey attempts to find an OpenAI key quickly without extra config. |
| 2871 | // resolveOpenAIKey reads the key from OPENAI_API_KEY and caches it for reuse. |
| 2872 | func resolveOpenAIKey(context.Context) (string, error) { |
| 2873 | if key := strings.TrimSpace(os.Getenv(openAIAPIKeyEnv)); key != "" { |
| 2874 | cachedOpenAIKey = key |
| 2875 | return key, nil |
| 2876 | } |
| 2877 | |
| 2878 | if cachedOpenAIKey != "" { |
| 2879 | return cachedOpenAIKey, nil |
| 2880 | } |
| 2881 | |
| 2882 | return "", fmt.Errorf("%s is not set; export it before running %s commit", openAIAPIKeyEnv, commandName) |
| 2883 | } |
| 2884 | |
| 2885 | func reportError(ctx *snap.Context, err error) error { |
| 2886 | if err == nil { |