From f10a6efd5da6ed9efa4a1151503980ac623609ce Mon Sep 17 00:00:00 2001 From: Hao Wu Date: Fri, 12 Jul 2024 10:31:13 +0800 Subject: [PATCH] Prompt clean up (#496) * Refactor string utility and debug database connection string * Update placeholders and default prompt list handling --- api/main.go | 1 + web/src/components/common/PromptStore/index.vue | 4 ++-- web/src/store/modules/prompt/helper.ts | 2 +- web/src/utils/prompt.ts | 0 web/src/utils/string.ts | 10 ++++++++++ web/src/views/chat/index.vue | 12 +----------- 6 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 web/src/utils/prompt.ts create mode 100644 web/src/utils/string.ts diff --git a/api/main.go b/api/main.go index 8041dd44..363eda67 100644 --- a/api/main.go +++ b/api/main.go @@ -108,6 +108,7 @@ func main() { pg := appConfig.PG connStr = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", pg.HOST, pg.PORT, pg.USER, pg.PASS, pg.DB) + print(connStr) } else { connStr = dbURL } diff --git a/web/src/components/common/PromptStore/index.vue b/web/src/components/common/PromptStore/index.vue index 18e87078..e8006017 100644 --- a/web/src/components/common/PromptStore/index.vue +++ b/web/src/components/common/PromptStore/index.vue @@ -369,9 +369,9 @@ watch( 模板标题 - + 模板内容 - + 确定 diff --git a/web/src/store/modules/prompt/helper.ts b/web/src/store/modules/prompt/helper.ts index fc5cb67d..3c97a7e4 100644 --- a/web/src/store/modules/prompt/helper.ts +++ b/web/src/store/modules/prompt/helper.ts @@ -133,10 +133,10 @@ let defaultPromptMap: { [key: string]: Prompt[] } = { export function getLocalPromptList(): PromptStore { const promptStore: PromptStore | undefined = ss.get(LOCAL_NAME) - let defaultPromptList = defaultPromptMap[navigator.language]; if (promptStore && promptStore?.promptList?.length > 0) { return promptStore } else { + let defaultPromptList = defaultPromptMap[navigator.language]; setLocalPromptList({ promptList: defaultPromptList }) return { promptList: defaultPromptList } } diff --git a/web/src/utils/prompt.ts b/web/src/utils/prompt.ts new file mode 100644 index 00000000..e69de29b diff --git a/web/src/utils/string.ts b/web/src/utils/string.ts new file mode 100644 index 00000000..37c46a71 --- /dev/null +++ b/web/src/utils/string.ts @@ -0,0 +1,10 @@ +export function getDataFromResponseText(responseText: string): string { + // first data segment + if (responseText.lastIndexOf('data:') === 0) + return responseText.slice(5) + // Find the last occurrence of the data segment + const lastIndex = responseText.lastIndexOf('\n\ndata:') + // Extract the JSON data chunk from the responseText + const chunk = responseText.slice(lastIndex + 8) + return chunk +} \ No newline at end of file diff --git a/web/src/views/chat/index.vue b/web/src/views/chat/index.vue index eabe388d..7aa18ae4 100644 --- a/web/src/views/chat/index.vue +++ b/web/src/views/chat/index.vue @@ -25,6 +25,7 @@ import UploaderReadOnly from './components/UploaderReadOnly.vue' import ModelSelector from './components/ModelSelector.vue' import PromptGallery from '@/views/chat/components/PromptGallery/index.vue' +import { getDataFromResponseText } from '@/utils/string' let controller = new AbortController() const route = useRoute() @@ -517,17 +518,6 @@ onUnmounted(() => { const handleUsePrompt = (_: string, value: string): void => { prompt.value = value } -function getDataFromResponseText(responseText: string): string { - // first data segment - if (responseText.lastIndexOf('data:') === 0) - return responseText.slice(5) - // Find the last occurrence of the data segment - const lastIndex = responseText.lastIndexOf('\n\ndata:') - // Extract the JSON data chunk from the responseText - const chunk = responseText.slice(lastIndex + 8) - return chunk -} -