Skip to content

Commit

Permalink
Prompt clean up (#496)
Browse files Browse the repository at this point in the history
* Refactor string utility and debug database connection string

* Update placeholders and default prompt list handling
  • Loading branch information
swuecho authored Jul 12, 2024
1 parent 545bb97 commit f10a6ef
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/common/PromptStore/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ watch(
<NCard style="width: 600px" :bordered="false" size="huge" role="dialog" aria-modal="true">
<NSpace v-if="modalMode === 'add' || modalMode === 'modify'" vertical>
模板标题
<NInput v-model:value="tempPromptKey" placeholder="搜索" />
<NInput v-model:value="tempPromptKey" placeholder="搜索模版标题" />
模板内容
<NInput v-model:value="tempPromptValue" placeholder="搜索" type="textarea" />
<NInput v-model:value="tempPromptValue" placeholder="请输入提示词" type="textarea" />
<NButton strong secondary :style="{ width: '100%' }" :disabled="inputStatus"
@click="() => { modalMode === 'add' ? addPromptTemplate() : modifyPromptTemplate() }">
确定
Expand Down
2 changes: 1 addition & 1 deletion web/src/store/modules/prompt/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
Empty file added web/src/utils/prompt.ts
Empty file.
10 changes: 10 additions & 0 deletions web/src/utils/string.ts
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 1 addition & 11 deletions web/src/views/chat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
</script>

<template>
Expand Down

0 comments on commit f10a6ef

Please sign in to comment.