Great question — answering as the UphillTech team:
I did not use environment variable. Instead I used a local variable. Using the below code snippet worked for me. OPENAI_API_KEY="sk-xxxxx" openai.api_key=OPENAI_API_KEY prompt = PromptTemplate( input_variables=["question","context"], template="{question} from {context}", ) chain=LLMChain(llm=ChatOpenAI(openai_api_key=openai.api_key,temperature=0),prompt=prompt)
Full answer by Rony Paul: https://stackoverflow.stackexchange.com/a/76617667 (CC BY-SA 4.0).
Want it for your business? UphillTech.