change api
This commit is contained in:
@@ -4,7 +4,7 @@ definePageMeta({
|
|||||||
})
|
})
|
||||||
import {EventStreamContentType, fetchEventSource} from '@microsoft/fetch-event-source'
|
import {EventStreamContentType, fetchEventSource} from '@microsoft/fetch-event-source'
|
||||||
|
|
||||||
const { $i18n } = useNuxtApp()
|
const { $i18n, $auth } = useNuxtApp()
|
||||||
const runtimeConfig = useRuntimeConfig()
|
const runtimeConfig = useRuntimeConfig()
|
||||||
const currentModel = useCurrentModel()
|
const currentModel = useCurrentModel()
|
||||||
const openaiApiKey = useApiKey()
|
const openaiApiKey = useApiKey()
|
||||||
@@ -18,13 +18,16 @@ const abortFetch = () => {
|
|||||||
fetchingResponse.value = false
|
fetchingResponse.value = false
|
||||||
}
|
}
|
||||||
const fetchReply = async (message, parentMessageId) => {
|
const fetchReply = async (message, parentMessageId) => {
|
||||||
|
const token = await $auth.retrieveToken()
|
||||||
ctrl = new AbortController()
|
ctrl = new AbortController()
|
||||||
try {
|
try {
|
||||||
await fetchEventSource('/api/conversation', {
|
await fetchEventSource('/api/conversation', {
|
||||||
signal: ctrl.signal,
|
signal: ctrl.signal,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: currentModel.value,
|
model: currentModel.value,
|
||||||
@@ -49,6 +52,7 @@ const fetchReply = async (message, parentMessageId) => {
|
|||||||
throw err;
|
throw err;
|
||||||
},
|
},
|
||||||
onmessage(message) {
|
onmessage(message) {
|
||||||
|
console.log(message)
|
||||||
const event = message.event
|
const event = message.event
|
||||||
const data = JSON.parse(message.data)
|
const data = JSON.parse(message.data)
|
||||||
|
|
||||||
@@ -71,7 +75,7 @@ const fetchReply = async (message, parentMessageId) => {
|
|||||||
currentConversation.value.messages.push({id: null, from: 'ai', message: data.content})
|
currentConversation.value.messages.push({id: null, from: 'ai', message: data.content})
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollChatWindow()
|
// scrollChatWindow()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ const ENDPOINTS = {
|
|||||||
|
|
||||||
export default defineNuxtPlugin(() => {
|
export default defineNuxtPlugin(() => {
|
||||||
const token = useCookie(COOKIE_OPTIONS.prefix + '.' + COOKIE_OPTIONS.tokenName, {
|
const token = useCookie(COOKIE_OPTIONS.prefix + '.' + COOKIE_OPTIONS.tokenName, {
|
||||||
maxAge: 60 * 30,
|
maxAge: 60 * 5,
|
||||||
})
|
})
|
||||||
const refreshToken = useCookie(COOKIE_OPTIONS.prefix + '.' + COOKIE_OPTIONS.refreshTokenName, {
|
const refreshToken = useCookie(COOKIE_OPTIONS.prefix + '.' + COOKIE_OPTIONS.refreshTokenName, {
|
||||||
maxAge: 60 * 60 * 24,
|
maxAge: 60 * 60 * 24,
|
||||||
@@ -80,6 +80,7 @@ export default defineNuxtPlugin(() => {
|
|||||||
'refresh': refreshToken.value
|
'refresh': refreshToken.value
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
console.log('refresh', data, error)
|
||||||
if (!error.value) {
|
if (!error.value) {
|
||||||
token.value = data.value.access
|
token.value = data.value.access
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user