Feat/explore (#198)
This commit is contained in:
@@ -1,44 +1,62 @@
|
||||
import type { IOnCompleted, IOnData, IOnError } from './base'
|
||||
import { getPublic as get, postPublic as post, ssePost, delPublic as del } from './base'
|
||||
import {
|
||||
get as consoleGet, post as consolePost, del as consoleDel,
|
||||
getPublic as get, postPublic as post, ssePost, delPublic as del
|
||||
} from './base'
|
||||
import type { Feedbacktype } from '@/app/components/app/chat'
|
||||
|
||||
function getAction(action: 'get' | 'post' | 'del', isInstalledApp: boolean) {
|
||||
switch (action) {
|
||||
case 'get':
|
||||
return isInstalledApp ? consoleGet : get
|
||||
case 'post':
|
||||
return isInstalledApp ? consolePost : post
|
||||
case 'del':
|
||||
return isInstalledApp ? consoleDel : del
|
||||
}
|
||||
}
|
||||
|
||||
function getUrl(url: string, isInstalledApp: boolean, installedAppId: string) {
|
||||
return isInstalledApp ? `installed-apps/${installedAppId}/${url.startsWith('/') ? url.slice(1) : url}` : url
|
||||
}
|
||||
|
||||
export const sendChatMessage = async (body: Record<string, any>, { onData, onCompleted, onError, getAbortController }: {
|
||||
onData: IOnData
|
||||
onCompleted: IOnCompleted
|
||||
onError: IOnError,
|
||||
getAbortController?: (abortController: AbortController) => void
|
||||
}) => {
|
||||
return ssePost('chat-messages', {
|
||||
}, isInstalledApp: boolean, installedAppId = '') => {
|
||||
return ssePost(getUrl('chat-messages', isInstalledApp, installedAppId), {
|
||||
body: {
|
||||
...body,
|
||||
response_mode: 'streaming',
|
||||
},
|
||||
}, { onData, onCompleted, isPublicAPI: true, onError, getAbortController })
|
||||
}, { onData, onCompleted, isPublicAPI: !isInstalledApp, onError, getAbortController })
|
||||
}
|
||||
|
||||
export const sendCompletionMessage = async (body: Record<string, any>, { onData, onCompleted, onError }: {
|
||||
onData: IOnData
|
||||
onCompleted: IOnCompleted
|
||||
onError: IOnError
|
||||
}) => {
|
||||
return ssePost('completion-messages', {
|
||||
}, isInstalledApp: boolean, installedAppId = '') => {
|
||||
return ssePost(getUrl('completion-messages', isInstalledApp, installedAppId), {
|
||||
body: {
|
||||
...body,
|
||||
response_mode: 'streaming',
|
||||
},
|
||||
}, { onData, onCompleted, isPublicAPI: true, onError })
|
||||
}, { onData, onCompleted, isPublicAPI: !isInstalledApp, onError })
|
||||
}
|
||||
|
||||
export const fetchAppInfo = async () => {
|
||||
return get('/site')
|
||||
}
|
||||
|
||||
export const fetchConversations = async () => {
|
||||
return get('conversations', { params: { limit: 20, first_id: '' } })
|
||||
export const fetchConversations = async (isInstalledApp: boolean, installedAppId='', last_id?: string) => {
|
||||
return getAction('get', isInstalledApp)(getUrl('conversations', isInstalledApp, installedAppId), { params: {...{ limit: 20 }, ...(last_id ? { last_id } : {}) } })
|
||||
}
|
||||
|
||||
export const fetchChatList = async (conversationId: string) => {
|
||||
return get('messages', { params: { conversation_id: conversationId, limit: 20, last_id: '' } })
|
||||
export const fetchChatList = async (conversationId: string, isInstalledApp: boolean, installedAppId='') => {
|
||||
return getAction('get', isInstalledApp)(getUrl('messages', isInstalledApp, installedAppId), { params: { conversation_id: conversationId, limit: 20, last_id: '' } })
|
||||
}
|
||||
|
||||
// Abandoned API interface
|
||||
@@ -47,35 +65,34 @@ export const fetchChatList = async (conversationId: string) => {
|
||||
// }
|
||||
|
||||
// init value. wait for server update
|
||||
export const fetchAppParams = async () => {
|
||||
return get('parameters')
|
||||
export const fetchAppParams = async (isInstalledApp: boolean, installedAppId = '') => {
|
||||
return (getAction('get', isInstalledApp))(getUrl('parameters', isInstalledApp, installedAppId))
|
||||
}
|
||||
|
||||
export const updateFeedback = async ({ url, body }: { url: string; body: Feedbacktype }) => {
|
||||
return post(url, { body })
|
||||
export const updateFeedback = async ({ url, body }: { url: string; body: Feedbacktype }, isInstalledApp: boolean, installedAppId = '') => {
|
||||
return (getAction('post', isInstalledApp))(getUrl(url, isInstalledApp, installedAppId), { body })
|
||||
}
|
||||
|
||||
export const fetcMoreLikeThis = async (messageId: string) => {
|
||||
return get(`/messages/${messageId}/more-like-this`, {
|
||||
export const fetchMoreLikeThis = async (messageId: string, isInstalledApp: boolean, installedAppId = '') => {
|
||||
return (getAction('get', isInstalledApp))(getUrl(`/messages/${messageId}/more-like-this`, isInstalledApp, installedAppId), {
|
||||
params: {
|
||||
response_mode: 'blocking',
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const saveMessage = (messageId: string) => {
|
||||
return post('/saved-messages', { body: { message_id: messageId } })
|
||||
export const saveMessage = (messageId: string, isInstalledApp: boolean, installedAppId = '') => {
|
||||
return (getAction('post', isInstalledApp))(getUrl('/saved-messages', isInstalledApp, installedAppId), { body: { message_id: messageId } })
|
||||
}
|
||||
|
||||
export const fetchSavedMessage = async () => {
|
||||
return get(`/saved-messages`)
|
||||
export const fetchSavedMessage = async (isInstalledApp: boolean, installedAppId = '') => {
|
||||
return (getAction('get', isInstalledApp))(getUrl(`/saved-messages`, isInstalledApp, installedAppId))
|
||||
}
|
||||
|
||||
|
||||
export const removeMessage = (messageId: string) => {
|
||||
return del(`/saved-messages/${messageId}`)
|
||||
export const removeMessage = (messageId: string, isInstalledApp: boolean, installedAppId = '') => {
|
||||
return (getAction('del', isInstalledApp))(getUrl(`/saved-messages/${messageId}`, isInstalledApp, installedAppId))
|
||||
}
|
||||
|
||||
export const fetchSuggestedQuestions = (messageId: string) => {
|
||||
return get(`/messages/${messageId}/suggested-questions`)
|
||||
export const fetchSuggestedQuestions = (messageId: string, isInstalledApp: boolean, installedAppId = '') => {
|
||||
return (getAction('get', isInstalledApp))(getUrl(`/messages/${messageId}/suggested-questions`, isInstalledApp, installedAppId))
|
||||
}
|
||||
|
Reference in New Issue
Block a user