patterns-ai-core / langchainrb_rails

MIT License
204 stars 21 forks source link

Missing API KEY when using Docker #61

Open chalmagean opened 7 months ago

chalmagean commented 7 months ago

When trying to deploy with Docker, the precompile step seems to initialize the application and it's calling the initializer, which if you're setting the key using the ENV hash, it will raise an exception.

I'm putting a check around it, but maybe that's not the best option?

if key = ENV["OPENAI_API_KEY"]
  LangchainrbRails.configure do |config|
    config.vectorsearch = Langchain::Vectorsearch::Pgvector.new(
      llm: Langchain::LLM::OpenAI.new(api_key: key)
    )
  end
end
andreibondarev commented 7 months ago

@chalmagean We can try using dotenv and Dotenv.require_keys("OPENAI_API_KEY") but .env is not necessarily the only way people will be setting env vars.