-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add getAPIKey method that can get api key from env
- Loading branch information
1 parent
87285c7
commit 00ab3a9
Showing
3 changed files
with
39 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { homedir } from 'os'; | ||
import { join } from 'path'; | ||
import { loadConfig } from './config.js'; | ||
|
||
const KIMI_RC_PATH = join(homedir(), '.moonshot_ai_rc'); | ||
|
||
export async function getAPIKey(rcPath = KIMI_RC_PATH) { | ||
if (process.env.MOONSHOT_API_KEY) { | ||
return process.env.MOONSHOT_API_KEY; | ||
} | ||
|
||
const config = await loadConfig(rcPath); | ||
if (config && config.api_key) { | ||
return config.api_key; | ||
} | ||
|
||
return ''; | ||
} |