Skip to content

Commit

Permalink
feat: Remove prettier import rules; Use node-fetch to make proxy requ…
Browse files Browse the repository at this point in the history
…ests; add baseUrl setting
  • Loading branch information
chenweiyi committed Apr 11, 2024
1 parent 7fe2dc7 commit 76f7bd9
Show file tree
Hide file tree
Showing 11 changed files with 9,383 additions and 13,873 deletions.
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
registry=https://registry.npm.taobao.org
registry=https://registry.npmmirror.com
7 changes: 1 addition & 6 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
plugins: [require('@trivago/prettier-plugin-sort-imports')],
printWidth: 80,
singleQuote: true,
jsxSingleQuote: true,
Expand All @@ -9,9 +8,5 @@ module.exports = {
bracketSpacing: true,
bracketSameLine: false,
arrowParens: 'always',
trailingComma: 'none',
importOrder: ['^node:.*', '<THIRD_PARTY_MODULES>', '^[./]'],
importOrderSeparation: true,
importOrderSortSpecifiers: true,
importOrderGroupNamespaceSpecifiers: true
trailingComma: 'none'
}
1 change: 0 additions & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"ts-node": "^10.9.1"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/shelljs": "^0.8.11",
"cross-env": "^7.0.3",
"nodemon": "^1.19.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/bin/www.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import debugLibrary from 'debug'
import http from 'http'
import path from 'path'

import app from '../app.mjs'
import '../utils/abortControllerPolyfill.mjs'
import '../utils/fetchPolyfill.mjs'
import app from '../app.mjs'

const debug = debugLibrary('server')

Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/controller/message.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface ISSEQuery {
parentMessageId?: string
conversationId?: string
model?: string
baseUrl?: string
apiKey?: string
temperature?: string
top_p?: string
Expand Down
13 changes: 9 additions & 4 deletions packages/backend/src/service/thirdparty.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ChatGPTAPI, ChatGPTUnofficialProxyAPI, ChatMessage } from 'chatgpt'
import debugLibrary from 'debug'
import proxy from 'https-proxy-agent'
import { isNil } from 'lodash-es'
import fetch from 'node-fetch'

import { ISSEQuery } from '../controller/message.mjs'

Expand All @@ -22,15 +23,16 @@ export async function responseChatgpt(
msg,
ownerId,
parentMessageId,
conversationId,
model,
baseUrl,
apiKey,
temperature,
top_p
} = query
if (!chatgptApiMap.get(ownerId)) {
const api = new ChatGPTAPI({
apiBaseUrl: process.env.OPENAI_API_BASE_URL || 'https://api.openai.com',
const chatOption = {
apiBaseUrl:
baseUrl || process.env.OPENAI_API_BASE_URL || 'https://api.openai.com',
apiKey: apiKey || process.env.OPENAI_API_KEY,
completionParams: {
model: model || 'gpt-3.5-turbo',
Expand All @@ -51,7 +53,10 @@ export async function responseChatgpt(
return fetch(url, mergedOptions)
}
: undefined
})
}
debug('...chatOption: %o', chatOption)
// @ts-ignore
const api = new ChatGPTAPI(chatOption)
chatgptApiMap.set(ownerId, api)
}
const api = chatgptApiMap.get(ownerId)
Expand Down
6 changes: 6 additions & 0 deletions packages/frontend/.umirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { existsSync } from 'node:fs'
import * as dotenv from 'dotenv'
import { defineConfig } from '@umijs/max'
import path from 'path'
import { codeInspectorPlugin } from 'code-inspector-plugin'

import { autoImportPlugin } from './auto-import'

Expand Down Expand Up @@ -39,6 +40,11 @@ export default defineConfig({
// console.log('memo', memo)
memo.optimization.minimize(false)
memo.plugin('unplugin-auto-import').use(autoImportPlugin())
memo.plugin('code-inspector-plugin').use(
codeInspectorPlugin({
bundler: 'webpack'
})
)
return memo
},
routes: [
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/react-syntax-highlighter": "^15.5.6",
"code-inspector-plugin": "^0.11.0",
"cross-env": "^7.0.3",
"dotenv": "^16.0.3",
"prettier-plugin-organize-imports": "^2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default function SettingModal(props: SettingModalProps) {
}

const formRef = useRef<FormInstance<ILocalSettings>>(null)
const initData = {
const initData: ILocalSettings = {
baseUrl: '',
apiKey: '',
model: 'gpt-3.5-turbo',
temperature: 0.8,
Expand All @@ -37,6 +38,13 @@ export default function SettingModal(props: SettingModalProps) {
}
]

const baseUrlRule = [
{
required: false,
message: '不填值时使用系统默认baseUrl'
}
]

const temperatureRule = [
{
required: false
Expand Down Expand Up @@ -92,6 +100,9 @@ export default function SettingModal(props: SettingModalProps) {
onFinish={submit}
onFinishFailed={submitError}
>
<Form.Item label='baseUrl' name='baseUrl' rules={baseUrlRule}>
<Input placeholder='不填值时使用系统默认baseUrl' />
</Form.Item>
<Form.Item label='apiKey' name='apiKey' rules={apiKeyRule}>
<Input placeholder='不填值时使用系统默认key' />
</Form.Item>
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/src/utils/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { convasitionDB } from './indexdb'

export type ILocalSettings = {
baseUrl: string
apiKey: string
model: string
temperature: number
Expand Down
Loading

0 comments on commit 76f7bd9

Please sign in to comment.