2023-08-05 12:10:36 -04:00
|
|
|
import { tConversationSchema } from './schemas';
|
2023-08-05 13:45:26 -07:00
|
|
|
import { TSubmission, EModelEndpoint } from './types';
|
2023-07-30 10:37:25 -04:00
|
|
|
|
|
|
|
|
export default function createPayload(submission: TSubmission) {
|
|
|
|
|
const { conversation, message, endpointOption } = submission;
|
2023-08-05 12:10:36 -04:00
|
|
|
const { conversationId } = tConversationSchema.parse(conversation);
|
2023-07-30 10:37:25 -04:00
|
|
|
const { endpoint } = endpointOption as { endpoint: EModelEndpoint };
|
|
|
|
|
|
|
|
|
|
const endpointUrlMap = {
|
|
|
|
|
azureOpenAI: '/api/ask/azureOpenAI',
|
|
|
|
|
openAI: '/api/ask/openAI',
|
|
|
|
|
google: '/api/ask/google',
|
|
|
|
|
bingAI: '/api/ask/bingAI',
|
|
|
|
|
chatGPT: '/api/ask/chatGPT',
|
|
|
|
|
chatGPTBrowser: '/api/ask/chatGPTBrowser',
|
|
|
|
|
gptPlugins: '/api/ask/gptPlugins',
|
|
|
|
|
anthropic: '/api/ask/anthropic',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const server = endpointUrlMap[endpoint];
|
|
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
|
...message,
|
|
|
|
|
...endpointOption,
|
|
|
|
|
conversationId,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return { server, payload };
|
|
|
|
|
}
|