From 53dedf2ff5fd49d0fd7e67624d23f20fb5738aa1 Mon Sep 17 00:00:00 2001 From: KieSun Date: Thu, 23 Mar 2023 15:46:02 +0800 Subject: [PATCH 01/10] feat: add prompt --- .env.example | 14 ------- package.json | 5 ++- pnpm-lock.yaml | 34 ++++++++++----- src/components/Footer.astro | 6 +-- src/components/Generator.tsx | 73 +++++++++++++++++++-------------- src/components/Header.astro | 3 +- src/components/SwitchPrompt.tsx | 37 +++++++++++++++++ src/components/style.css | 4 ++ src/layouts/Layout.astro | 4 +- 9 files changed, 116 insertions(+), 64 deletions(-) delete mode 100644 .env.example create mode 100644 src/components/SwitchPrompt.tsx create mode 100644 src/components/style.css diff --git a/.env.example b/.env.example deleted file mode 100644 index 2a7f07567..000000000 --- a/.env.example +++ /dev/null @@ -1,14 +0,0 @@ -# Your API Key for OpenAI -OPENAI_API_KEY= -# Provide proxy for OpenAI API. e.g. http://127.0.0.1:7890 -HTTPS_PROXY= -# Custom base url for OpenAI API. default: https://api.openai.com -OPENAI_API_BASE_URL= -# Inject analytics or other scripts before of the page -HEAD_SCRIPTS= -# Secret string for the project. Use for generating signatures for API calls -SECRET_KEY= -# Set password for site. If not set, site will be public -SITE_PASSWORD= -# ID of the model to use. https://platform.openai.com/docs/api-reference/models/list -OPENAI_API_MODEL= diff --git a/package.json b/package.json index 0afc9d3c3..5103b38b5 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "@astrojs/node": "^5.0.4", "@astrojs/solid-js": "^2.0.2", "@astrojs/vercel": "^3.1.3", + "@thisbeyond/solid-select": "^0.13.0", "@unocss/reset": "^0.50.1", "astro": "^2.0.15", "eslint": "^8.36.0", @@ -33,6 +34,7 @@ "undici": "^5.20.0" }, "devDependencies": { + "@evan-yang/eslint-config": "^1.0.1", "@iconify-json/carbon": "^1.1.16", "@types/markdown-it": "^12.2.3", "@typescript-eslint/parser": "^5.54.1", @@ -41,7 +43,6 @@ "@unocss/preset-typography": "^0.50.3", "eslint-plugin-astro": "^0.24.0", "punycode": "^2.3.0", - "unocss": "^0.50.1", - "@evan-yang/eslint-config": "^1.0.1" + "unocss": "^0.50.1" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ff8cb4663..048ba4f22 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,6 +7,7 @@ specifiers: '@astrojs/vercel': ^3.1.3 '@evan-yang/eslint-config': ^1.0.1 '@iconify-json/carbon': ^1.1.16 + '@thisbeyond/solid-select': ^0.13.0 '@types/markdown-it': ^12.2.3 '@typescript-eslint/parser': ^5.54.1 '@unocss/preset-attributify': ^0.50.1 @@ -34,6 +35,7 @@ dependencies: '@astrojs/node': 5.1.0_astro@2.1.3 '@astrojs/solid-js': 2.1.0_fqjiu6dx33dr7dveogf7j2esim '@astrojs/vercel': 3.2.1_astro@2.1.3+react@18.2.0 + '@thisbeyond/solid-select': 0.13.0_solid-js@1.6.12 '@unocss/reset': 0.50.4 astro: 2.1.3 eslint: 8.36.0 @@ -58,7 +60,7 @@ devDependencies: '@unocss/preset-typography': 0.50.4 eslint-plugin-astro: 0.24.0_eslint@8.36.0 punycode: 2.3.0 - unocss: 0.50.4_vite@4.1.4 + unocss: 0.50.4_postcss@8.4.21+vite@4.1.4 packages: @@ -721,7 +723,7 @@ packages: eslint-import-resolver-typescript: 2.7.1_eakrjjutlgqjxe5ydhtnd4qdmy eslint-plugin-eslint-comments: 3.2.0_eslint@8.36.0 eslint-plugin-html: 6.2.0 - eslint-plugin-import: 2.27.5_ehloacyzzkbjdczhrjhdzdi6ba + eslint-plugin-import: 2.27.5_a7er6olmtneep4uytpot6gt7wu eslint-plugin-jsonc: 2.7.0_eslint@8.36.0 eslint-plugin-jsx-a11y: 6.7.1_eslint@8.36.0 eslint-plugin-markdown: 2.2.1_eslint@8.36.0 @@ -906,6 +908,14 @@ packages: resolution: {integrity: sha512-ZmIThxUeX+D40ck0bviDEhta2WSpJd2AQYFF+rjO8zQmgySifeeiEc0Kn/Sp1BMHbLMcLboPYdOnT+6E1E9OLg==} dev: false + /@thisbeyond/solid-select/0.13.0_solid-js@1.6.12: + resolution: {integrity: sha512-eION+Xf8TGLs1NZrvRo1NRKOl4plYMbY7UswHhh5bEUY8oMltjrBhUWF0hzaFViEc1zZpkCQyafaD89iofG6Tg==} + peerDependencies: + solid-js: ^1.5 + dependencies: + solid-js: 1.6.12 + dev: false + /@types/babel__core/7.20.0: resolution: {integrity: sha512-+n8dL/9GWblDO0iU6eZAwEIJVr5DWigtle+Q6HLOrh/pdbXOhOtqzq8VPPE2zvNJzSKY4vH/z3iT3tn0A3ypiQ==} dependencies: @@ -1201,9 +1211,11 @@ packages: sirv: 2.0.2 dev: true - /@unocss/postcss/0.50.4: + /@unocss/postcss/0.50.4_postcss@8.4.21: resolution: {integrity: sha512-Gri+EqIOs/yKk0YHel5XLHQCRD1BzKdQHF82zizJUyqaRStR2qvR8ECInYsirXL/eUEvx2zT8iQKCXkiApTuQw==} engines: {node: '>=14'} + peerDependencies: + postcss: ^8.4.21 dependencies: '@unocss/config': 0.50.4 '@unocss/core': 0.50.4 @@ -2555,7 +2567,7 @@ packages: eslint-plugin-promise: ^6.0.0 dependencies: eslint: 8.36.0 - eslint-plugin-import: 2.27.5_ehloacyzzkbjdczhrjhdzdi6ba + eslint-plugin-import: 2.27.5_a7er6olmtneep4uytpot6gt7wu eslint-plugin-n: 15.6.1_eslint@8.36.0 eslint-plugin-promise: 6.1.1_eslint@8.36.0 dev: true @@ -2579,7 +2591,7 @@ packages: dependencies: debug: 4.3.4 eslint: 8.36.0 - eslint-plugin-import: 2.27.5_ehloacyzzkbjdczhrjhdzdi6ba + eslint-plugin-import: 2.27.5_a7er6olmtneep4uytpot6gt7wu glob: 7.2.3 is-glob: 4.0.3 resolve: 1.22.1 @@ -2588,7 +2600,7 @@ packages: - supports-color dev: true - /eslint-module-utils/2.7.4_vpmbjtxneznonqcn7xpyrnpqzq: + /eslint-module-utils/2.7.4_tzfhnsp6rhftjfsbnqrkrbah74: resolution: {integrity: sha512-j4GT+rqzCoRKHwURX7pddtIPGySnX9Si/cgMI5ztrcqOPtk5dDEeZ34CQVPphnqkJytlc97Vuk05Um2mJ3gEQA==} engines: {node: '>=4'} peerDependencies: @@ -2613,7 +2625,6 @@ packages: debug: 3.2.7 eslint: 8.36.0 eslint-import-resolver-node: 0.3.7 - eslint-import-resolver-typescript: 2.7.1_eakrjjutlgqjxe5ydhtnd4qdmy transitivePeerDependencies: - supports-color dev: true @@ -2663,7 +2674,7 @@ packages: htmlparser2: 7.2.0 dev: true - /eslint-plugin-import/2.27.5_ehloacyzzkbjdczhrjhdzdi6ba: + /eslint-plugin-import/2.27.5_a7er6olmtneep4uytpot6gt7wu: resolution: {integrity: sha512-LmEt3GVofgiGuiE+ORpnvP+kAm3h6MLZJ4Q5HCyHADofsb4VzXFsRiWj3c0OFiV+3DWFh0qg3v9gcPlfc3zRow==} engines: {node: '>=4'} peerDependencies: @@ -2681,7 +2692,7 @@ packages: doctrine: 2.1.0 eslint: 8.36.0 eslint-import-resolver-node: 0.3.7 - eslint-module-utils: 2.7.4_vpmbjtxneznonqcn7xpyrnpqzq + eslint-module-utils: 2.7.4_tzfhnsp6rhftjfsbnqrkrbah74 has: 1.0.3 is-core-module: 2.11.0 is-glob: 4.0.3 @@ -5851,7 +5862,7 @@ packages: unist-util-visit-parents: 5.1.3 dev: false - /unocss/0.50.4_vite@4.1.4: + /unocss/0.50.4_postcss@8.4.21+vite@4.1.4: resolution: {integrity: sha512-9offjUEwVlAkR//0sidTyvKkSArRGkDdgSFeW4P4005GWnjmXnbx4amuAeS3Au4o8WoshZCCOi5EYrpO4aLdfg==} engines: {node: '>=14'} peerDependencies: @@ -5863,7 +5874,7 @@ packages: '@unocss/astro': 0.50.4_vite@4.1.4 '@unocss/cli': 0.50.4 '@unocss/core': 0.50.4 - '@unocss/postcss': 0.50.4 + '@unocss/postcss': 0.50.4_postcss@8.4.21 '@unocss/preset-attributify': 0.50.4 '@unocss/preset-icons': 0.50.4 '@unocss/preset-mini': 0.50.4 @@ -5879,6 +5890,7 @@ packages: '@unocss/transformer-variant-group': 0.50.4 '@unocss/vite': 0.50.4_vite@4.1.4 transitivePeerDependencies: + - postcss - rollup - supports-color - vite diff --git a/src/components/Footer.astro b/src/components/Footer.astro index a871bc1d8..487bf056a 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -3,14 +3,14 @@ Made by - Diu + yck | Source Code diff --git a/src/components/Generator.tsx b/src/components/Generator.tsx index 3a64990b4..36cf7b53f 100644 --- a/src/components/Generator.tsx +++ b/src/components/Generator.tsx @@ -1,14 +1,15 @@ -import { Index, Show, createSignal, onCleanup, onMount } from 'solid-js' +import { Index, Show, createEffect, createSignal, onCleanup, onMount } from 'solid-js' import { useThrottleFn } from 'solidjs-use' import { generateSignature } from '@/utils/auth' import IconClear from './icons/Clear' import MessageItem from './MessageItem' -import SystemRoleSettings from './SystemRoleSettings' import ErrorMessageItem from './ErrorMessageItem' +import SwitchPrompt from './SwitchPrompt' import type { ChatMessage, ErrorMessage } from '@/types' export default () => { let inputRef: HTMLTextAreaElement + let messageRef: HTMLDivElement const [currentSystemRoleSettings, setCurrentSystemRoleSettings] = createSignal('') const [systemRoleEditing, setSystemRoleEditing] = createSignal(false) const [messageList, setMessageList] = createSignal([]) @@ -177,60 +178,72 @@ export default () => { handleButtonClick() } + const handlePromptChange = (v) => { + clear() + setCurrentSystemRoleSettings(v) + } + + createEffect(() => { + let timer + if (loading()) { + timer = setInterval(() => { + messageRef.scrollTo(0, messageRef.scrollHeight) + }, 500) + } else { + timer && clearInterval(timer) + } + }) + return (
- messageList().length === 0} - systemRoleEditing={systemRoleEditing} - setSystemRoleEditing={setSystemRoleEditing} - currentSystemRoleSettings={currentSystemRoleSettings} - setCurrentSystemRoleSettings={setCurrentSystemRoleSettings} - /> - - {(message, index) => ( - (message().role === 'assistant' && index === messageList().length - 1)} - onRetry={retryLastFetch} - /> - )} - - {currentAssistantMessage() && ( + +
+ + {(message, index) => ( + (message().role === 'assistant' && index === messageList().length - 1)} + onRetry={retryLastFetch} + /> + )} + + {currentAssistantMessage() && ( - )} - { currentError() && } + )} +
+ {currentError() && } ( -
+
AI is thinking... -
Stop
+
Stop
)} > -
+