@@ -3,15 +3,19 @@ import { FormValues } from "../pages/Feedback/FeedbackForm";
33import { Conversation } from "../components/Header/Chat" ;
44const baseURL = import . meta. env . VITE_API_BASE_URL ;
55
6- export const api = axios . create ( {
6+ export const publicApi = axios . create ( {
7+ baseURL
8+ } ) ;
9+
10+ export const adminApi = axios . create ( {
711 baseURL,
812 headers : {
913 Authorization : `JWT ${ localStorage . getItem ( "access" ) } ` ,
1014 } ,
1115} ) ;
1216
1317// Request interceptor to set the Authorization header
14- api . interceptors . request . use (
18+ adminApi . interceptors . request . use (
1519 ( configuration ) => {
1620 const token = localStorage . getItem ( "access" ) ;
1721 if ( token ) {
@@ -29,7 +33,7 @@ const handleSubmitFeedback = async (
2933 message : FormValues [ "message" ] ,
3034) => {
3135 try {
32- const response = await api . post ( `/v1/api/feedback/` , {
36+ const response = await publicApi . post ( `/v1/api/feedback/` , {
3337 feedbacktype : feedbackType ,
3438 name,
3539 email,
@@ -45,7 +49,7 @@ const handleSubmitFeedback = async (
4549const handleSendDrugSummary = async ( message : FormValues [ "message" ] , guid : string ) => {
4650 try {
4751 const endpoint = guid ? `/v1/api/embeddings/ask_embeddings?guid=${ guid } ` : '/v1/api/embeddings/ask_embeddings' ;
48- const response = await api . post ( endpoint , {
52+ const response = await adminApi . post ( endpoint , {
4953 message,
5054 } ) ;
5155 console . log ( "Response data:" , JSON . stringify ( response . data , null , 2 ) ) ;
@@ -58,7 +62,7 @@ const handleSendDrugSummary = async (message: FormValues["message"], guid: strin
5862
5963const handleRuleExtraction = async ( guid : string ) => {
6064 try {
61- const response = await api . get ( `/v1/api/rule_extraction_openai?guid=${ guid } ` ) ;
65+ const response = await adminApi . get ( `/v1/api/rule_extraction_openai?guid=${ guid } ` ) ;
6266 // console.log("Rule extraction response:", JSON.stringify(response.data, null, 2));
6367 return response . data ;
6468 } catch ( error ) {
@@ -69,7 +73,7 @@ const handleRuleExtraction = async (guid: string) => {
6973
7074const fetchRiskDataWithSources = async ( medication : string , source : "include" | "diagnosis" = "include" ) => {
7175 try {
72- const response = await api . post ( `/v1/api/riskWithSources` , {
76+ const response = await adminApi . post ( `/v1/api/riskWithSources` , {
7377 drug : medication ,
7478 source : source ,
7579 } ) ;
@@ -192,7 +196,7 @@ const handleSendDrugSummaryStreamLegacy = async (
192196
193197const fetchConversations = async ( ) : Promise < Conversation [ ] > => {
194198 try {
195- const response = await api . get ( `/chatgpt/conversations/` ) ;
199+ const response = await publicApi . get ( `/chatgpt/conversations/` ) ;
196200 return response . data ;
197201 } catch ( error ) {
198202 console . error ( "Error(s) during getConversations: " , error ) ;
@@ -202,7 +206,7 @@ const fetchConversations = async (): Promise<Conversation[]> => {
202206
203207const fetchConversation = async ( id : string ) : Promise < Conversation > => {
204208 try {
205- const response = await api . get ( `/chatgpt/conversations/${ id } /` ) ;
209+ const response = await publicApi . get ( `/chatgpt/conversations/${ id } /` ) ;
206210 return response . data ;
207211 } catch ( error ) {
208212 console . error ( "Error(s) during getConversation: " , error ) ;
@@ -212,7 +216,7 @@ const fetchConversation = async (id: string): Promise<Conversation> => {
212216
213217const newConversation = async ( ) : Promise < Conversation > => {
214218 try {
215- const response = await api . post ( `/chatgpt/conversations/` , {
219+ const response = await publicApi . post ( `/chatgpt/conversations/` , {
216220 messages : [ ] ,
217221 } ) ;
218222 return response . data ;
@@ -228,7 +232,7 @@ const continueConversation = async (
228232 page_context ?: string ,
229233) : Promise < { response : string ; title : Conversation [ "title" ] } > => {
230234 try {
231- const response = await api . post (
235+ const response = await publicApi . post (
232236 `/chatgpt/conversations/${ id } /continue_conversation/` ,
233237 {
234238 message,
@@ -244,7 +248,7 @@ const continueConversation = async (
244248
245249const deleteConversation = async ( id : string ) => {
246250 try {
247- const response = await api . delete ( `/chatgpt/conversations/${ id } /` ) ;
251+ const response = await publicApi . delete ( `/chatgpt/conversations/${ id } /` ) ;
248252 return response . data ;
249253 } catch ( error ) {
250254 console . error ( "Error(s) during deleteConversation: " , error ) ;
@@ -257,7 +261,7 @@ const updateConversationTitle = async (
257261 newTitle : Conversation [ "title" ] ,
258262) : Promise < { status : string , title : Conversation [ "title" ] } | { error : string } > => {
259263 try {
260- const response = await api . patch ( `/chatgpt/conversations/${ id } /update_title/` , {
264+ const response = await publicApi . patch ( `/chatgpt/conversations/${ id } /update_title/` , {
261265 title : newTitle ,
262266 } ) ;
263267 return response . data ;
0 commit comments