-
I need to instantiate a Whisper loader with no access to the environment, so I want to provide the OpenAI client with my API key in the constructor. I have:
and have confirmed that the gptkey variable contains the correct key. I get the error: `/var/www/src/whisper/node_modules/openai/index.js:90 Error: The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: 'my apiKey' }). Node.js v18.14.2` I had originally tried:
because the latest langchain version uses "openAIApiKey" as the field name in the OpenAI constructor but got the same error so changed to "apiKey" in line with what it suggested. I'm sure I'm doing something simple and stupid but I can't see what :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
🤖 Hi @dmb0058, Good to see you again! I see you're trying to use the LangChain framework with Node.js and the Whisper API. From the context provided, it seems that LangChain is primarily a Python framework. The instantiation of the OpenAI client with an API key in the constructor is done in Python as shown in the example: from langchain.llms import OpenAI
openai = OpenAI(model_name="text-davinci-003", openai_api_key="your-api-key") The error you're encountering seems to be coming from the Node.js OpenAI library, not the LangChain framework. The Node.js OpenAI library expects the API key to be provided either through an environment variable or in the constructor of the OpenAI client. However, it's important to note that the LangChain framework might not be fully compatible with Node.js or the Whisper API as there's no explicit mention or documentation about this in the repository. If you're trying to use LangChain with Node.js, you might need to create a compatibility layer or use a tool that allows you to run Python code within a Node.js environment. I hope this helps! If you have any other questions or need further clarification, feel free to ask. Best, SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
Solved ! Digging through the langchain code I worked out the arcane formula ...
Hope it helps someone. |
Beta Was this translation helpful? Give feedback.
Solved !
Digging through the langchain code I worked out the arcane formula ...
const loader = new OpenAIWhisperAudio(filePath, { clientOptions: { apiKey: gptkey }});
Hope it helps someone.