feat: 支持上下文联想

This commit is contained in:
ChenZhaoYu
2023-02-11 15:20:58 +08:00
parent 52bfd15ad8
commit 4b16560958
4 changed files with 75 additions and 14 deletions

View File

@@ -1,13 +1,13 @@
import axios from 'axios'
async function fetchChatAPI(message: string) {
const url = `${import.meta.env.VITE_GLOB_API_URL}/chat`
const BASE_URL = import.meta.env.VITE_GLOB_API_URL
async function fetchChatAPI(message: string) {
if (!message || message.trim() === '')
return
try {
const { status, data } = await axios.post(url, { message })
const { status, data } = await axios.post(`${BASE_URL}/chat`, { message })
if (status === 200) {
if (data.text)
@@ -24,4 +24,18 @@ async function fetchChatAPI(message: string) {
}
}
export { fetchChatAPI }
async function clearChatContext() {
try {
const { status, data } = await axios.post(`${BASE_URL}/clear`)
if (status === 200)
return Promise.resolve(data)
return Promise.reject(new Error('Request failed'))
}
catch (error) {
return Promise.reject(error)
}
}
export { fetchChatAPI, clearChatContext }