Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve get api key for kimi-file command #30

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading