langflow icon indicating copy to clipboard operation
langflow copied to clipboard

Cannot use ChatOpenAI - Component when LANGFLOW_REMOVE_API_KEYS=true

Open 7frank opened this issue 1 year ago • 1 comments

Describe the bug

Using the ChatOpenAI Component, when setting the environment variable LANGFLOW_REMOVE_API_KEYS=true while providing an API key in the frontend, I receive the following error message:

Error building node ChatOpenAI(ID:ChatOpenAI-FT4Cg): 1 validation error for ChatOpenAI root Did not find openai_api_key, please add an environment variable OPENAI_API_KEY which contains it, or pass openai_api_key as a named parameter. (type=value_error)

Browser and Version

  • Browser Firefox
  • Version 123.0 (64-bit)

To Reproduce Steps to reproduce the behavior: 1.start the Application with LANGFLOW_REMOVE_API_KEYS=true 2. create a "new project"
3. add a ChatOpenAI Component 4. fill out the OpenAI Api Key Field with a key 5. Click on 'build trigger / stroke icon '

Screenshots

Additional context

This happens regardless of whether I set the API key in the OpenAI Api Key Field or not. I can see in the Network traffic (see image down below) that my openai api key gets submitted, but it seems to be ignored.

Clarification I understand that if i set the environment variable OPENAI_API_KEY the application will be working again. I wanted to set LANGFLOW_REMOVE_API_KEYS= true so that i can allow multiple users to share flows while preventing them from exposing their API Keys

7frank avatar Mar 05 '24 21:03 7frank

Hey there, @7frank! Great to see you diving into another challenge with Langflow. Let's tackle this one together.

Thank you for providing detailed information about the issue you're experiencing. Based on the context provided, it seems like the LANGFLOW_REMOVE_API_KEYS environment variable is used to determine whether API keys should be removed from the projects saved in the database. This is controlled by the remove_api_keys boolean parameter, which is set based on the value of the LANGFLOW_REMOVE_API_KEYS environment variable.

The ChatOpenAI component handles the openai_api_key parameter by accepting it as an optional argument in the build method and then passing it directly to the ChatOpenAI constructor from the langchain_community.chat_models.openai module. If the openai_api_key is not provided (i.e., it is None), it is still passed to the ChatOpenAI constructor, which implies that the handling of a missing API key (if any specific handling is required) is expected to be implemented within the ChatOpenAI class itself or managed through default behavior in the absence of a key.

From your description, it seems like the ChatOpenAI component is not correctly handling the case when LANGFLOW_REMOVE_API_KEYS is set to true and an API key is provided in the frontend. This could be a bug in the ChatOpenAI component or in the way the LANGFLOW_REMOVE_API_KEYS environment variable is handled.

As a workaround, you could try setting the OPENAI_API_KEY environment variable, as you mentioned. However, this would not solve the issue of allowing multiple users to share flows while preventing them from exposing their API keys.

I would recommend creating an issue in the langflow repository detailing this problem, as it seems to be a bug that needs to be addressed by the maintainers. Please include all the information you provided here, as it will be very helpful for debugging the issue.

I hope this helps, and please let me know if you have any other questions or need further clarification. Dosu

Sources

About Dosu

This 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.

dosubot[bot] avatar Mar 05 '24 21:03 dosubot[bot]