GithubHelp home page GithubHelp logo

chatapi-single's People

Contributors

fuergaosi233 avatar gengjiawen avatar w1ndseeker avatar wengchaoxi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chatapi-single's Issues

容器内curl发生异常

# curl -X "POST" "http://localhost:4000/message"     -H 'Content-Type: application/json; charset=utf-8'   -d $'{  "message": "Hello"}'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>SyntaxError: Unexpected token &#39;<br> &nbsp; &nbsp;at JSON.parse (&lt;anonymous&gt;)<br> &nbsp; &nbsp;at createStrictSyntaxError (/app/node_modules/.store/[email protected]/node_modules/body-parser/lib/types/json.js:160:10)<br> &nbsp; &nbsp;at parse (/app/node_modules/.store/[email protected]/node_modules/body-parser/lib/types/json.js:83:15)<br> &nbsp; &nbsp;at /app/node_modules/.store/[email protected]/node_modules/body-parser/lib/read.js:128:18<br> &nbsp; &nbsp;at AsyncResource.runInAsyncScope (node:async_hooks:204:9)<br> &nbsp; &nbsp;at invokeCallback (/app/node_modules/.store/[email protected]/node_modules/raw-body/index.js:231:16)<br> &nbsp; &nbsp;at done (/app/node_modules/.store/[email protected]/node_modules/raw-body/index.js:220:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (/app/node_modules/.store/[email protected]/node_modules/raw-body/index.js:280:7)<br> &nbsp; &nbsp;at IncomingMessage.emit (node:events:512:28)<br> &nbsp; &nbsp;at endReadableNT (node:internal/streams/readable:1359:12), &quot;#&quot; is not valid JSON<br> &nbsp; &nbsp;at JSON.parse (&lt;anonymous&gt;)<br> &nbsp; &nbsp;at createStrictSyntaxError (/app/node_modules/.store/[email protected]/node_modules/body-parser/lib/types/json.js:160:10)<br> &nbsp; &nbsp;at parse (/app/node_modules/.store/[email protected]/node_modules/body-parser/lib/types/json.js:83:15)<br> &nbsp; &nbsp;at /app/node_modules/.store/[email protected]/node_modules/body-parser/lib/read.js:128:18<br> &nbsp; &nbsp;at AsyncResource.runInAsyncScope (node:async_hooks:204:9)<br> &nbsp; &nbsp;at invokeCallback (/app/node_modules/.store/[email protected]/node_modules/raw-body/index.js:231:16)<br> &nbsp; &nbsp;at done (/app/node_modules/.store/[email protected]/node_modules/raw-body/index.js:220:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (/app/node_modules/.store/[email protected]/node_modules/raw-body/index.js:280:7)<br> &nbsp; &nbsp;at IncomingMessage.emit (node:events:512:28)<br> &nbsp; &nbsp;at endReadableNT (node:internal/streams/readable:1359:12)</pre>
</body>
</html>

部署成功后,启动验证发生以上异常

google login error

Prisma schema loaded from prisma/schema.prisma
Datasource "db": SQLite database "data.db" at "file:../data/data.db"

2 migrations found in prisma/migrations

No pending migrations to apply.
Starting chatgpt with config: {
"email": "[email protected]",
"password": "xxx",
"sessionToken": "",
"reverseProxyUrl": "https://chat.y1s1.host",
"isProAccount": false,
"markdown": true,
"debug": false,
"isGoogleLogin": true,
"isMicrosoftLogin": false,
"minimize": false
}
Starting chatgpt failed, retrying...
ProtocolError: Waiting for selector input[type="email"] failed: Protocol error (Runtime.callFunctionOn): Argument should belong to the same JavaScript world as target object
at /app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:329:24
at new Promise ()
at CDPSessionImpl.send (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:325:16)
at ExecutionContext._ExecutionContext_evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:229:46)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async WaitTask.rerun (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/WaitTask.js:98:68)
Starting chatgpt failed, retrying...
ProtocolError: Waiting for selector input[type="email"] failed: Protocol error (Runtime.callFunctionOn): Argument should belong to the same JavaScript world as target object
at /app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:329:24
at new Promise ()
at CDPSessionImpl.send (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:325:16)
at ExecutionContext._ExecutionContext_evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:229:46)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async WaitTask.rerun (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/WaitTask.js:98:68)
Starting chatgpt failed, retrying...
ProtocolError: Waiting for selector input[type="email"] failed: Protocol error (Runtime.callFunctionOn): Argument should belong to the same JavaScript world as target object
at /app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:329:24
at new Promise ()
at CDPSessionImpl.send (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:325:16)
at ExecutionContext._ExecutionContext_evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:229:46)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async WaitTask.rerun (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/WaitTask.js:98:68)
Starting chatgpt failed, retrying...
ProtocolError: Waiting for selector input[type="email"] failed: Protocol error (Runtime.callFunctionOn): Argument should belong to the same JavaScript world as target object
at /app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:329:24
at new Promise ()
at CDPSessionImpl.send (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:325:16)
at ExecutionContext._ExecutionContext_evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:229:46)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async WaitTask.rerun (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/WaitTask.js:98:68)
Starting chatgpt failed, retrying...
ProtocolError: Waiting for selector input[type="email"] failed: Protocol error (Runtime.callFunctionOn): Argument should belong to the same JavaScript world as target object
at /app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:329:24
at new Promise ()
at CDPSessionImpl.send (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:325:16)
at ExecutionContext._ExecutionContext_evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:229:46)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async WaitTask.rerun (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/WaitTask.js:98:68)

docker start timeout

Starting chatgpt failed, retrying...
TimeoutError: Navigation timeout of 30000 ms exceeded
    at LifecycleWatcher._LifecycleWatcher_createTimeoutPromise (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/LifecycleWatcher.js:174:12)

Is it because deployment env (In my case, Oracle Korean) not supported by OpenAI, in that case, Is there any easy way
use proxy inside docker ?

代码围栏不识别

chatgpt回答中存在代码围栏时,无法获取到围栏内容。

chatapi

curl -X "POST" "https://xxxx/message/holego1ts" -H 'Content-Type: application/json; charset=utf-8' -d $'{"message": "写一个聊天机器人前端代码"}'
{"response":"这是一个基于 JavaScript 和 HTML 的简单聊天机器人前端代码示例:这是一个非常基础的示例,可以作为更复杂的聊天机器人应用程序的起点。你可以通过向服务器请求数据并使用 API 获取更多信息来改进它,例如通过使用自然语言处理或机器学习算法等。\n"}

官方网页展示

20230214094828

curl: (56) Recv failure: Connection reset by peer

安装

使用 docker 安装,命令就是复制的README里的。安装好之后,docker logs -f chatgpt-api-single 查看,一切正常:

截屏2023-02-19 20 38 21

使用 docker exec -it chatgpt-api-single /bin/bash 进入容器,输入:

curl -X "POST" "http://localhost:4000/message" \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "message": "Hello"
}'

输出一切正常:

截屏2023-02-19 20 40 58

问题

但是在容器外就一直报错 curl: (56) Recv failure: Connection reset by peer

截屏2023-02-19 20 42 03

其他信息

docker ps 查看一切正常:

截屏2023-02-19 20 42 37

查看端口占用也是应该正常:

截屏2023-02-19 20 44 02

ufw 防火墙也开启了 4000 端口。

还有什么可能的原因导致了这个问题呢🥹

Unable to start

I noticed that the start command in package.json is node dist/src/index.js, but there is no dist directory in the project, so it won't start.

npm run dev is fine!

➜  chatapi-single git:(main) ✗ npm run start

> [email protected] start
> node dist/src/index.js

node:internal/modules/cjs/loader:1063
  throw err;
  ^

Error: Cannot find module '/Users/vincent/Downloads/chatapi-single/dist/src/index.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1060:15)
    at Module._load (node:internal/modules/cjs/loader:905:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v19.6.0

For arm64(RPI4B) chromium is the only option

Create a debian-stable.list file containing:

deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] http://deb.debian.org/debian stable main
deb-src [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] http://deb.debian.org/debian stable main

deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] http://deb.debian.org/debian-security/ stable-security main
deb-src [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] http://deb.debian.org/debian-security/ stable-security main

deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] http://deb.debian.org/debian stable-updates main
deb-src [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] http://deb.debian.org/debian stable-updates main

Dockerfile for arm64, not tested.

FROM node:19
WORKDIR /app

COPY debian-stable.list /etc/apt/sources.list.d/debian-stable.list
RUN apt-get install -y wget curl gnupg  \
  && apt-get update && apt-get -y install chromium xvfb \
  && alias google-chrome="chromium" \
  && echo "Chrome: " && google-chrome --version \
  && ln -s /usr/bin/chromium /usr/bin/google-chrome-stable

COPY package.json .
COPY package-lock.json .
RUN npm install
COPY . .
RUN npm run build
EXPOSE 4000
CMD npx prisma migrate deploy && xvfb-run --server-args="-screen 0 1280x800x24 -ac -nolisten tcp -dpi 96 +extension RANDR -maxclients 2048" node dist/index.js

For testing:

docker build .
docker container run --name mychatapi3 -p 4000:4000 -it --mount type=bind,source=${PWD}/data,target=/app/data mychatapi-single bash
docker commit mychatapi3 mychatapi-single:v1

The original answer is here

It is not possible to start through Docker in the Quickstart.

Prisma schema loaded from prisma/schema.prisma
Datasource "db": SQLite database "data.db" at "file:../data/data.db"

SQLite database data.db created at file:../data/data.db

1 migration found in prisma/migrations

Applying migration 20230211124232_init

The following migration have been applied:

migrations/
└─ 20230211124232_init/
└─ migration.sql

All migrations have been successfully applied.
Starting chatgpt with config: {
"email": "[email protected]",
"password": "xxxxxx1",
"isProAccount": false,
"markdown": false,
"debug": false,
"isGoogleLogin": false,
"isMicrosoftLogin": false,
"minimize": false
}
no access token
Starting chatgpt failed, retrying...
ChatGPTError: Failed to authenticate session
at ChatGPTAPIBrowser.initSession (file:///app/node_modules/chatgpt/build/index.js:1448:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async retries (/app/dist/index.js:150:9)
at async main (/app/dist/index.js:149:5)

npm run start 报错

Starting chatgpt failed, retrying...
Error: Failed to launch the browser process! spawn /usr/bin/google-chrome-stable ENOENT

TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

at onClose (/home/chatapi-single/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:299:20)
at ChildProcess.<anonymous> (/home/chatapi-single/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:293:24)
at ChildProcess.emit (node:events:513:28)
at ChildProcess._handle.onexit (node:internal/child_process:289:12)
at onErrorNT (node:internal/child_process:476:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

当我执行npm run start时报错

日志信息如下:
Starting chatgpt with config: {
"email": "[email protected]",
"password": "xxxxx",
"sessionToken": "",
"reverseProxyUrl": "https://chat.y1s1.host/completions",
"isProAccount": false,
"markdown": false,
"debug": false,
"isGoogleLogin": false,
"isMicrosoftLogin": false,
"minimize": false,
"proxyServer": "http://127.0.0.1:7890"
}
Starting chatgpt failed, retrying...
Error: Failed to launch the browser process!
[1471:1490:0215/023119.348070:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[1471:1471:0215/023119.358143:ERROR:ozone_platform_x11.cc(238)] Missing X server or $DISPLAY
[1471:1471:0215/023119.358186:ERROR:env.cc(255)] The platform failed to initialize. Exiting.

TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

at onClose (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:299:20)
at ChildProcess.<anonymous> (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:290:24)
at ChildProcess.emit (node:events:524:35)
at ChildProcess._handle.onexit (node:internal/child_process:293:12)

排查过程:我以为是代理问题,增加配置后仍是此报错

Need to expose the error message to the client

When the "Conversation not found" error occurs, only the 404 status code is sent to the client. In this case, the user must call DELETE to create a new chat.

Exception <HTTPError 500: 'Internal Server Error'> response_body='{"message":"Something went wrong","error":"Error: ChatGPTAPI err
or 404"}'

The error message should be exposed to the client, allowing the user to better understand why the error occurred and what action they need to take.

Docker

ChatGPTError: ChatGPTAPI error 404
    at ChatGPTAPIBrowser.sendMessage (file:///app/node_modules/chatgpt/build/index.js:1604:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async sendMesasge (/app/dist/index.js:68:20)
    at async /app/dist/index.js:110:26 {
  statusCode: 404,
  statusText: ''
}
ChatGPT "[email protected]" error 404; Conversation not found

Sorry, I cannot locate the code that processes the 'Conversation not found' error. Could you please fix it for me?

Starting chatgpt failed on Mac

Run by Docker and got log:

Error: Failed to launch the browser process!
[149:169:0212/004135.621875:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[149:149:0212/004135.778687:ERROR:ozone_platform_x11.cc(238)] Missing X server or $DISPLAY
[149:149:0212/004135.778740:ERROR:env.cc(255)] The platform failed to initialize.  Exiting.

Any other dependencies needed?

TimeoutError: Waiting for selector `#__next .btn-primary` failed: Waiting failed: 180000ms exceeded

docker安装之后,用示例的发请求取不到结果呢?

log报错

Starting chatgpt failed, retrying...
TimeoutError: Waiting for selector #__next .btn-primary failed: Waiting failed: 180000ms exceeded
at Timeout. (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/WaitTask.js:65:32)
at listOnTimeout (node:internal/timers:568:17)
at process.processTimers (node:internal/timers:511:7)

Docker拉取镜像报错

使用docker-compose.yml文件构建容器,pull镜像时报错:

failed to register layer: ApplyLayer exit status 1 stdout:  stderr: lchown /app/node_modules/tmp/LICENSE: invalid argument

app.listen 默认监听host设定为localhost之后,可能导致docker映射端口无法访问

之前版本app.listen只设定了监听端口,默认情况下,会监听全部interface。
当前版本添加了HOST环境变量提供自定义监听地址的同时,也指定了localhost为默认监听地址。
在Docker中运行的情况下,如果没有将HOST环境变量设定为:0.0.0.0的话,将无法从container外访问服务。

建议在readme中以及.env文件示例中添加HOST=0.0.0.0的默认设定。

Unable to start with Google Auth

$ docker-compose up

Starting chatgpt with config: {
chatgpt-api-single | "email": "[email protected]",
chatgpt-api-single | "password": "",
chatgpt-api-single | "isProAccount": true,
chatgpt-api-single | "markdown": true,
chatgpt-api-single | "debug": false,
chatgpt-api-single | "isGoogleLogin": true,
chatgpt-api-single | "isMicrosoftLogin": false,
chatgpt-api-single | "minimize": false
chatgpt-api-single | }

chatgpt-api-single | Starting chatgpt failed, retrying...
chatgpt-api-single | Error: Failed to launch the browser process!
chatgpt-api-single | [316:351:0212/124533.095555:ERROR:file_path_watcher_inotify.cc(315)] inotify_init() failed: Function not implemented (38)
chatgpt-api-single | [316:354:0212/124533.122735:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory

chatgpt-api-single | [0212/124533.209167:ERROR:scoped_ptrace_attach.cc(27)] ptrace: Function not implemented (38)
chatgpt-api-single | Assertion failed: p_rcu_reader->depth != 0 (/qemu/include/qemu/rcu.h: rcu_read_unlock: 101)
chatgpt-api-single |
chatgpt-api-single |
chatgpt-api-single | TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

MacOS Montrey 12.6

Under the configuration where isGoogleLogin is set to true, failing to fill in the email and password fields will result in the inability to start up. Writing any random email and password will result in the aforementioned issue.

.ENV中变量的含义

能否解释各个变量的含义和用途,除了邮箱/密码,其他的属实有点不知道填

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.