mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-30 09:03:15 +00:00
enhancement: reusable api client setup + replaced in settings, conversation
This commit is contained in:
69
frontend/src/api/client.ts
Normal file
69
frontend/src/api/client.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
const baseURL = import.meta.env.VITE_API_HOST || 'https://docsapi.arc53.com';
|
||||
|
||||
const defaultHeaders = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
const apiClient = {
|
||||
get: (url: string, headers = {}, signal?: AbortSignal): Promise<any> =>
|
||||
fetch(`${baseURL}${url}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
...headers,
|
||||
},
|
||||
signal,
|
||||
}).then((response) => {
|
||||
return response;
|
||||
}),
|
||||
|
||||
post: (
|
||||
url: string,
|
||||
data: any,
|
||||
headers = {},
|
||||
signal?: AbortSignal,
|
||||
): Promise<any> =>
|
||||
fetch(`${baseURL}${url}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
...headers,
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
signal,
|
||||
}).then((response) => {
|
||||
return response;
|
||||
}),
|
||||
|
||||
put: (
|
||||
url: string,
|
||||
data: any,
|
||||
headers = {},
|
||||
signal?: AbortSignal,
|
||||
): Promise<any> =>
|
||||
fetch(`${baseURL}${url}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
...headers,
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
signal,
|
||||
}).then((response) => {
|
||||
return response;
|
||||
}),
|
||||
|
||||
delete: (url: string, headers = {}, signal?: AbortSignal): Promise<any> =>
|
||||
fetch(`${baseURL}${url}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
...headers,
|
||||
},
|
||||
signal,
|
||||
}).then((response) => {
|
||||
return response;
|
||||
}),
|
||||
};
|
||||
|
||||
export default apiClient;
|
||||
23
frontend/src/api/endpoints.ts
Normal file
23
frontend/src/api/endpoints.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
const endpoints = {
|
||||
USER: {
|
||||
API_KEYS: '/api/get_api_keys',
|
||||
CREATE_API_KEY: '/api/create_api_key',
|
||||
DELETE_API_KEY: '/api/delete_api_key',
|
||||
PROMPTS: '/api/get_prompts',
|
||||
CREATE_PROMPT: '/api/create_prompt',
|
||||
DELETE_PROMPT: '/api/delete_prompt',
|
||||
UPDATE_PROMPT: '/api/update_prompt',
|
||||
SINGLE_PROMPT: (id: string) => `/api/get_single_prompt?id=${id}`,
|
||||
DELETE_PATH: (docPath: string) => `/api/delete_old?path=${docPath}`,
|
||||
},
|
||||
CONVERSATION: {
|
||||
ANSWER: '/api/answer',
|
||||
ANSWER_STREAMING: '/stream',
|
||||
SEARCH: '/api/search',
|
||||
FEEDBACK: '/api/feedback',
|
||||
SHARED_CONVERSATION: (identifier: string) =>
|
||||
`/api/shared_conversation/${identifier}`,
|
||||
},
|
||||
};
|
||||
|
||||
export default endpoints;
|
||||
17
frontend/src/api/services/conversationService.ts
Normal file
17
frontend/src/api/services/conversationService.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import apiClient from '../client';
|
||||
import endpoints from '../endpoints';
|
||||
|
||||
const conversationService = {
|
||||
answer: (data: any, signal: AbortSignal): Promise<any> =>
|
||||
apiClient.post(endpoints.CONVERSATION.ANSWER, data, {}, signal),
|
||||
answerStream: (data: any, signal: AbortSignal): Promise<any> =>
|
||||
apiClient.post(endpoints.CONVERSATION.ANSWER_STREAMING, data, {}, signal),
|
||||
search: (data: any): Promise<any> =>
|
||||
apiClient.post(endpoints.CONVERSATION.SEARCH, data),
|
||||
feedback: (data: any): Promise<any> =>
|
||||
apiClient.post(endpoints.CONVERSATION.FEEDBACK, data),
|
||||
getSharedConversation: (identifier: string): Promise<any> =>
|
||||
apiClient.get(endpoints.CONVERSATION.SHARED_CONVERSATION(identifier)),
|
||||
};
|
||||
|
||||
export default conversationService;
|
||||
23
frontend/src/api/services/userService.ts
Normal file
23
frontend/src/api/services/userService.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import apiClient from '../client';
|
||||
import endpoints from '../endpoints';
|
||||
|
||||
const userService = {
|
||||
getAPIKeys: (): Promise<any> => apiClient.get(endpoints.USER.API_KEYS),
|
||||
createAPIKey: (data: any): Promise<any> =>
|
||||
apiClient.post(endpoints.USER.CREATE_API_KEY, data),
|
||||
deleteAPIKey: (data: any): Promise<any> =>
|
||||
apiClient.post(endpoints.USER.DELETE_API_KEY, data),
|
||||
getPrompts: (): Promise<any> => apiClient.get(endpoints.USER.PROMPTS),
|
||||
createPrompt: (data: any): Promise<any> =>
|
||||
apiClient.post(endpoints.USER.CREATE_PROMPT, data),
|
||||
deletePrompt: (data: any): Promise<any> =>
|
||||
apiClient.post(endpoints.USER.DELETE_PROMPT, data),
|
||||
updatePrompt: (data: any): Promise<any> =>
|
||||
apiClient.post(endpoints.USER.UPDATE_PROMPT, data),
|
||||
getSinglePrompt: (id: string): Promise<any> =>
|
||||
apiClient.get(endpoints.USER.SINGLE_PROMPT(id)),
|
||||
deletePath: (docPath: string): Promise<any> =>
|
||||
apiClient.get(endpoints.USER.DELETE_PATH(docPath)),
|
||||
};
|
||||
|
||||
export default userService;
|
||||
Reference in New Issue
Block a user