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)
tail 및 모니터링할 로그 파일--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을 열어보세요. 이 프로젝트의 철학을 따르는 것이 보이면 검토하겠습니다. 대규모 작업이나 디자인 변경의 경우 전략을 논의할 수 있도록 먼저 이슈를 공개하세요.