this is my code:
import os
from dotenv import load_dotenv,find_dotenv
load_dotenv(find_dotenv())
print(os.environ.get("OPEN_AI_KEY"))
from langchain.llms import OpenAI
llm=OpenAI(model_name="text-davinci-003",temperature=0.7,max_tokens=512)
print(llm)
when I execute above code I get this error
ValidationError: 1 validation error for OpenAI
__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)
docs say
If you d prefer not to set an environment variable you can pass the key in directly via the openai_api_key named parameter when initiating the OpenAI LLM class:
But already set it and it prints correctly
When I set the llm
by passing named param:
llm=OpenAI(openai_api_key="PASSINGCORRECTKEY", model_name="text-davinci-003",temperature=0.7,max_tokens=512)
llm("Tell me a joke")
then I get this error:
raise ValueError(
"Argument `prompt` is expected to be a string. Instead found "
f"{type(prompt)}. If you want to run the LLM on multiple prompts, use "
"`generate` instead."
)