提交 49d8e7d2 编写于 作者: D DebugIsFalse

fix: 清除符号

上级 ca7b4fa1
...@@ -176,14 +176,14 @@ const handleCopyMD = (index) => { ...@@ -176,14 +176,14 @@ const handleCopyMD = (index) => {
}) })
} }
const handleReGenerate = (index) => { const handleReGenerate = (index) => {
editIndex.value = index; editIndex.value = index
const question = data.value[editIndex.value].question; const question = data.value[editIndex.value].question
data.value[editIndex.value] = { data.value[editIndex.value] = {
question, question,
desLoading: true desLoading: true
}; }
nextTick(() => { nextTick(() => {
generateFetchData(question); generateFetchData(question)
}) })
} }
...@@ -202,18 +202,22 @@ const recommendQuestions = [ ...@@ -202,18 +202,22 @@ const recommendQuestions = [
] ]
const continueQuestion = ref(null) const continueQuestion = ref(null)
let asking = ref(false) let asking = ref(false)
const handleClearInput = () => {
continueQuestion.value = ''
}
const handleContinueAsk = (question) => { const handleContinueAsk = (question) => {
if (asking.value) return if (asking.value) return
asking.value = true asking.value = true
editIndex.value = data.value.length; editIndex.value = data.value.length
createGenerateInitItem(question); createGenerateInitItem(question)
generateFetchData(question); generateFetchData(question)
handleClearInput()
} }
// 处理ai generate // 处理ai generate
let aiChatController = null; // 用户取消操作方法 let aiChatController = null // 用户取消操作方法
const markedEnd = '[DONE]'; const markedEnd = '[DONE]'
let storeSource = []; let storeSource = []
const createGenerateInitItem = (question) => { const createGenerateInitItem = (question) => {
data.value.push({ question, desLoading: true }) data.value.push({ question, desLoading: true })
} }
...@@ -221,17 +225,17 @@ const resetAnsLoading = () => { ...@@ -221,17 +225,17 @@ const resetAnsLoading = () => {
Object.assign(data.value[editIndex.value], { ansLoading: false }) Object.assign(data.value[editIndex.value], { ansLoading: false })
} }
const handleFormFetchData = (fetchData) => { const handleFormFetchData = (fetchData) => {
let message = {}; let message = {}
try { try {
message = JSON.parse(fetchData); message = JSON.parse(fetchData)
} catch(error) { } catch(error) {
console.log(error) console.log(error)
} }
if (Object.keys(message).length === 0) return; if (Object.keys(message).length === 0) return
const { meta, choices } = message; const { meta, choices } = message
const index = editIndex.value; const index = editIndex.value
nextTick(() => { nextTick(() => {
scrollToView(); scrollToView()
}) })
if (meta.type === 'answer') { if (meta.type === 'answer') {
Object.assign(data.value[index], { Object.assign(data.value[index], {
...@@ -249,16 +253,16 @@ const handleFormFetchData = (fetchData) => { ...@@ -249,16 +253,16 @@ const handleFormFetchData = (fetchData) => {
} }
if (meta.action === 'search_file') { if (meta.action === 'search_file') {
Object.assign(data.value[index], { desLoading: true }) Object.assign(data.value[index], { desLoading: true })
let source = choices[0].message.content; let source = choices[0].message.content
storeSource = source.split('\n'); storeSource = source.split('\n')
} }
} }
const handleUpdateSource = () => { const handleUpdateSource = () => {
const index = editIndex.value; const index = editIndex.value
data.value[index] = data.value[index] || {}; data.value[index] = data.value[index] || {}
// https://github.com/allwefantasy/byzer-llm/blob/master/tests/functions_suite.py // https://github.com/allwefantasy/byzer-llm/blob/master/tests/functions_suite.py
const endWidthGit = state.gitPath.endsWith('.git'); const endWidthGit = state.gitPath.endsWith('.git')
const baseUrl = endWidthGit ? state.gitPath.slice(0, state.gitPath.length - 4) : state.gitPath; const baseUrl = endWidthGit ? state.gitPath.slice(0, state.gitPath.length - 4) : state.gitPath
storeSource = storeSource.map((item) => { storeSource = storeSource.map((item) => {
return { return {
repo: state.repo, repo: state.repo,
...@@ -266,37 +270,37 @@ const handleUpdateSource = () => { ...@@ -266,37 +270,37 @@ const handleUpdateSource = () => {
label: item label: item
} }
}) })
Object.assign(data.value[index], { source: storeSource }); Object.assign(data.value[index], { source: storeSource })
} }
const handleHideInitLoading = () => { const handleHideInitLoading = () => {
initLoading.value = false; initLoading.value = false
} }
const handleMessage = (event) => { const handleMessage = (event) => {
if (initLoading.value) { if (initLoading.value) {
handleHideInitLoading() handleHideInitLoading()
createGenerateInitItem(state.query) createGenerateInitItem(state.query)
}; }
if (event.data === markedEnd) { if (event.data === markedEnd) {
asking.value = false; asking.value = false
resetAnsLoading(); resetAnsLoading()
handleUpdateSource(); handleUpdateSource()
return; return
} }
handleFormFetchData(event.data) handleFormFetchData(event.data)
} }
const handleStopGenerate = () => { const handleStopGenerate = () => {
asking.value && aiChatController && aiChatController.abort(); asking.value && aiChatController && aiChatController.abort()
asking.value = false; asking.value = false
} }
const handleError = (event) => { const handleError = (event) => {
handleStopGenerate(); handleStopGenerate()
} }
const generateFetchData = (query) => { const generateFetchData = (query) => {
const { gitPath, id } = state; const { gitPath, id } = state
const messages = []; const messages = []
messages.push({ role: 'user', content: query }); messages.push({ role: 'user', content: query })
aiChatController = new AbortController(); aiChatController = new AbortController()
asking.value = true; asking.value = true
fetchEventSource('/v1/chat/completions', { fetchEventSource('/v1/chat/completions', {
params: { params: {
repo_path: gitPath, repo_path: gitPath,
...@@ -311,6 +315,6 @@ const generateFetchData = (query) => { ...@@ -311,6 +315,6 @@ const generateFetchData = (query) => {
}) })
} }
onMounted(() => { onMounted(() => {
generateFetchData(state.query); generateFetchData(state.query)
}) })
</script> </script>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册