Skip to content

Commit f5b4a75

Browse files
committed
allow default ai platform in config
1 parent 806d8e1 commit f5b4a75

4 files changed

Lines changed: 36 additions & 8 deletions

File tree

commands.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const generateBaseOptions = [
1010
{
1111
flags: '-p, --platform [name]',
1212
description: 'The AI platform to use.',
13-
default: 'openai',
1413
choices: ['openai', 'claude', 'gemini', 'grok'],
1514
},
1615
{

src/config/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,37 @@ import { yellow } from 'kleur/colors';
33
import { promptConfirm } from '../utils/prompt.js';
44
import { loadConfig, writeConfig } from '../utils/config.js';
55

6+
const PLATFORMS = ['openai', 'anthropic', 'gemini', 'grok'];
7+
68
export async function config() {
79
const config = await loadConfig();
810

911
await promptConfirm(config, [
12+
{
13+
type: 'select',
14+
prompt: true,
15+
required: true,
16+
name: 'DEFAULT_AI_PLATFORM',
17+
description: 'Default AI platform',
18+
choices: [
19+
{
20+
title: 'OpenAI',
21+
value: 'openai',
22+
},
23+
{
24+
title: 'Claude',
25+
value: 'anthropic',
26+
},
27+
{
28+
title: 'Gemini',
29+
value: 'gemini',
30+
},
31+
{
32+
title: 'Grok',
33+
value: 'xai',
34+
},
35+
],
36+
},
1037
{
1138
type: 'text',
1239
name: 'OPENAI_API_KEY',

src/generate/utils/ai.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@ export async function ejectTemplate(options) {
1919
}
2020

2121
export async function createAiClient(options) {
22-
const { platform } = options;
23-
24-
if (!platform) {
25-
throw new Error('Platform not provided.');
26-
}
27-
2822
const config = await loadConfig();
23+
const { DEFAULT_AI_PLATFORM: platform = 'openai' } = config;
2924
const name = getConfigForPlatform(platform);
3025
const apiKey = config[name];
3126

32-
if (!apiKey) {
27+
if (!platform) {
28+
throw new Error('Platform not provided.');
29+
} else if (!apiKey) {
3330
throw new Error(`API key not found for ${platform}. Use bedrock config to set.`);
3431
}
3532

src/utils/prompt.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ function getPromptOptions(option) {
9191
type: 'password',
9292
message: `Enter ${msg}${required ? '' : ' (optional)'}:`,
9393
};
94+
} else if (optionType === 'select') {
95+
return {
96+
message: `Enter ${msg}${required ? '' : ' (optional)'}:`,
97+
...option,
98+
};
9499
} else {
95100
return {
96101
type: 'text',

0 commit comments

Comments
 (0)