File size: 1,223 Bytes
c5cf697
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
import { apiJson } from './http'

export function listChats({ skip = 0, limit = 30 } = {}) {
  const q = new URLSearchParams({
    skip: String(skip),
    limit: String(limit),
  })
  return apiJson(`/list_chats?${q}`, { auth: true })
}

export function createChat() {
  return apiJson('/get_new_chat', { method: 'POST', auth: true })
}

/** Latest page: omit beforeIndex. Older: pass next_before_index from prior response. */
export function fetchChatPage(chatId, { beforeIndex = null, limit = 20 } = {}) {
  const q = new URLSearchParams({ limit: String(limit) })
  if (beforeIndex != null) q.set('before_index', String(beforeIndex))
  return apiJson(`/get_chat/${encodeURIComponent(chatId)}?${q}`, { auth: true })
}

export function removeChat(chatId) {
  return apiJson(`/delete_chat/${encodeURIComponent(chatId)}`, {
    method: 'DELETE',
    auth: true,
  })
}

export function sendMessage(
  chatId,
  question,
  {
    allowAugmentation = true,
    useWebSearch = false,
  } = {},
) {
  return apiJson('/response', {
    method: 'POST',
    body: JSON.stringify({
      chat_id: chatId,
      question,
      allow_augmentation: allowAugmentation,
      use_web_search: useWebSearch,
    }),
    auth: true,
  })
}