提交 d96fc4fc 编写于 作者: View Design's avatar View Design

Merge branch 'main' of gitcode.com:git_bot/ai-fe

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