Skip to content

Commit

Permalink
feat: proxy & model
Browse files Browse the repository at this point in the history
  • Loading branch information
IceEnd committed May 10, 2023
1 parent 64ab7eb commit dc9e37e
Show file tree
Hide file tree
Showing 21 changed files with 183 additions and 1,200 deletions.
1 change: 1 addition & 0 deletions components.d.ts
Expand Up @@ -15,6 +15,7 @@ declare module '@vue/runtime-core' {
ElButton: typeof import('element-plus/es')['ElButton']
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
ElDialog: typeof import('element-plus/es')['ElDialog']
ElDivider: typeof import('element-plus/es')['ElDivider']
ElForm: typeof import('element-plus/es')['ElForm']
ElFormItem: typeof import('element-plus/es')['ElFormItem']
ElInput: typeof import('element-plus/es')['ElInput']
Expand Down
5 changes: 2 additions & 3 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "1chat",
"private": true,
"version": "0.1.0",
"version": "0.1.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -13,8 +13,6 @@
"dependencies": {
"@element-plus/icons-vue": "^2.1.0",
"@tauri-apps/api": "^1.2.0",
"@vueuse/core": "^10.0.2",
"axios": "^1.3.6",
"dayjs": "^1.11.7",
"element-plus": "^2.3.3",
"eventsource-parser": "^1.0.0",
Expand All @@ -36,6 +34,7 @@
"autoprefixer": "^10.4.14",
"eslint": "^8.38.0",
"eslint-plugin-vue": "^9.11.0",
"github-markdown-css": "^5.2.0",
"highlight.js": "^11.8.0",
"husky": "^8.0.3",
"less": "^4.1.3",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "one_chat"
version = "0.1.0"
version = "0.1.1"
description = "A Tauri App"
authors = ["you"]
license = ""
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "1chat",
"version": "0.1.0"
"version": "0.1.1"
},
"tauri": {
"allowlist": {
Expand Down
1 change: 1 addition & 0 deletions src/App.vue
Expand Up @@ -6,6 +6,7 @@

<script setup lang="ts">
import 'highlight.js/styles/atom-one-dark.css';
import 'github-markdown-css';
import 'element-plus/es/components/notification/style/css';
import { computed, onMounted } from 'vue';
import { invoke } from '@tauri-apps/api/tauri';
Expand Down
4 changes: 2 additions & 2 deletions src/client/index.ts
Expand Up @@ -2,6 +2,7 @@
* OpenAI API
*/
import { createParser } from 'eventsource-parser';
import { DEFAULT_HOST } from '@/constants';

export interface IOnTextCallbackResult {
// 返回的文本
Expand Down Expand Up @@ -37,7 +38,7 @@ export const completion = async (
}));
try {
const response = await fetch(
'https://api.openai.com/v1/chat/completions', {
`${request.host || DEFAULT_HOST}/v1/chat/completions`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${request.token}`,
Expand Down Expand Up @@ -75,7 +76,6 @@ export const completion = async (
return fullText;
};


// 处理 server-sent events/eventsource,
const handleSSE = async (
response: Response,
Expand Down
31 changes: 28 additions & 3 deletions src/components/layout/app/settings-dialog.vue
Expand Up @@ -4,7 +4,7 @@
width="420px"
:title="$t('Settings')"
>
<div class="pb-16">{{ $t('Version') }} {{ version }}</div>
<el-divider content-position="left">{{ $t('Version') }} {{ version }}</el-divider>
<el-form
label-position="top"
size="small"
Expand All @@ -14,7 +14,7 @@
<el-input type="password" v-model="config.openaiAPIKey" />
</el-form-item>

<el-form-item :label="t('Language')">
<el-form-item :label="$t('Language')">
<el-select v-model="config.locale">
<el-option
v-for="lang in LanguageOptions"
Expand Down Expand Up @@ -46,6 +46,23 @@
/>
</el-select>
</el-form-item>

<el-divider content-position="left">{{ $t('Proxy & Model') }}</el-divider>

<el-form-item :label="$t('API Host')">
<el-input v-model="config.host" />
</el-form-item>

<el-form-item :label="$t('Model')">
<el-select v-model="config.model">
<el-option
v-for="model in ModelOptions"
:key="model.value"
:label="model.label"
:value="model.value"
></el-option>
</el-select>
</el-form-item>
</el-form>
</el-dialog>
</template>
Expand All @@ -54,7 +71,7 @@
import { ref, inject, computed, Ref, onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
import { getVersion } from '@tauri-apps/api/app';
import { Language, Theme } from '@/constants';
import { Language, Theme, Model } from '@/constants';
import { useSystemStore } from '@/store/system';
import { SETTINGS_VISIBLE } from './symbol';
Expand Down Expand Up @@ -93,6 +110,14 @@ const FontSizeOptions = computed(() => {
return options;
});
const ModelOptions = computed(() => Object.keys(Model).map((key) => {
const v = Model[key as keyof typeof Model];
return {
label: v,
value: v,
};
}));
onMounted(async () => {
try {
version.value = await getVersion();
Expand Down
7 changes: 7 additions & 0 deletions src/constants/index.ts
Expand Up @@ -40,5 +40,12 @@ export enum Role {

export enum Model {
GPT_35_TURBO = 'gpt-3.5-turbo',
GPT_35_TURBO_0301 = 'gpt-3.5-turbo-0301',
GPT_4 = 'gpt-4',
GPT_4_0314 = 'gpt-4-0314',
GPT_4_32K = 'gpt-4-32k',
GPT_4_32K_0314 = 'gpt-4-32k-0314',
}

// 默认代理
export const DEFAULT_HOST = 'https://api.openai.com';
5 changes: 4 additions & 1 deletion src/locales/en.json
Expand Up @@ -11,5 +11,8 @@
"[Enter] send, [Shift+Enter] line break, [Ctrl+Enter] send without generating": "[Enter] send, [Shift+Enter] line break, [Ctrl+Enter] send without generating",
"copied to clipboard": "copied to clipboard",
"An error occurred, please retry": "An error occurred, please retry",
"Version": "Version"
"Version": "Version",
"Proxy & Model": "Proxy & Model",
"API Host": "API Host",
"Model": "Model"
}
5 changes: 4 additions & 1 deletion src/locales/zh-CN.json
Expand Up @@ -11,5 +11,8 @@
"[Enter] send, [Shift+Enter] line break, [Ctrl+Enter] send without generating": "[回车键] 发送,[Shift+回车键] 换行, [Ctrl+回车键] 发送但不生成",
"copied to clipboard": "已复制到剪贴板",
"An error occurred, please retry": "发生错误,请重试",
"Version": "版本"
"Version": "版本",
"Proxy & Model": "代理 & 模型",
"API Host": "API Host",
"Model": "模型"
}
4 changes: 3 additions & 1 deletion src/store/system.ts
Expand Up @@ -3,7 +3,7 @@ import { invoke } from '@tauri-apps/api/tauri';
import { appWindow } from '@tauri-apps/api/window';
import { defineStore } from 'pinia';
import { useI18n } from 'vue-i18n';
import { Language, Theme, TauriCommand } from '@/constants';
import { Language, Theme, TauriCommand, DEFAULT_HOST, Model } from '@/constants';

export const useSystemStore = defineStore('system', () => {
const { locale } = useI18n();
Expand All @@ -12,6 +12,8 @@ export const useSystemStore = defineStore('system', () => {
locale: takeLocale(navigator.language),
theme: takeTheme(Theme.Auto),
fontSize: 13,
host: DEFAULT_HOST,
model: Model.GPT_35_TURBO,
});

const update = (payload: AppSystem.IConfig) => {
Expand Down
2 changes: 1 addition & 1 deletion src/styles/index.less
@@ -1,4 +1,4 @@
@import "./reset.less";
@import "./variables/index.less";
@import "./common/index.less";
@import "./markdown.css";
@import "./markdown.less";

0 comments on commit dc9e37e

Please sign in to comment.