|
1 | | -export const getAnthropicApiKeyError = () => ` |
2 | | -Error: ANTHROPIC_API_KEY environment variable is not set |
| 1 | +// Provider configuration map |
| 2 | +export const providerConfig: Record< |
| 3 | + string, |
| 4 | + { keyName: string; docsUrl: string } | undefined |
| 5 | +> = { |
| 6 | + anthropic: { |
| 7 | + keyName: 'ANTHROPIC_API_KEY', |
| 8 | + docsUrl: 'https://mycoder.ai/docs/getting-started/anthropic', |
| 9 | + }, |
| 10 | + openai: { |
| 11 | + keyName: 'OPENAI_API_KEY', |
| 12 | + docsUrl: 'https://mycoder.ai/docs/getting-started/openai', |
| 13 | + }, |
| 14 | + xai: { |
| 15 | + keyName: 'XAI_API_KEY', |
| 16 | + docsUrl: 'https://mycoder.ai/docs/getting-started/xai', |
| 17 | + }, |
| 18 | + mistral: { |
| 19 | + keyName: 'MISTRAL_API_KEY', |
| 20 | + docsUrl: 'https://mycoder.ai/docs/getting-started/mistral', |
| 21 | + }, |
| 22 | + // No API key needed for ollama as it uses a local server |
| 23 | + ollama: undefined, |
| 24 | +}; |
3 | 25 |
|
4 | | -Before using MyCoder, you must have an ANTHROPIC_API_KEY specified either: |
| 26 | +/** |
| 27 | + * Generates a provider-specific API key error message |
| 28 | + * @param provider The LLM provider name |
| 29 | + * @returns Error message with provider-specific instructions |
| 30 | + */ |
| 31 | +export const getProviderApiKeyError = (provider: string): string => { |
| 32 | + const config = providerConfig[provider]; |
5 | 33 |
|
6 | | -- As an environment variable, "export ANTHROPIC_API_KEY=[your-api-key]" or |
| 34 | + if (!config) { |
| 35 | + return `Unknown provider: ${provider}`; |
| 36 | + } |
| 37 | + |
| 38 | + const { keyName, docsUrl } = config; |
| 39 | + const platform = process.platform; |
| 40 | + let osSpecificInstructions = ''; |
| 41 | + |
| 42 | + if (platform === 'win32') { |
| 43 | + osSpecificInstructions = `- Using the windows command prompt, "setx ${keyName}=[your-api-key]"`; |
| 44 | + } else if (platform === 'darwin' || platform === 'linux') { |
| 45 | + osSpecificInstructions = `- As an environment variable, "export ${keyName}=[your-api-key]"`; |
| 46 | + } else { |
| 47 | + osSpecificInstructions = `- As an environment variable (platform-specific command)`; |
| 48 | + } |
| 49 | + |
| 50 | + return ` |
| 51 | +Error: ${keyName} environment variable is not set |
| 52 | +
|
| 53 | +Before using MyCoder with ${provider} models, you must have a ${keyName} specified. |
| 54 | +
|
| 55 | +You can set it via: |
| 56 | +${osSpecificInstructions} |
7 | 57 | - In a .env file in the folder you run "mycoder" from |
8 | 58 |
|
9 | | -Get an API key from https://www.anthropic.com/api |
| 59 | +For setup instructions, visit: ${docsUrl} |
10 | 60 | `; |
| 61 | +}; |
| 62 | + |
| 63 | +// Legacy function for backward compatibility |
| 64 | +export const getAnthropicApiKeyError = () => |
| 65 | + getProviderApiKeyError('anthropic'); |
0 commit comments