File size: 758 Bytes
4d270f8
7781557
83f6a8c
7781557
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83f6a8c
7781557
 
 
 
 
 
 
 
 
 
 
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
const API_URL = 'http://localhost:8000';

export const login = async (string, password) => {
  const response = await fetch(`${API_URL}/api/token`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: new URLSearchParams({
      username,
      password,
    }),
  });

  if (!response.ok) {
    throw new Error('Login failed');
  }

  const data = await response.json();
  return data.access_token;
};

export const clearMessages = async (token) => {
  const response = await fetch(`${API_URL}/api/clear_memory`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${token}`,
    },
    body: JSON.stringify({})
  })
  return response
}