visual-chatgpt icon indicating copy to clipboard operation
visual-chatgpt copied to clipboard

ValidationError: 1 validation error for OpenAI - please help :)

Open ind1-go opened this issue 1 year ago • 7 comments

╭───────────────────── Traceback (most recent call last) ──────────────────────╮ │ /Users/user/PycharmProjects/pythonProject2/visual_chatgpt.py:941 in │ │ │ │ 938 │ │ return state, state, txt + ' ' + image_filename + ' ' │ │ 939 │ │ 940 if name == 'main': │ │ ❱ 941 │ bot = ConversationBot() │ │ 942 │ with gr.Blocks(css="#chatbot .overflow-y-auto{height:500px}") as d │ │ 943 │ │ chatbot = gr.Chatbot(elem_id="chatbot", label="Visual ChatGPT" │ │ 944 │ │ state = gr.State([]) │ │ │ │ /Users/user/PycharmProjects/pythonProject2/visual_chatgpt.py:804 in init │ │ │ │ 801 class ConversationBot: │ │ 802 │ def init(self): │ │ 803 │ │ print("Initializing VisualChatGPT") │ │ ❱ 804 │ │ self.llm = OpenAI(temperature=0) │ │ 805 │ │ self.edit = ImageEditing(device="cuda:6") │ │ 806 │ │ self.i2t = ImageCaptioning(device="cuda:4") │ │ 807 │ │ self.t2i = T2I(device="cuda:1") │ │ │ │ in pydantic.main.BaseModel.init:341 │ ╰──────────────────────────────────────────────────────────────────────────────╯ 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)

ind1-go avatar Mar 11 '23 13:03 ind1-go

# prepare your private openAI private key
export OPENAI_API_KEY={Your_Private_Openai_Key}

wrk226 avatar Mar 11 '23 17:03 wrk226

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)

Have you soloved this problem?Can you share your idea with me?

baipengfeifei avatar Mar 13 '23 10:03 baipengfeifei

# prepare your private openAI private key
export OPENAI_API_KEY={Your_Private_Openai_Key}

it makes no sense,i have tried this idea but this problem still exists, Do you have another idea?

baipengfeifei avatar Mar 13 '23 10:03 baipengfeifei

it makes no sense,i have tried this idea but this problem still exists, Do you have another idea?

If you are on linux, it should work as long as you don't close the command line after export the api key. However, if you are on windows, you may want to mannually set the api key as your enviroment variable.

wrk226 avatar Mar 13 '23 11:03 wrk226

how to use it on windows???

DoubleCore avatar Mar 24 '23 13:03 DoubleCore

I also encountered this issue on Windows 11,I even manually set "OPENAI_API_KEY" in the system environment variable Who can tell me where the problem is? Thank you.

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ D:\PROJECT\Python_Project\VisualChatGPT\visual-chatgpt\visual_chatgpt.py:1051 in <module>        │
│                                                                                                  │
│   1048 │   parser.add_argument('--load', type=str, default="ImageCaptioning_cuda:0,Text2Image_c  │
│   1049 │   args = parser.parse_args()                                                            │
│   1050 │   load_dict = {e.split('_')[0].strip(): e.split('_')[1].strip() for e in args.load.spl  │
│ ❱ 1051 │   bot = ConversationBot(load_dict=load_dict)                                            │
│   1052 │   with gr.Blocks(css="#chatbot .overflow-y-auto{height:500px}") as demo:                │
│   1053 │   │   chatbot = gr.Chatbot(elem_id="chatbot", label="Visual ChatGPT")                   │
│   1054 │   │   state = gr.State([])                                                              │
│                                                                                                  │
│ D:\PROJECT\Python_Project\VisualChatGPT\visual-chatgpt\visual_chatgpt.py:981 in __init__         │
│                                                                                                  │
│    978 │   │   if 'ImageCaptioning' not in load_dict:                                            │
│    979 │   │   │   raise ValueError("You have to load ImageCaptioning as a basic function for V  │
│    980 │   │                                                                                     │
│ ❱  981 │   │   self.llm = OpenAI(temperature=0)                                                  │
│    982 │   │   self.memory = ConversationBufferMemory(memory_key="chat_history", output_key='ou  │
│    983 │   │                                                                                     │
│    984 │   │   self.models = {}                                                                  │
│                                                                                                  │
│ in pydantic.main.BaseModel.__init__:341                                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
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)```

SlowFeather avatar Mar 30 '23 07:03 SlowFeather

If you have manually set the system environment variable then just restart your device once, it'll run.

pranjalanimesh avatar May 11 '23 09:05 pranjalanimesh