Skip to content

Commit

Permalink
improve get api key for kimi-file command
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian committed Jun 7, 2024
1 parent 630f2e1 commit 7c9949d
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions bin/kimi-file.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
#!/usr/bin/env node

import { homedir } from 'os';
import path from 'path';

import inquirer from 'inquirer';

import Kimi from '../lib/kimi.js';
import { loadConfig, saveConfig } from '../lib/config.js';

const KIMI_RC_PATH = path.join(homedir(), '.moonshot_ai_rc');
import { getAPIKey } from '../lib/apikey.js';

const config = await loadConfig(KIMI_RC_PATH);

async function question(prompt) {
const answers = await inquirer.prompt([
{
name: 'question',
...prompt
}
]);
return answers.question.trim();
}
const apiKey = await getAPIKey();

if (!config.api_key) {
const apikey = await question({
message: 'Please input your KIMI api key(you can visit https://platform.moonshot.cn/console/api-keys to get api key):'
});
config.api_key = apikey.trim();
await saveConfig(config, KIMI_RC_PATH);
if (!apiKey) {
console.log('Can not found api key, please set api key via command kimi first.');
process.exit(1);
}

const kimi = new Kimi({apiKey: config.api_key});
const kimi = new Kimi({apiKey: apiKey});

const [command, ...args] = process.argv.slice(2);

Expand Down

0 comments on commit 7c9949d

Please sign in to comment.