Yeonghun1675 / ChatMOF

Predict and Inverse design for metal-organic framework with large-language models (llms)
https://www.nature.com/articles/s41467-024-48998-4
MIT License
50 stars 6 forks source link

AttributeError: module 'openai' has no attribute 'error' in ChatMOF #16

Closed zyc2806 closed 1 week ago

zyc2806 commented 2 weeks ago

Dear Yeonghun: I am encountering an error when running the ChatMOF tool. The error occurs due to the openai module trying to access a non-existent openai.error.Timeout attribute. Below are the steps to reproduce and the full stack trace.

Steps to Reproduce:

  1. Run the chatmof -T run command.
  2. Enter the question: What are the MOFs with 20A or more LCDs and 15A or less PLDs?.

Expected Behavior:

The tool should execute and provide the necessary information about MOFs with specified LCD and PLD values.

Actual Behavior:

An AttributeError is raised, indicating that the openai module has no attribute error.

Stack Trace:

(chatmof_arm) zhangyichen@zhangyichendeMacBook-Pro ~ % chatmof -T run
>>> Console logs (under WARNING level) are disabled.
WARNING:root:File logs (under WARNING level) are disabled.
Warning: The internet tool does not work - 1 validation error for GoogleSearchAPIWrapper
__root__
  Did not find google_api_key, please add an environment variable `GOOGLE_API_KEY` which contains it, or pass  `google_api_key` as a named parameter. (type=value_error)
##################################################

Welcom to ChatMOF!

########## Question ##############################
Please enter the question below >>
What are the MOFs with 20A or more LCDs and 15A or less PLDs?

> Entering new ChatMOF chain...

> Entering new AgentExecutor chain...
Traceback (most recent call last):
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/bin/chatmof", line 8, in <module>
    sys.exit(main())
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/chatmof/cli/main.py", line 72, in main
    f(args)
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/chatmof/cli/run.py", line 76, in run
    main(model=model, temperature=temperature, **kwargs)
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/chatmof/main.py", line 62, in main
    output = chatmof.run(question, callbacks=callback_manager)
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chains/base.py", line 440, in run
    return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chains/base.py", line 243, in __call__
    raise e
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chains/base.py", line 239, in __call__
    else self._call(inputs)
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/chatmof/agents/agent.py", line 32, in _call
    output = self.agent.run(query)
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chains/base.py", line 440, in run
    return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chains/base.py", line 243, in __call__
    raise e
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chains/base.py", line 237, in __call__
    self._call(inputs, run_manager=run_manager)
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/agents/agent.py", line 994, in _call
    next_step_output = self._take_next_step(
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/agents/agent.py", line 797, in _take_next_step
    output = self.agent.plan(
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/agents/agent.py", line 443, in plan
    full_output = self.llm_chain.predict(callbacks=callbacks, **full_inputs)
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chains/llm.py", line 252, in predict
    return self(kwargs, callbacks=callbacks)[self.output_key]
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chains/base.py", line 243, in __call__
    raise e
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chains/base.py", line 237, in __call__
    self._call(inputs, run_manager=run_manager)
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chains/llm.py", line 92, in _call
    response = self.generate([inputs], run_manager=run_manager)
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chains/llm.py", line 102, in generate
    return self.llm.generate_prompt(
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chat_models/base.py", line 230, in generate_prompt
    return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chat_models/base.py", line 125, in generate
    raise e
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chat_models/base.py", line 115, in generate
    self._generate_with_cache(
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chat_models/base.py", line 262, in _generate_with_cache
    return self._generate(
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chat_models/openai.py", line 371, in _generate
    response = self.completion_with_retry(messages=message_dicts, **params)
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chat_models/openai.py", line 313, in completion_with_retry
    retry_decorator = self._create_retry_decorator()
  File "/Users/zhangyichen/miniforge3/envs/chatmof_arm/lib/python3.9/site-packages/langchain/chat_models/openai.py", line 302, in _create_retry_decorator
    retry_if_exception_type(openai.error.Timeout)
AttributeError: module 'openai' has no attribute 'error'

Environment:

Thank you for looking into this issue.

Yeonghun1675 commented 2 weeks ago

Hi @zyc2806,

Thank you for your interest in my research. I checked the error you sent me and found that there is a problem with the dependency of openai. I have added the dependency and released chatmof version 0.2.1. I would appreciate it if you could test it after a reinstallation.

Yeonghun1675 commented 2 weeks ago

Additionally, when I tested the question you mensioned, I found that it throws a TOKEN LIMIT ERROR. This happens when more posts are written than the data provided by OPENAI, because there is a lot of data that falls under that conditional statement. If you modify the question to be specific and include the appropriate amount of data, you should be able to use it without error.