Skip to main content

Python chatgpt api

Project description

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为真实启动的)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-chatgpt-plus-0.2.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_chatgpt_plus-0.2.0-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file py-chatgpt-plus-0.2.0.tar.gz.

File metadata

  • Download URL: py-chatgpt-plus-0.2.0.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for py-chatgpt-plus-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7ea0758f0ba78fe15df538183d2844f35c2e2f9851d19b87a9f3d561f195a0ac
MD5 7e82dbc3632efab39bb83e945d2f103b
BLAKE2b-256 45bf3a5346f635fc4e2d1640a5847b65a7d699b6d4bf792e031ada1ce3353cf1

See more details on using hashes here.

File details

Details for the file py_chatgpt_plus-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_chatgpt_plus-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d72a7aaf72b399115f2e8d83a2cb30c84e7e0cb422e013adb3ba8a185b9c5fea
MD5 3b718b5fb3fd324c034c30a7f11f730c
BLAKE2b-256 24241abb8d62f1c430fc82746c46ebc103ebc185dcb9e2802e4d396ac47c1f40

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page