dify/web/service/debug.ts

61 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-09-09 19:17:12 +08:00
import type { IOnCompleted, IOnData, IOnError, IOnMessageEnd } from './base'
2023-06-06 10:52:02 +08:00
import { get, post, ssePost } from './base'
2023-05-15 08:51:32 +08:00
2023-09-09 19:17:12 +08:00
export const sendChatMessage = async (appId: string, body: Record<string, any>, { onData, onCompleted, onError, getAbortController, onMessageEnd }: {
2023-05-15 08:51:32 +08:00
onData: IOnData
onCompleted: IOnCompleted
2023-09-09 19:17:12 +08:00
onMessageEnd: IOnMessageEnd
2023-06-06 10:52:02 +08:00
onError: IOnError
2023-05-15 08:51:32 +08:00
getAbortController?: (abortController: AbortController) => void
}) => {
return ssePost(`apps/${appId}/chat-messages`, {
body: {
...body,
2023-06-06 10:52:02 +08:00
response_mode: 'streaming',
},
2023-09-09 19:17:12 +08:00
}, { onData, onCompleted, onError, getAbortController, onMessageEnd })
2023-05-15 08:51:32 +08:00
}
2023-06-12 16:37:03 +08:00
export const stopChatMessageResponding = async (appId: string, taskId: string) => {
return post(`apps/${appId}/chat-messages/${taskId}/stop`)
}
2023-05-15 08:51:32 +08:00
export const sendCompletionMessage = async (appId: string, body: Record<string, any>, { onData, onCompleted, onError }: {
onData: IOnData
onCompleted: IOnCompleted
onError: IOnError
}) => {
return ssePost(`apps/${appId}/completion-messages`, {
body: {
...body,
2023-06-06 10:52:02 +08:00
response_mode: 'streaming',
},
2023-05-15 08:51:32 +08:00
}, { onData, onCompleted, onError })
}
export const fetchSuggestedQuestions = (appId: string, messageId: string) => {
return get(`apps/${appId}/chat-messages/${messageId}/suggested-questions`)
}
export const fetchConvesationMessages = (appId: string, conversation_id: string) => {
return get(`apps/${appId}/chat-messages`, {
params: {
2023-06-06 10:52:02 +08:00
conversation_id,
},
})
}
export const generateRule = (body: Record<string, any>) => {
return post('/rule-generate', {
body,
2023-05-15 08:51:32 +08:00
})
}
export const fetchModelParams = (providerName: string, modelId: string) => {
return get(`workspaces/current/model-providers/${providerName}/models/parameter-rules`, {
params: {
model_name: modelId,
},
})
}