GithubHelp home page GithubHelp logo

rosemary666 / chatgpt Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 2.0 3.27 MB

chatgpt库的调用, 支持流式和非流式,可以实现类似官方chatgpt的显示效果

License: Apache License 2.0

Python 96.83% Shell 3.17%
chatapp chatgpt chatgpt-api chatgpt-python chatgpt-sdk chatgpt3 python

chatgpt's Introduction

chatgpt

Forks Stars Contributors Docs Pypi License: Apache2.0

DOCS

chatgpt库的封装调用, 支持流式和非流式。

特性

  • 支持流式和非流式
  • 支持底层调用chatgpt的封装(很easy启动)
  • 支持上层Http服务的封装调用(支持sse方式)

调用

安装

pip install py-chatgpt-plus

底层调用

  • 非流式
from py_chatgpt_plus.core.chat_gpt_3 import ChatGptV3

cg = ChatGptV3(
    api_key="*****",
    system_prompt="请帮我把以下的工作内容填充为工作周报,用markdown格式以分点叙述的方式输出:",
)
answer = cg.chat_once("主要开展了三件事情, 第一是完成功能1的开发,第二是完成了xx的需求评审,第三是接待了xx客户")
print(answer)
cg.save_conversations("./conversations.json")
  • 流式
from py_chatgpt_plus.core.chat_gpt_3 import ChatGptV3

cg = ChatGptV3(
    api_key="****"  # 请填写自己生成的api_key
)

streams = cg.chat_stream(prompt="**")  # 返回的流式结果
for stream in streams:
    print(stream)

上层调用

上层支持以sse的接口形式将结果返回给调用方,采用该方式可模拟chatgpt官方网页显示效果。

服务启动方式:

1. cd python/py_chatgpt_plus      
2. 修改conf/service.yaml配置文件(重点配置api_key和proxy)      
3. 执行run.sh即可启动   

接口文档

浏览器打开:

http://${ip}:${port}/api/v1/doc

即可在线访问(注意替换ip和port为真实启动的)

chatgpt's People

Contributors

dejavu6 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

cobanka tridu33

chatgpt's Issues

There is something wrong when using pip to install

Describe the bug

  • pip version: 23.2.1
  • python version: 3.12.1
  • os: Windows 11

Additional Information

pip install py-chatgpt-plus
Collecting py-chatgpt-plus
  Obtaining dependency information for py-chatgpt-plus from https://files.pythonhosted.org/packages/24/24/1abb8d62f1c430fc82746c46ebc103ebc185dcb9e2802e4d396ac47c1f40/py_chatgpt_plus-0.2.0-py3-none-any.whl.metadata
  Using cached py_chatgpt_plus-0.2.0-py3-none-any.whl.metadata (3.7 kB)
Collecting Flask==2.2.3 (from py-chatgpt-plus)
  Obtaining dependency information for Flask==2.2.3 from https://files.pythonhosted.org/packages/95/9c/a3542594ce4973786236a1b7b702b8ca81dbf40ea270f0f96284f0c27348/Flask-2.2.3-py3-none-any.whl.metadata
  Using cached Flask-2.2.3-py3-none-any.whl.metadata (3.9 kB)
Collecting flask-restx==1.1.0 (from py-chatgpt-plus)
  Obtaining dependency information for flask-restx==1.1.0 from https://files.pythonhosted.org/packages/0e/74/1b871716adffdf7b7f65ce83f33722eabde72cc9820f8be95e9265dad013/flask_restx-1.1.0-py2.py3-none-any.whl.metadata
  Using cached flask_restx-1.1.0-py2.py3-none-any.whl.metadata (9.0 kB)
Collecting loguru==0.6.0 (from py-chatgpt-plus)
  Obtaining dependency information for loguru==0.6.0 from https://files.pythonhosted.org/packages/fe/21/e1d1da2586865a159fc73b611f36bdd50b6c4043cb6132d3d5e972988028/loguru-0.6.0-py3-none-any.whl.metadata
  Using cached loguru-0.6.0-py3-none-any.whl.metadata (21 kB)
Collecting pytablewriter==0.64.2 (from py-chatgpt-plus)
  Obtaining dependency information for pytablewriter==0.64.2 from https://files.pythonhosted.org/packages/d0/82/093f5d0729c43c81c4bb54054f9523a75eafb855f6c4d44fe6978cec6695/pytablewriter-0.64.2-py3-none-any.whl.metadata
  Using cached pytablewriter-0.64.2-py3-none-any.whl.metadata (32 kB)
Collecting PyYAML==6.0 (from py-chatgpt-plus)
  Using cached PyYAML-6.0.tar.gz (124 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [54 lines of output]
      running egg_info
      writing lib\PyYAML.egg-info\PKG-INFO
      writing dependency_links to lib\PyYAML.egg-info\dependency_links.txt
      writing top-level names to lib\PyYAML.egg-info\top_level.txt
      Traceback (most recent call last):
        File "D:\PyProject\chat-test\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>      
          main()
        File "D:\PyProject\chat-test\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "D:\PyProject\chat-test\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\build_meta.py", line 325, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\build_meta.py", line 295, in _get_build_requires
          self.run_setup()
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 288, in <module>
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\__init__.py", line 103, in setup   
          return distutils.core.setup(**attrs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 185, in setup
          return run_commands(dist)
                 ^^^^^^^^^^^^^^^^^^
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands
          dist.run_commands()
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\dist.py", line 963, in run_command 
          super().run_command(command)
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
          cmd_obj.run()
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 321, in run
          self.find_sources()
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 329, in find_sources
          mm.run()
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 550, in run
          self.add_defaults()
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 588, in add_defaults
          sdist.add_defaults(self)
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\command\sdist.py", line 102, in add_defaults
          super().add_defaults()
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\_distutils\command\sdist.py", line 251, in add_defaults
          self._add_defaults_ext()
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\_distutils\command\sdist.py", line 336, in _add_defaults_ext
          self.filelist.extend(build_ext.get_source_files())
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "<string>", line 204, in get_source_files
        File "C:\Users\longlin\AppData\Local\Temp\pip-build-env-sg42qil1\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 107, in __getattr__
          raise AttributeError(attr)
      AttributeError: cython_sources
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.