Skip to content

Commit

Permalink
update setting dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
SchneeHertz committed Sep 6, 2023
1 parent 9710545 commit 4060334
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 47 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ ChatGPT双向语音助手
"AI_NAME": "休留",
"systemPrompt": "你是虚拟猫娘休留",
"writeFolder": "D:\\folder_name",
"allowPowerfulInterpreter": false,
"proxyObject": {
"protocol": "http",
"host": "127.0.0.1",
"port": 7890
},
"proxyString": "http://127.0.0.1:7890"
}
}
```

Expand Down
9 changes: 9 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@ export {}

declare module 'vue' {
export interface GlobalComponents {
Dialog: typeof import('./src/components/Dialog.vue')['default']
Message: typeof import('./src/components/Message.vue')['default']
NButton: typeof import('naive-ui')['NButton']
NCard: typeof import('naive-ui')['NCard']
NDialogProvider: typeof import('naive-ui')['NDialogProvider']
NForm: typeof import('naive-ui')['NForm']
NFormItem: typeof import('naive-ui')['NFormItem']
NFormItemGi: typeof import('naive-ui')['NFormItemGi']
NGi: typeof import('naive-ui')['NGi']
NGrid: typeof import('naive-ui')['NGrid']
NIcon: typeof import('naive-ui')['NIcon']
NInput: typeof import('naive-ui')['NInput']
NInputGroup: typeof import('naive-ui')['NInputGroup']
NInputNumber: typeof import('naive-ui')['NInputNumber']
NList: typeof import('naive-ui')['NList']
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
NModal: typeof import('naive-ui')['NModal']
NSpace: typeof import('naive-ui')['NSpace']
NSwitch: typeof import('naive-ui')['NSwitch']
Setting: typeof import('./src/components/Setting.vue')['default']
}
}
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { BrowserWindow, app, ipcMain, shell, Menu } = require('electron')
const { BrowserWindow, app, ipcMain, shell, Menu, dialog } = require('electron')
const path = require('node:path')
const fs = require('node:fs')
const { format } = require('node:util')
Expand All @@ -21,8 +21,9 @@ const {
SpeechSynthesisVoiceName,
ADMIN_NAME, AI_NAME,
systemPrompt,
proxyString,
proxyObject,
} = config
const proxyString = `${proxyObject.protocol}://${proxyObject.host}:${proxyObject.port}`

const logFile = fs.createWriteStream(path.join(LOG_PATH, `log-${new Date().toLocaleString('zh-CN').replace(/[\/:]/gi, '-')}.txt`), { flags: 'w' })
const messageLog = (message) => {
Expand Down Expand Up @@ -486,7 +487,7 @@ ipcMain.handle('restart-app', async()=>{
})

// setting
ipcMain.handle('select-folder', async (event, type) => {
ipcMain.handle('select-folder', async () => {
let result = await dialog.showOpenDialog(mainWindow, {
properties: ['openDirectory']
})
Expand All @@ -497,7 +498,7 @@ ipcMain.handle('select-folder', async (event, type) => {
}
})

ipcMain.handle('select-file', async (event, type) => {
ipcMain.handle('select-file', async () => {
let result = await dialog.showOpenDialog(mainWindow, {
properties: ['openFile']
})
Expand All @@ -513,6 +514,5 @@ ipcMain.handle('load-setting', async () => {
})

ipcMain.handle('save-setting', async (event, receiveSetting) => {
console.log(receiveSetting)
return await fs.promises.writeFile(path.join(STORE_PATH, 'config.json'), JSON.stringify(receiveSetting, null, ' '), { encoding: 'utf-8' })
})
3 changes: 2 additions & 1 deletion modules/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const _ = require('lodash')
const { config: {
OPENAI_API_KEY, OPENAI_API_ENDPOINT, DEFAULT_MODEL,
AZURE_OPENAI_KEY, AZURE_OPENAI_ENDPOINT, AZURE_API_VERSION, AZURE_CHAT_MODEL, AZURE_EMBEDDING_MODEL,
proxyString
proxyObject
} } = require('../utils/loadConfig.js')
const proxyString = `${proxyObject.protocol}://${proxyObject.host}:${proxyObject.port}`

const openai = new OpenAI({
apiKey: OPENAI_API_KEY,
Expand Down
3 changes: 2 additions & 1 deletion modules/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const { getQuickJS, shouldInterruptAfterDeadline } = require('quickjs-emscripte
const { shell } = require('electron')
const { js: beautify } = require('js-beautify/js')

let { config: { proxyObject, proxyString, AI_NAME, writeFolder, allowPowerfulInterpreter } } = require('../utils/loadConfig.js')
let { config: { proxyObject, AI_NAME, writeFolder, allowPowerfulInterpreter } } = require('../utils/loadConfig.js')
const proxyString = `${proxyObject.protocol}://${proxyObject.host}:${proxyObject.port}`

const { sliceStringbyTokenLength } = require('./tiktoken.js')
const { javaScriptInterpreterPowerful } = require('./vm.js')
Expand Down
26 changes: 0 additions & 26 deletions package-lock.json

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

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@
}
},
"devDependencies": {
"@vicons/carbon": "^0.12.0",
"@vicons/fa": "^0.12.0",
"@vicons/fluent": "^0.12.0",
"@vicons/ionicons4": "^0.12.0",
"@vicons/material": "^0.12.0",
"@vitejs/plugin-vue": "^4.0.0",
"electron": "^26.0.0",
"electron-builder": "^24.6.3",
Expand Down
29 changes: 27 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import CopyButtonPlugin from 'highlightjs-copy'
hljs.addPlugin(new CopyButtonPlugin())
import Setting from './components/Setting.vue'
import Message from './components/Message.vue'
const messageRef = ref(null)
const printMessage = (type, msg, option) => {
messageRef.value.message.destroyAll()
messageRef.value.message[type](msg, option)
}
const messageHistory = ref([])
Expand Down Expand Up @@ -71,6 +78,18 @@ const scrollToBottom = (id) => {
const element = document.getElementById(id)
element.scrollTop = element.scrollHeight
}
// API Key Check
const setting = ref(null)
onMounted(async () => {
let config = await ipcRenderer.invoke('load-setting')
if (!config.OPENAI_API_KEY && !config.AZURE_OPENAI_KEY) {
setting.value.openConfig()
printMessage('error', '请先设置 OPENAI_API_KEY', { duration: 5000 })
}
})
// STATUS
const isSpeechTalk = ref(false)
const recordStatus = ref(false)
const isAudioPlay = ref(false)
Expand All @@ -90,6 +109,7 @@ const switchAudio = () => {
const emptyHistory = () => {
ipcRenderer.invoke('empty-history')
}
</script>

<template>
Expand Down Expand Up @@ -128,11 +148,14 @@ const emptyHistory = () => {
<n-icon><Speaker216Filled v-if="isAudioPlay" /><SpeakerOff16Filled v-else /></n-icon>
</template>
</n-button>
<n-button type="primary" tertiary @click="emptyHistory">Clear History</n-button>
<Setting />
<n-button type="primary" tertiary @click="emptyHistory">清除对话历史</n-button>
<Setting ref="setting"/>
</n-space>
</n-gi>
</n-grid>
<n-message-provider>
<Message ref="messageRef"/>
</n-message-provider>
</template>

<style lang="stylus">
Expand All @@ -156,6 +179,8 @@ const emptyHistory = () => {
.code-block
position: relative
code.hljs
border-radius: 4px
.hljs-copy-button
position: absolute
right: 4px
Expand Down
6 changes: 6 additions & 0 deletions src/components/Dialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script setup>
defineExpose({
dialog: useDialog()
})
</script>
<template></template>
6 changes: 6 additions & 0 deletions src/components/Message.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script setup>
defineExpose({
message: useMessage()
})
</script>
<template></template>

0 comments on commit 4060334

Please sign in to comment.