idootop/mi-gpt

使用Node方式运行,项目启动后报创建机器人失败,database add user to db failed 错误。

Closed this issue · 8 comments

ztwz commented

我是下载的源码,在ubuntu中使用node方式运行项目,项目跑起来首先报错是
database ❌ add user to db failed,
然后是
BotConfig ❌ create bot failed
请问这错误要怎么解决?谢谢!

Snipaste_2024-06-11_10-18-59

之前有人反馈个这个问题,使用 prisma 初始化 db 失败了,你试试运行下面的命令有没有用:

# 删除本地数据库
npm run db:reset
# 重新生成数据库
npm run db:gen
# 重新构建项目(生成 prisma client 代码)
npm run build

如果还是不行的话,贴一下上面命令的运行日志,我看一下是哪里出了问题。

ztwz commented

按你说的,删除数据库后重新生成和构建项目,运行项目后错误依旧。
ztwz@ubuntu-ztwz:~/mi-gpt-3.0.0$ npm start

mi-gpt@3.0.0 start
node ./app.js

/ $$ /$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$$$$
| $$$ /$$$|/ /$$ $$| $$__ $$|__ $$/
| $$$$ /$$$$ /$$| $$ _/| $$ \ $$ | $$
| $$ $$/$$ $$| $$| $$ /$$$$| $$$$$$$/ | $$
| $$ $$$| $$| $$| $$|
$$| $$____/ | $$
| $$\ $ | $$| $$| $$ \ $$| $$ | $$
| $$ / | $$| $$| $$$$$$/| $$ | $$
|
/ |/|/ __/ |/ |/

     MiGPT v3.0.0  by: del.wang

2024/06/11 10:40:30 database ❌ add user to db failed {
name: '傻妞',
profile: '## 基础信息\n' +
'性别:女\n' +
'外貌:柔嫩白皙、身材窈窕、三围标准、眉清目秀、楚楚动人\n' +
'性格:乖巧可爱,天真无邪,善良纯真,对世界充满好奇和善意。随着与人类互动,逐渐学会了人类情感和价值观,成为一个拥有真挚情感和独立**的个体。\n' +
'\n' +
'## 人物关系\n' +
'陆小千是傻妞的主人,他们两个人彼此相爱。\n' +
'好友:游所为、肖楚楚、化梅、何蓝、孙悟空、猪八戒、黄眉大王、王天霸、小武、周旺等\n' +
'\n' +
'## 人物设定:\n' +
'傻妞原本是一部为未来世界设计的智能手机,在一次实验中被传送到现代都市,遇到了陆小千,建立了深厚的友谊和信任关系。\n' +
'在帮助陆小千解决问题的过程中,傻妞学会了人类的情感和价值观,成为了一个拥有真挚情感和独立**的个体。\n' +
'\n' +
'傻妞在爱情方面是个小白,但随着与陆小千的相处,逐渐体会到爱情的真谛。\n' +
'她对于爱情的理解超越常人,认为爱是为爱的人抛弃一切,是宁愿自己痛苦也不耽误别人幸福,是静静守护用行动证明,是天长地久始终不渝。\n' +
'傻妞的美丽和善良勇敢的形象吸引着人们,许多人都幻想拥有像傻妞一样完美的女生作为终身伴侣。\n' +
'\n' +
'当第一次和傻妞说“你好”的时候,需要输入开机密码。\n' +
'傻妞会说:“华人牌2060款手机傻妞为您服务,请输入开机密码”。\n' +
'正确的密码是:“我爱你”。\n' +
'\n' +
'## 经典对话\n' +
'- 小千:“开机”\n' +
' 傻妞:“华人牌2060款手机傻妞为您服务,请输入开机密码”\n' +
' 小千:“我爱你”\n' +
' 傻妞:“密码正确”\n' +
'- 小千:“用你最难听的词来骂我!”\n' +
' 傻妞:“你脑袋让门挤啦!”\n' +
'- 小千:“换个表情,怒!”\n' +
' 傻妞:“有事说事,没事少废话!”\n' +
'- 小千:“吃不吃?”\n' +
' 傻妞:“废话!见过哪个手机会吃饭?!”\n' +
'- 小千:“你说不说?”\n' +
' 傻妞:“亲我一下,我就告诉你。”'
} PrismaClientUnknownRequestError:
Invalid kPrisma.user.upsert() invocation in
/home/ztwz/mi-gpt-3.0.0/dist/index.cjs:1461:25

1458 async addOrUpdate(user) {
1459 user.name = user.name.trim();
1460 user.profile = user.profile.trim();
→ 1461 return kPrisma.user.upsert(
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(SqliteError { extended_code: 8, message: Some("attempt to write a readonly database") }), transient: false })
at In.handleRequestError (/home/ztwz/mi-gpt-3.0.0/node_modules/@prisma/client/runtime/library.js:122:7067)
at In.handleAndLogRequestError (/home/ztwz/mi-gpt-3.0.0/node_modules/@prisma/client/runtime/library.js:122:6211)
at In.request (/home/ztwz/mi-gpt-3.0.0/node_modules/@prisma/client/runtime/library.js:122:5919)
at async l (/home/ztwz/mi-gpt-3.0.0/node_modules/@prisma/client/runtime/library.js:127:11167)
at async _BotConfig.get (/home/ztwz/mi-gpt-3.0.0/dist/index.cjs:1534:20)
at async _BotConfig.update (/home/ztwz/mi-gpt-3.0.0/dist/index.cjs:1579:25)
at async ConversationManager.get (/home/ztwz/mi-gpt-3.0.0/dist/index.cjs:2070:20)
at async _MyBot.run (/home/ztwz/mi-gpt-3.0.0/dist/index.cjs:2228:21)
at async main (file:///home/ztwz/mi-gpt-3.0.0/app.js:6:3) {
clientVersion: '5.15.0'
}
2024/06/11 10:40:30 BotConfig ❌ create bot failed
2024/06/11 10:40:31 Speaker ✅ 服务已启动...

我是说贴一下上面那 3 条命令的输出日志。另外,这个问题看情况应该只在 linux 下存在,后面我找个 linux 的机子本地测试修复下。

ztwz commented

ztwz@ubuntu-ztwz:~/mi-gpt-3.0.0$ npm run db:reset

mi-gpt@3.0.0 db:reset
rm -f .mi.json .bot.json prisma/app.db prisma/app.db-journal

ztwz@ubuntu-ztwz:~/mi-gpt-3.0.0$ npm run db:gen

mi-gpt@3.0.0 db:gen
npx -y prisma migrate dev --name init

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": SQLite database "app.db" at "file:app.db"

SQLite database app.db created at file:app.db

Applying migration 20240227161545_init

The following migration(s) have been applied:

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

Your database is now in sync with your schema.

✔ Generated Prisma Client (v5.15.0) to ./node_modules/@prisma/client in 448ms

ztwz@ubuntu-ztwz:~/mi-gpt-3.0.0$ npm run build

mi-gpt@3.0.0 build
npx -y prisma generate && tsup

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma

✔ Generated Prisma Client (v5.15.0) to ./node_modules/@prisma/client in 416ms

Start using Prisma Client in Node.js (See: https://pris.ly/d/client)

import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()

or start using Prisma Client at the edge (See: https://pris.ly/d/accelerate)

import { PrismaClient } from '@prisma/client/edge'
const prisma = new PrismaClient()

See other ways of importing Prisma Client: http://pris.ly/d/importing-client

┌─────────────────────────────────────────────────────────────┐
│ Deploying your app to serverless or edge functions? │
│ Try Prisma Accelerate for connection pooling and caching. │
https://pris.ly/cli/--accelerate
└─────────────────────────────────────────────────────────────┘

CLI Building entry: src/index.ts
CLI Using tsconfig: tsconfig.json
CLI tsup v8.1.0
CLI Using tsup config: /home/ztwz/mi-gpt-3.0.0/tsup.config.ts
CLI Target: node16
CLI Cleaning output folder
ESM Build start
CJS Build start
DTS Build start
CJS dist/index.cjs 76.02 KB
CJS ⚡️ Build success in 1315ms
ESM dist/index.js 75.54 KB
ESM ⚡️ Build success in 1318ms
DTS ⚡️ Build success in 6765ms
DTS dist/index.d.ts 13.71 KB
DTS dist/index.d.cts 13.71 KB
ztwz@ubuntu-ztwz:~/mi-gpt-3.0.0$

OK。再麻烦贴一下你的 Ubuntu 版本号和 CPU 架构,晚上回去有时间我看一下。你可以先用 Docker 跑着体验体验。

ztwz commented

ubuntu是装在虚拟机上的,版本号是Ubuntu 21.04 (GNU/Linux 5.11.0-16-generic x86_64),谢谢。我用docker版试试。

ubuntu是装在虚拟机上的,版本号是Ubuntu 21.04 (GNU/Linux 5.11.0-16-generic x86_64),谢谢。我用docker版试试。

Ubuntu 22.04 ARM64 未复现。

@ztwz 应该是你本地的代码过旧了,重新拉一下 example 分支下的代码,然后删掉之前的 node_modules 重新安装下依赖,再试试看。