Skip to content

Commit

Permalink
添加线路选择,默认选项不再存到db
Browse files Browse the repository at this point in the history
  • Loading branch information
lblblong committed Apr 1, 2023
1 parent f530d64 commit 320fc8d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mossgpt",
"private": true,
"version": "1.12.0",
"version": "1.12.1",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
Expand Down
19 changes: 16 additions & 3 deletions src/constance.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { IConfig, MessageShortcutKey } from './types'

export const Models = ['gpt-3.5-turbo-0301', 'gpt-3.5-turbo']
export const Models = ['gpt-3.5-turbo', 'gpt-3.5-turbo-0301']

export const DefaultAutoTranslation = true

export const DefaultConfig: IConfig = {
model: undefined,
apiBaseUrl: undefined,
model: Models[0],
apiBaseUrl: 'https://closeai.deno.dev/v1',
prompt: undefined,
max_tokens: undefined,
temperature: undefined,
Expand Down Expand Up @@ -73,3 +73,16 @@ export const dataVersion = 2

export const defaultMessageShortcutKey = MessageShortcutKey.Enter

export const ApiUrls = [
{
name: 'OpenAI 官方线路',
url: 'https://api.openai.com/v1',
needVpn: true,
},
{
name: '免费线路 - justjavac 大佬搭建',
url: 'https://closeai.deno.dev/v1',
needVpn: false,
},
]

36 changes: 31 additions & 5 deletions src/pages/setting/basic/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { useStore } from '@libeilong/react-store-provider'
import { AutoComplete, Button, Col, Form, Input, InputNumber, Row } from 'antd'
import { Models } from '../../../constance'
import {
AutoComplete,
Button,
Col,
Form,
Input,
InputNumber,
Row,
Tag,
} from 'antd'
import { ApiUrls, Models } from '../../../constance'
import { withObserver } from '../../../shared/func/withObserver'
import { appStore } from '../../../stores/app'
import { Store } from '../store'
Expand Down Expand Up @@ -52,15 +61,32 @@ export function BasicSetting() {
size="small"
onClick={appStore.openProxyShareUrl}
>
(这里有一些免费的接口代理服务)
(这里有一些免费的接口代理服务和免费搭建代理的教程)
</Button>
</span>
}
tooltip="适用于使用自建的 openai 接口代理服务,示例:https://api.my-openai.com/v1"
>
<Input
<AutoComplete
value={root.baseConfig.apiBaseUrl}
onChange={({ target }) => (root.baseConfig.apiBaseUrl = target.value)}
onChange={(val) => (root.baseConfig.apiBaseUrl = val)}
options={ApiUrls.map((it) => {
return {
label: (
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
}}
>
<div>{`${it.url} - ${it.name}`}</div>
{!it.needVpn && <Tag color="#87d068">无需梯子</Tag>}
</div>
),
value: it.url,
}
})}
/>
</Form.Item>

Expand Down
12 changes: 12 additions & 0 deletions src/shared/func/filterSameValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { objectKeys } from '@libeilong/func'

export function filterSameValue<T extends object>(source: T, target: T): T {
const result = { ...target }
for (const key of objectKeys(target)) {
if (result[key] === source[key]) {
delete result[key]
}
}
return result
}

2 changes: 2 additions & 0 deletions src/shared/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Conversation } from '../../models/conversation'
import { Message } from '../../models/message'
import { Template } from '../../models/template'
import { IConfig, MessageShortcutKey } from '../../types'
import { filterSameValue } from '../func/filterSameValue'
import { isNil } from '../func/isNil'

export class Storage {
Expand Down Expand Up @@ -79,6 +80,7 @@ export class Storage {
}

static setConfig(config: Partial<IConfig>) {
config = filterSameValue(DefaultConfig, config)
utools.dbStorage.setItem('config', config)
}

Expand Down

0 comments on commit 320fc8d

Please sign in to comment.