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

[JS] Confusing Error Message When apiKey is Not Passed in Configuration #328

Closed
ManiDoraisamy opened this issue Jun 5, 2024 · 5 comments
Labels
bug Something isn't working js

Comments

@ManiDoraisamy
Copy link

Describe the bug
When the apiKey is not passed in the configuration for the generate function, the error message is confusing and suggests that the model is not found, instead of indicating that the apiKey is missing.

To Reproduce
Steps to reproduce the behavior:

  1. Set up a project using Genkit.
  2. Do not include the apiKey in the generate function's configuration.
  3. Run the code.

Expected behavior
A clear error message indicating that the apiKey is missing and should be included in the configuration.

Code Snippet

const { generate } = require('@genkit-ai/ai');
const { geminiPro } = require('@genkit-ai/googleai');

exports.generate = function() {
    console.log('generate for', geminiPro);
    return generate({
        model: geminiPro,
        config: { 
            temperature: 0.3, 
            maxOutputTokens: 200
            // apiKey is missing here
        },
        prompt: 'What makes you the best LLM out there?',
    })
    .then(result => {
        return result.text();
    })
    .catch(error => {
        console.error('Error generating response:', error);
        throw error;
    });
}

Error Message

Error: Model {"name":"googleai/gemini-pro","info":{"label":"Google AI - Gemini Pro","versions":["gemini-1.0-pro","gemini-1.0-pro-latest","gemini-1.0-pro-001"],"supports":{"multiturn":true,"media":false,"tools":true,"systemRole":true}},"configSchema":{"_def":{"unknownKeys":"strip","catchall":{"_def":{"typeName":"ZodNever"}},"typeName":"ZodObject"},"_cached":null}} not found
    at C:\work\Promptrepo\functions\node_modules\@genkit-ai\ai\lib\generate.js:513:13
    at Generator.next (<anonymous>)
    at fulfilled (C:\work\Promptrepo\functions\node_modules\@genkit-ai\ai\lib\generate.js:53:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Additional context
The error message should more accurately reflect the issue with the missing apiKey. It would help if the error message guided the user to include the apiKey in the configuration using configureGenkit.

Environment:

  • OS: [e.g., Windows 10]
  • Node.js version: [e.g., 14.17.0]
  • Genkit version: [e.g., 1.0.0-beta]
@ManiDoraisamy ManiDoraisamy added bug Something isn't working js labels Jun 5, 2024
@MichaelDoyle
Copy link
Member

Hey @ManiDoraisamy thanks for reporting. Are you able to confirm, is the above the entirety of the code that produced the error? Or was there a call to configureGenkit() somewhere as well?

From what I am able to gather, it's not so much that the apiKey isn't there (although that is definitely required) but rather that Genkit was not yet initialized and/or the googleAI plugin was not loaded (and thus no models were registered).

@ManiDoraisamy
Copy link
Author

ManiDoraisamy commented Jun 6, 2024

You are right, @MichaelDoyle! I didnt call configureGenkit() and therefore googleAI plugin was not loaded. But, this error message looks like the Model not found :

>  Error: Model {"name":"googleai/gemini-pro","info":{"label":"Google AI - Gemini Pro","versions":["gemini-1.0-pro","gemini-1.0-pro-latest","gemini-1.0-pro-001"],"supports":{"multiturn":true,"media":false,"tools":true,"systemRole":true}},"configSchema":{"_def":{"unknownKeys":"strip","catchall":{"_def":{"typeName":"ZodNever"}},"typeName":"ZodObject"},"_cached":null}} not found
>      at C:\work\Promptrepo\functions\node_modules\@genkit-ai\ai\lib\generate.js:513:13
>      at Generator.next (<anonymous>)
>      at fulfilled (C:\work\Promptrepo\functions\node_modules\@genkit-ai\ai\lib\generate.js:53:24)
>      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

May be, the error message could be "Plugin for googleai/gemini-pro not initialized. Initialize it with configureGenkit({plugins:[plugin({apiKey})]})"?

@ManiDoraisamy
Copy link
Author

Just noticed, this is already filed here: #173
Please close this as duplicate.

@MichaelDoyle
Copy link
Member

Thanks again for your report - it really does help us continue to iterate and improve. We'll definitely make this experience better.

@MichaelDoyle
Copy link
Member

Duplicate of #173

@MichaelDoyle MichaelDoyle marked this as a duplicate of #173 Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working js
Projects
None yet
Development

No branches or pull requests

2 participants