|
1 | | -export const getAnthropicApiKeyError = () => ` |
2 | | -Error: ANTHROPIC_API_KEY environment variable is not set |
3 | | -
|
4 | | -Before using MyCoder with Anthropic models, you must have an ANTHROPIC_API_KEY specified either: |
5 | | -
|
6 | | -- As an environment variable, "export ANTHROPIC_API_KEY=[your-api-key]" or |
7 | | -- In a .env file in the folder you run "mycoder" from |
8 | | -
|
9 | | -Get an API key from https://www.anthropic.com/api |
10 | | -For setup instructions, visit: https://mycoder.ai/docs/getting-started/anthropic |
11 | | -`; |
12 | | - |
13 | | -export const getOpenAIApiKeyError = () => ` |
14 | | -Error: OPENAI_API_KEY environment variable is not set |
15 | | -
|
16 | | -Before using MyCoder with OpenAI models, you must have an OPENAI_API_KEY specified either: |
17 | | -
|
18 | | -- As an environment variable, "export OPENAI_API_KEY=[your-api-key]" or |
| 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 | +}; |
| 25 | + |
| 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]; |
| 33 | + |
| 34 | + if (!config) { |
| 35 | + return `Unknown provider: ${provider}`; |
| 36 | + } |
| 37 | + |
| 38 | + const { keyName, docsUrl } = config; |
| 39 | + |
| 40 | + return ` |
| 41 | +Error: ${keyName} environment variable is not set |
| 42 | +
|
| 43 | +Before using MyCoder with ${provider} models, you must have a ${keyName} specified either: |
| 44 | +
|
| 45 | +- As an environment variable, "export ${keyName}=[your-api-key]" or |
19 | 46 | - In a .env file in the folder you run "mycoder" from |
20 | 47 |
|
21 | | -Get an API key from https://platform.openai.com/api-keys |
22 | | -For setup instructions, visit: https://mycoder.ai/docs/getting-started/openai |
| 48 | +For setup instructions, visit: ${docsUrl} |
23 | 49 | `; |
| 50 | +}; |
24 | 51 |
|
25 | | -export const getXAIApiKeyError = () => ` |
26 | | -Error: XAI_API_KEY environment variable is not set |
27 | | -
|
28 | | -Before using MyCoder with xAI models, you must have an XAI_API_KEY specified either: |
29 | | -
|
30 | | -- As an environment variable, "export XAI_API_KEY=[your-api-key]" or |
31 | | -- In a .env file in the folder you run "mycoder" from |
32 | | -
|
33 | | -Get an API key from https://platform.xai.com |
34 | | -For setup instructions, visit: https://mycoder.ai/docs/getting-started/xai |
35 | | -`; |
36 | | - |
37 | | -export const getMistralApiKeyError = () => ` |
38 | | -Error: MISTRAL_API_KEY environment variable is not set |
39 | | -
|
40 | | -Before using MyCoder with Mistral models, you must have a MISTRAL_API_KEY specified either: |
41 | | -
|
42 | | -- As an environment variable, "export MISTRAL_API_KEY=[your-api-key]" or |
43 | | -- In a .env file in the folder you run "mycoder" from |
44 | | -
|
45 | | -Get an API key from https://console.mistral.ai/api-keys/ |
46 | | -For setup instructions, visit: https://mycoder.ai/docs/getting-started/mistral |
47 | | -`; |
| 52 | +// Legacy function for backward compatibility |
| 53 | +export const getAnthropicApiKeyError = () => |
| 54 | + getProviderApiKeyError('anthropic'); |
0 commit comments