Giter Club home page Giter Club logo

ywtyltd / test Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 4.0 242 KB

本项目是最易部署的ChatGPT环境,想做点事情的创业者欢迎加群参与讨论!PHP版调用OpenAI最新接口和模型gpt-3.5-turbo进行问答的Demo,采用Stream流模式通信,一边生成一边输出,响应速度超过官网。前端采用JS的EventSource,支持Markdown格式解析,代码有着色处理。页面UI简洁,支持上下文连续会话。源码只有两三个文件,没用任何框架,支持所有PHP版本。只需要修改stream.php中的API_KEY即可使用,也可让浏览者使用自定义API_KEY

CSS 12.58% PHP 16.01% JavaScript 71.42%

test's Introduction


2023-03-11更新版本日志:

  1. 支持多行输入,文本框高度自动调节
  2. AI回答途中可以随时打断
  3. 增加了API_KEY被封禁和未提供API_KEY错误的提示
  4. 增加了一些预设话术
  5. 对手机浏览器进行了适配优化
  6. 修复了AI回复内容包含某些代码时,显示效果异常的bug
  7. 增加了代码复制按钮

PHP版调用OpenAI的API接口进行问答的Demo,代码已更新为调用最新的gpt-3.5-turbo模型。 采用Stream流模式通信,一边生成一边输出,响应速度超过官网。前端采用JS的EventSource,还将Markdown格式文本进行了排版,对代码进行了着色处理。服务器记录所有访问者的对话日志。

很多人想要Demo网站中自己输入API-KEY的功能,已经把代码加上了,取消index.php的注释就行了。为了美观可以把上面的“连续对话”部分注释掉,要不然手机访问不是很友好。

在国内访问OpenAI的新接口会提示超时,如果你本地有HTTP-PROXY,可以把stream.php里面注释掉的“curl_setopt($ch, CURLOPT_PROXY, " http://127.0.0.1:1081 ");”修改一下,这样就可以通过你本地的代理访问openai的接口。

如果你自己没代理,可以使用热心网友提供的反代地址,把“curl_setopt($ch, CURLOPT_URL, ' https://api.openai.com/v1/chat/completions ');”这行里面的网址改成' https://openai.1rmb.tk/v1/chat/completions ',不确定那个什么时候会失效,也可以进群再找其他群友求一个。不过反代的方式访问速度比较慢,最好还是自己买个海外服务器吧,每个月不到20元的有的是。

如果你实在不会买海外服务器,那你有自己的域名吗?有的话还可以用cf worker自建反代


核心代码只有几个文件,没有用任何框架,修改调试很方便,只需要修改stream.php中的API_KEY即可使用。

index.php前面的代码还可以实现区分内外网IP,内网直接访问,外网通过BASIC认证后可访问。可以根据需要删掉注释并进行修改。

部署好了可以放在公司内网,让同事们一起体验chatGPT的强大功能。也可以发到朋友圈分享,互联网技术大牛的形象直接拉满。

test's People

Contributors

ywtyltd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar 程序_小时代 avatar 霓狐 avatar  avatar 夸父爬树 avatar  avatar wangxuncai avatar

Watchers

Kostas Georgiou avatar  avatar

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.