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

GitAuto: 访问 llama-3.1-70b-versatile 失败,请检查网络或 API 密钥 #152

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,5 @@ $ fanyi config set iciba false // disable iciba globally
$ fanyi config set groq false // disable groq globally
$ fanyi config set color false // disable color globally
$ fanyi config set GROQ_API_KEY your-api-key // set GROQ_API_KEY
$ fanyi config set OTHER_API_KEYS your-other-api-keys # set OTHER_API_KEYS
```
3 changes: 2 additions & 1 deletion bin/fanyi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ program
.argument('<value>', '配置项值')
.action(async (key, value) => {
const options = {};
if (key === 'GROQ_API_KEY') {
if (key === 'GROQ_API_KEY' || key === 'OTHER_API_KEYS') {
options[key] = value;
} else {
options[key] = value === 'true' ? true : value === 'false' ? false : value;
Comment on lines +46 to 49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Consider simplifying the conditional assignment for options[key] by using a single line ternary operator to make the code more concise and readable. [enhancement]

Suggested change
if (key === 'GROQ_API_KEY' || key === 'OTHER_API_KEYS') {
options[key] = value;
} else {
options[key] = value === 'true' ? true : value === 'false' ? false : value;
options[key] = (key === 'GROQ_API_KEY' || key === 'OTHER_API_KEYS') ? value : (value === 'true' ? true : value === 'false' ? false : value);

Expand Down Expand Up @@ -71,6 +71,7 @@ program.on('--help', () => {
console.log(`${chalk.cyan(' $ ')}fanyi config set iciba true`);
console.log(`${chalk.cyan(' $ ')}fanyi config set groq true`);
console.log(`${chalk.cyan(' $ ')}fanyi config set GROQ_API_KEY your_api_key_here`);
console.log(`${chalk.cyan(' $ ')}fanyi config set OTHER_API_KEYS your_other_api_keys_here`);
console.log(`${chalk.cyan(' $ ')}fanyi config list`);
console.log('');
});
Expand Down
6 changes: 3 additions & 3 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const gradients = [

export default async (word, options) => {
console.log('');
const { iciba, groq, GROQ_API_KEY } = options;
const { iciba, groq, GROQ_API_KEY, OTHER_API_KEYS } = options;
const endcodedWord = encodeURIComponent(word);

// iciba
Expand All @@ -45,8 +45,8 @@ export default async (word, options) => {

// groq ai
if (isTrueOrUndefined(groq)) {
const groqClient = new Groq({
apiKey: GROQ_API_KEY || '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',
const apiKey = OTHER_API_KEYS || GROQ_API_KEY;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在选择API密钥时,建议优先考虑用户指定的密钥顺序,而不仅仅是OTHER_API_KEYSGROQ_API_KEY的简单选择。这可以通过在配置中允许用户设置密钥的优先级来实现。

apiKey: apiKey || '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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Secret detected: Base64 High Entropy String
Confidence: MEDIUM

Comment on lines +48 to +49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Ensure that the Groq client is instantiated correctly by wrapping the apiKey assignment within the Groq constructor call. [possible bug]

Suggested change
const apiKey = OTHER_API_KEYS || GROQ_API_KEY;
apiKey: apiKey || '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',
const groqClient = new Groq({
apiKey: OTHER_API_KEYS || GROQ_API_KEY || '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',
});

});
const model = 'llama-3.1-70b-versatile';
const spinner = ora(`正在请教 ${model}...`).start();
Expand Down
Loading