diff --git a/app/src/main/shortCut.ts b/app/src/main/shortCut.ts index e9bb651..fdd2945 100644 --- a/app/src/main/shortCut.ts +++ b/app/src/main/shortCut.ts @@ -14,7 +14,9 @@ ipcMain.handle("shortCut", (_event: IpcMainInvokeEvent) => { export function registerSearchShortCut(){ globalShortcut.unregisterAll() const ret = findOne(`select * from config where id=1`) as {content: string} - const shortCut = JSON.parse(ret.content).shortCut as string + console.log(ret) + const shortCut = JSON.parse(ret.content).shortcut as string + console.log(shortCut) if (shortCut && globalShortcut.isRegistered(shortCut)){ dialog.showErrorBox('提示', '快捷键注册失败,请更换') return false diff --git a/app/src/main/windows.ts b/app/src/main/windows.ts index 432ea76..b153958 100644 --- a/app/src/main/windows.ts +++ b/app/src/main/windows.ts @@ -27,9 +27,9 @@ export const config = { id: 0, options: { initShow: true, - width: 600, - height: 400, - openDevTools: false, + width: 800, + height: 650, + openDevTools: true, frame: true, transparent: false, hash: '/#config' diff --git a/app/src/renderer/src/pages/Setting/index.tsx b/app/src/renderer/src/pages/Setting/index.tsx index 9396c42..2fda3ff 100644 --- a/app/src/renderer/src/pages/Setting/index.tsx +++ b/app/src/renderer/src/pages/Setting/index.tsx @@ -1,24 +1,23 @@ -import { Button, Form, Input, Select, Space } from 'antd'; +import { Button, Form, Input, Select, Space, message } from 'antd'; +import styles from './styles.module.scss' +import { useEffect, useState } from 'react'; +import { useLoaderData } from 'react-router-dom'; +import { localServerBaseUrl } from '@renderer/config'; -const { Option } = Select; - -const layout = { - labelCol: { span: 6 }, - wrapperCol: { span: 16 }, -}; - -const tailLayout = { - wrapperCol: { offset: 6, span: 16 }, -}; - -export const Setting = () => { - const [form] = Form.useForm(); +export function Setting(){ + const [form] = Form.useForm(); + const config = useLoaderData() as ConfigDataType + form.setFieldsValue(config); + const { Option } = Select; + const tailLayout = { + wrapperCol: { offset: 6, span: 16 }, + }; + const [keys, setKeys] = useState([]) const onModelChange = (value: string) => { switch (value) { case 'openai': form.setFieldsValue({ model: 'gpt-4-turbo', base_url:"https://api.openai.com/v1"}); - break; case 'ollama': form.setFieldsValue({ model: 'ollama/llama2',api_base: "http://localhost:11434" }); @@ -27,24 +26,84 @@ export const Setting = () => { } }; - const onFinish = (values: any) => { - console.log(values); + const onFinish = async (values: any) => { + // 注册快捷键 + window.api.shortCut() + await window.api.sql(`update config set content=@content where id = 1`, + 'update', + { + content: JSON.stringify(values) + }) + // window.close(); }; - const onReset = () => { - form.resetFields(); + const onClose = () => { + window.close() }; return ( -
+
+

Setting

+ > +
+
快捷键定义
+ + { + if (e.metaKey || e.ctrlKey || e.altKey) { + const code = e.code.replace(/Left|Right|Key|Digit/, '') + if (keys.includes(code)) return + keys.push(code) + setKeys(keys) + // 如果以数字或字母或者空格结尾 + if (code.match(/^(\w|\s)$/gi)) { + e.currentTarget.value = keys.join('+') + form.setFieldsValue({shortcut: e.currentTarget.value}) + setKeys([]) + } + } + }} + /> + +
+
+ +
+
大模型配置信息
+ +
- + @@ -67,10 +126,10 @@ export const Setting = () => { {({ getFieldValue }) => getFieldValue('format') === 'openai' ? (
- + - +
@@ -84,22 +143,26 @@ export const Setting = () => { > {({ getFieldValue }) => getFieldValue('format') === 'ollama' ? ( - + ) : null } - +
+
+ + - + +
); diff --git a/app/src/renderer/src/pages/Setting/index.tsx.bk b/app/src/renderer/src/pages/Setting/index.tsx.bk index de8055b..d15d022 100644 --- a/app/src/renderer/src/pages/Setting/index.tsx.bk +++ b/app/src/renderer/src/pages/Setting/index.tsx.bk @@ -25,7 +25,6 @@ export const Setting = () => { if (keys.includes(code)) return keys.push(code) setKeys(keys) - // 如果以数字或字母或者空格结尾 if (code.match(/^(\w|\s)$/gi)) { e.currentTarget.value = keys.join('+') diff --git a/app/src/renderer/src/pages/Setting/styles.module.scss b/app/src/renderer/src/pages/Setting/styles.module.scss index a9f6c0f..819acac 100644 --- a/app/src/renderer/src/pages/Setting/styles.module.scss +++ b/app/src/renderer/src/pages/Setting/styles.module.scss @@ -6,7 +6,7 @@ section{ h5 { - @apply text-xs font-bold mb-2 text-slate-700 opacity-80; + @apply text-sm font-bold mb-8 text-slate-700 opacity-80; } h6 { @apply text-sm mb-2 text-slate-700 opacity-80; diff --git a/app/types.d.ts b/app/types.d.ts index 672a7ff..32ef97b 100644 --- a/app/types.d.ts +++ b/app/types.d.ts @@ -25,9 +25,11 @@ type ConfigType = { type ConfigDataType = { shortCut: string + format: string llm: { model: string - api_key: string - base_url: string + api_key?: string + base_url?: string + api_base?: string } } diff --git a/server/route/llm.py b/server/route/llm.py index cf3ceb0..d54a867 100644 --- a/server/route/llm.py +++ b/server/route/llm.py @@ -7,15 +7,20 @@ home_bp = Blueprint('llm', __name__) @home_bp.route('/llm', methods=["POST"]) def llm(): - config = get_config() + messages = request.get_json()["messages"] isStream = request.get_json().get("isStream", False) + llm_config = request.get_json().get("llm_config", None) + if llm_config: + config = json.loads(llm_config) + else: + config = json.loads(get_config())["llm"] if isStream: def generate(): response = completion( messages=messages, stream=True, - **json.loads(config)["llm"] + **config ) for part in response: yield part.choices[0].delta.content or "" @@ -23,7 +28,7 @@ def llm(): else: res = completion( messages=messages, - **json.loads(config)["llm"] + **config ) return { "content": res.choices[0].message.content