当前位置:   article > 正文

gpt4free 0.0.1.4版本安装指南

gpt4free

gpt4free很牛,用过的都知道!gpt4free已经升级到0.0.1.4版本,使用方法跟以前略有区别。首先新版本的gpt4free只支持python3.10以上的版本,所以重新安装了python3.10环境。

刚开始用源代码编译编译安装,但是走了弯路,最后用Miniconda包安装,才最终成功。以下就是安装和使用中碰到的问题记录。

pip安装

pip install g4f

使用的时候报错:

    from google.protobuf.internal import type_checkers
  File "/home/skywalk/py10/lib/python3.10/site-packages/google/protobuf/internal/type_checkers.py", line 48, in <module>
    import ctypes
  File "/home/skywalk/py310/lib/python3.10/ctypes/__init__.py", line 8, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

把protobuf版本降低到3.20 ,报错:

  File "/home/skywalk/py10/lib/python3.10/site-packages/pandas/compat/compressors.py", line 7, in <module>
    import bz2
  File "/home/skywalk/py310/lib/python3.10/bz2.py", line 17, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'

把pandas的版本升级到2.1.0rc0 ,结果又出现了ctypes报错;
  File "/home/skywalk/py10/lib/python3.10/site-packages/pandas/errors/__init__.py", line 6, in <module>
    import ctypes
  File "/home/skywalk/py310/lib/python3.10/ctypes/__init__.py", line 8, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

很明显很多库新版本用ctypes都有点问题啊!

最后实在搞不定,装3.10版本Miniconda环境,问题解决。

现在有了新的报错:

raise OSError(errno.ENOSPC, "inotify watch limit reached")
OSError: [Errno 28] inotify watch limit reached

这个报错是系统报错,暂时问题不大,先不管它。

总结下新版本gpt4free一个streamlit网站的步骤:

安装gpt4free pip install g4f

安装相关库:进入gpt4free目录,pip install -r requirements.txt

安装streamlit库:pip install streamlit 

安装js2py库:pip install js2py 

写app_streamlit0.1.4.py 文件:

  1. mport os
  2. import sys
  3. sys.path.append(os.path.join(os.path.dirname(__file__), os.path.pardir))
  4. import g4f
  5. import streamlit as st
  6. from g4f.Provider import DeepAi
  7. def get_answer(question: str) -> str:
  8. # Set cloudflare clearance cookie and get answer from GPT-4 model
  9. try:
  10. tmp = ""
  11. response = g4f.ChatCompletion.create(model='gpt-3.5-turbo', provider=DeepAi, messages=[
  12. {"role": "user", "content": question }], stream=True)
  13. for message in response:
  14. #print(message)
  15. tmp += message
  16. status.text(tmp)
  17. return tmp
  18. except Exception as e:
  19. # Return error message if an exception occurs
  20. return (
  21. f'An error occurred: {e}. Please make sure you are using a valid cloudflare clearance token and user agent.'
  22. )
  23. # Set page configuration and add header
  24. st.set_page_config(
  25. page_title="gpt4freeGUI",
  26. initial_sidebar_state="expanded",
  27. page_icon="
    声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/237999
    推荐阅读
    相关标签