修复macos下fetch错误

This commit is contained in:
LOpSSH
2023-03-09 11:49:37 +08:00
parent 5f36bb27c2
commit dfc0c0659b
5 changed files with 349 additions and 310 deletions

View File

@@ -29,7 +29,7 @@
"chatgpt": "^5.0.8",
"compression": "^1.7.4",
"dotenv": "^16.0.3",
"isomorphic-unfetch": "^4.0.2",
"node-fetch": "^3.3.0",
"proxy-agent-v2": "^1.0.3",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.0",
@@ -76,5 +76,12 @@
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
},
"pnpm": {
"peerDependencyRules": {
"ignoreMissing": [
"webpack"
]
}
}
}

630
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,7 @@
import { Injectable, Logger, MessageEvent, OnModuleInit } from '@nestjs/common';
import { ChatGPTAPI, ChatMessage, ConversationResponseEvent } from 'chatgpt';
import fetch from 'isomorphic-unfetch';
import fetch from './fetch.js';
import ProxyAgent from 'proxy-agent-v2';
import { Observable } from 'rxjs';

12
src/fetch.ts Normal file
View File

@@ -0,0 +1,12 @@
import fetch, {
Headers,
Request,
Response,
} from 'node-fetch';
globalThis.fetch = fetch
globalThis.Headers = Headers;
globalThis.Request = Request;
globalThis.Response = Response;
export default fetch;

View File

@@ -1,13 +1,14 @@
{
"compilerOptions": {
"module": "ES2022",
"module": "esnext",
"lib": ["esnext"],
"moduleResolution": "node",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"target": "es2020",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",