forked from arc53/DocsGPT
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request arc53#1040 from siiddhantt/enhancement/reusable-ap…
…i-client enhancement: reusable api client in frontend
- Loading branch information
Showing
19 changed files
with
604 additions
and
511 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const endpoints = { | ||
USER: { | ||
DOCS: '/api/combine', | ||
DOCS_CHECK: '/api/docs_check', | ||
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}`, | ||
TASK_STATUS: (task_id: string) => `/api/task_status?task_id=${task_id}`, | ||
}, | ||
CONVERSATION: { | ||
ANSWER: '/api/answer', | ||
ANSWER_STREAMING: '/stream', | ||
SEARCH: '/api/search', | ||
FEEDBACK: '/api/feedback', | ||
CONVERSATION: (id: string) => `/api/get_single_conversation?id=${id}`, | ||
CONVERSATIONS: '/api/get_conversations', | ||
SHARE_CONVERSATION: (isPromptable: boolean) => | ||
`/api/share?isPromptable=${isPromptable}`, | ||
SHARED_CONVERSATION: (identifier: string) => | ||
`/api/shared_conversation/${identifier}`, | ||
DELETE: (id: string) => `/api/delete_conversation?id=${id}`, | ||
DELETE_ALL: '/api/delete_all_conversations', | ||
UPDATE: '/api/update_conversation_name', | ||
}, | ||
}; | ||
|
||
export default endpoints; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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), | ||
getConversation: (id: string): Promise<any> => | ||
apiClient.get(endpoints.CONVERSATION.CONVERSATION(id)), | ||
getConversations: (): Promise<any> => | ||
apiClient.get(endpoints.CONVERSATION.CONVERSATIONS), | ||
shareConversation: (isPromptable: boolean, data: any): Promise<any> => | ||
apiClient.post( | ||
endpoints.CONVERSATION.SHARE_CONVERSATION(isPromptable), | ||
data, | ||
), | ||
getSharedConversation: (identifier: string): Promise<any> => | ||
apiClient.get(endpoints.CONVERSATION.SHARED_CONVERSATION(identifier)), | ||
delete: (id: string, data: any): Promise<any> => | ||
apiClient.post(endpoints.CONVERSATION.DELETE(id), data), | ||
deleteAll: (data: any): Promise<any> => | ||
apiClient.post(endpoints.CONVERSATION.DELETE_ALL, data), | ||
update: (data: any): Promise<any> => | ||
apiClient.post(endpoints.CONVERSATION.UPDATE, data), | ||
}; | ||
|
||
export default conversationService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import apiClient from '../client'; | ||
import endpoints from '../endpoints'; | ||
|
||
const userService = { | ||
getDocs: (): Promise<any> => apiClient.get(endpoints.USER.DOCS), | ||
checkDocs: (data: any): Promise<any> => | ||
apiClient.post(endpoints.USER.DOCS_CHECK, data), | ||
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)), | ||
getTaskStatus: (task_id: string): Promise<any> => | ||
apiClient.get(endpoints.USER.TASK_STATUS(task_id)), | ||
}; | ||
|
||
export default userService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.