File size: 994 Bytes
9705b6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { tConversationSchema } from './schemas';
import { TSubmission, EModelEndpoint } from './types';

export default function createPayload(submission: TSubmission) {
  const { conversation, message, endpointOption, isEdited, isContinued } = submission;
  const { conversationId } = tConversationSchema.parse(conversation);
  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',
  };

  let server = endpointUrlMap[endpoint];

  if (isEdited) {
    server = server.replace('/ask/', '/edit/');
  }

  const payload = {
    ...message,
    ...endpointOption,
    isContinued: isEdited && isContinued,
    conversationId,
  };

  return { server, payload };
}