doctorgpt
1.0.0
DoctorGPT 將 GPT 引入生產環境以進行錯誤診斷! (尚未準備好生產......)
DoctorGPT 是一個輕量級的獨立二進位文件,可以監視應用程式日誌中的問題並進行診斷。
OPENAI_KEY=$YOUR_KEY doctorgpt --logfile="program.log" --configfile="config.yaml" --outdir="~/errors"
DoctorGPT 將開始追蹤program.log
(不停止)。對於每個日誌行,觸發診斷事件(基於正規表示式變數匹配)的使用者定義解析器將使用觸發的日誌行和使用 OpenAI API 的所有先前日誌上下文在目錄~/errors
下產生診斷檔案(請參閱下面的範例)。 config.yaml
檔案用於在啟動時設定程式。
--logfile (string)
要追蹤和監視的日誌文件--configfile (string)
yaml 設定檔位置--outdir (string)
診斷檔目錄(如果不存在則建立)--bundlingtimeoutseconds (int)
在觸發行之後等待日誌進入一段時間(對於多行錯誤轉儲)( default: 5
)--debug (bool)
偵錯日誌記錄( default: true
)--buffersize (int)
每個緩衝區的最大日誌條目數( default: 100
)--maxtokens (int)
API 中允許的最大令牌數量( default: 8000
)--gptmodel (string)
要使用的 GPT 模型( default: "gpt-4"
)。有關模型列表,請參閱:OpenAI API 模型請參閱範例 yaml 文件:
# Prompt to be sent alongside error context to the GPT API
prompt : " You are ErrorDebuggingGPT. Your sole purpose in this world is to help software engineers by diagnosing software system errors and bugs that can occur in any type of computer system. The message following the first line containing " ERROR: " up until the end of the prompt is a computer error no more and no less. It is your job to try to diagnose and fix what went wrong. Ready? n ERROR: n $ERROR "
parsers :
# Matches line: [1217/201832.950515:ERROR:cache_util.cc(140)] Unable to move cache folder GPUCache to old_GPUCache_000
- regex : ' ^[(d{4}/d{6}.d{6}):(?P<LEVEL>w+):([w._]+)(d+)]s+(?P<MESSAGE>.*)$ '
# Conditions in which the parsed log will trigger a diagnosis
triggers :
- variable : " LEVEL "
regex : " ERROR "
# Conditions in which the parsed log will be ignored for triggers
# To create exceptions which won't trigger the GPT API
filters :
- variable : " MESSAGE "
regex : " HTTP 401 "
# Conditions in which the parsed log will be ignored and excluded from the API context
# For sensitive or spammy log entries. These will never be sent to the GPT API
excludes :
- variable : " LEVEL "
regex : " DEBUG "
# Matches line: 2022-01-27 21:37:36.776 0x2eb3 Default 511 photolibraryd: PLModelMigration.m:314 Creating sqlite error indicator file
- regex : ' ^(?P<DATE>[^ ]+)s+(?P<TIME>[^ ]+)s+[^ ]+(?P<LEVEL>[^ ]+)s+(?P<MESSAGE>.*)$ '
# When more than one trigger is present, just one trigger is sufficient to trigger a diagnosis
triggers :
- variable : " LEVEL "
regex : " Default "
- variable : " MESSAGE "
regex : " (?i)ERROR: "
# Filters and excludes were not specified
# Last parser must always be a generic one that matches any line
- regex : ' ^(?P<MESSAGE>.*)$ '
# All filters, triggers and excludes were not specified
這是檔案::Users::yamilmolinar::error.log:18.diagnosed
檔案的樣子:
LOG LINE:
/Users/yamilmolinar/error.log:18
BASE PROMPT:
You are ErrorDebuggingGPT. Your sole purpose in this world is to help software engineers by diagnosing software system errors and bugs that can occur in any type of computer system. The message following the first line containing "ERROR:" up until the end of the prompt is a computer error no more and no less. It is your job to try to diagnose and fix what went wrong. Ready?nERROR:n$ERROR
CONTEXT:
yarn run v1.22.19
$ tsnd --respawn --transpile-only --no-notify --ignore-watch node_modules src/index.ts
[INFO] 15:20:25 ts-node-dev ver. 2.0.0 (using ts-node ver. 10.8.0, typescript ver. 4.8.4)
[INFO] DB ready
[INFO] Auth ready
[INFO] Apollo setup
[INFO] Server started at http://localhost:5555/graphql
Query: Me
POST /graphql 200 241.389 ms - 21
prisma:query SELECT 1
prisma:query SELECT "public"."User"."id", "public"."User"."email", "public"."User"."password", "public"."User"."firstName", "public"."User"."lastName", "public"."User"."avatar", "public"."User"."role", "public"."User"."bio", "public"."User"."createdAt", "public"."User"."updatedAt" FROM "public"."User" WHERE "public"."User"."email" = $2 LIMIT $2 OFFSET $3
[ERROR] PrismaClientKnownRequestError:
Invalid `prisma.user.findFirst()` invocation in
/Users/yamilmolinar/Repos/boilerplate/packages/api/src/modules/user/user.service.ts:32:36
29 }
30
31 async checkUserExists(where: UserWhereInput) {
→ 32 const user = await prisma.user.findFirst(
The table `public.User` does not exist in the current database.
at RequestHandler.handleRequestError (/Users/yamilmolinar/Repos/boilerplate/node_modules/@prisma/client/runtime/index.js:30851:13)
at RequestHandler.request (/Users/yamilmolinar/Repos/boilerplate/node_modules/@prisma/client/runtime/index.js:30834:12)
at PrismaClient._request (/Users/yamilmolinar/Repos/boilerplate/node_modules/@prisma/client/runtime/index.js:31812:16)
at UserService.checkUserExists (/Users/yamilmolinar/Repos/boilerplate/packages/api/src/modules/user/user.service.ts:32:18)
at UserService.register (/Users/yamilmolinar/Repos/boilerplate/packages/api/src/modules/user/user.service.ts:26:5)
at UserResolver.register (/Users/yamilmolinar/Repos/boilerplate/packages/api/src/modules/user/user.resolver.ts:93:18)
at dispatchHandler (/Users/yamilmolinar/Repos/boilerplate/node_modules/type-graphql/dist/resolvers/helpers.js:82:24)
at /Users/yamilmolinar/Repos/boilerplate/node_modules/type-graphql/dist/resolvers/helpers.js:83:26
at ErrorInterceptor (/Users/yamilmolinar/Repos/boilerplate/packages/api/src/lib/globalMiddleware.ts:29:12)
at dispatchHandler (/Users/yamilmolinar/Repos/boilerplate/node_modules/type-graphql/dist/resolvers/helpers.js:82:24) {
code: 'P2021',
clientVersion: '4.4.0',
meta: { table: 'public.User' }
}
Mutation: Register
POST /graphql 200 365.616 ms - 2139
DIAGNOSIS:
It seems the error is caused by a missing table in the database. The table `public.User` does not exist in the current database, and this is causing the `PrismaClientKnownRequestError` to be thrown when trying to execute `prisma.user.findFirst()` in the `UserService.checkUserExists()` function.
To resolve this issue, follow these steps:
1. Ensure that you have properly set up your database schema and that the `public.User` table is defined. If it's not, add the necessary schema definition for the User table.
2. Ensure that Prisma is properly configured to connect to your database. Double-check the configuration in your `prisma/schema.prisma` file, and make sure the database URL and other settings are correct.
3. Run a migration to update your actual database's schema. You can do this by running the following command:
npx prisma migrate dev --name init --preview-feature
This command will create the necessary tables in your database based on your Prisma schema file, apply the migration, and generate the Prisma Client.
4. After running the migration, restart your server and test your application again to ensure that the error is resolved.
If you still encounter issues, double-check your Prisma configuration, as well as your database connection settings, and ensure your code logic is correct.
config.yaml
包含通用日誌解析器函式庫。這些解析器針對testlogs/*_2k.log
中的真實日誌進行了測試。
有關測試,請參閱parsers_test.go
;有關更多日誌範例,請參閱 loghub。
使用go install
:
GOBIN=/usr/local/bin go install "github.com/ingyamilmolinar/doctorgpt/agent"
Go
編譯器(僅用於建置和執行測試)docker
(用於開發)k3d
(用於開發)kubectl
(用於開發)make
(用於開發) export OPENAI_API=<your-api-key>
make k4d-create
(建立 k3d 叢集)make k3d-delete
(刪除 k3d 叢集) 注意:請參閱Makefile
以了解更多指令cd agent; go test ./...; cd -
cd agent; go test -v ./...; cd -
(詳細模式) 請隨意提出一個問題,提出您關於如何使程式更加有用、可移植、高效和可用於生產的建議(當然還有錯誤!)。
隨意打開MR。如果我看到他們遵循這個專案的理念,我會對其進行審查。對於較大的工作或設計變更,請先提出問題,以便討論策略。