-
Notifications
You must be signed in to change notification settings - Fork 12
[#393] Allow unauthenticated users to use the chatbot #399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sahilds1
merged 4 commits into
CodeForPhilly:309-393-test-combined-prs
from
sahilds1:393-make-the-chatbot-public
Nov 18, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -3,15 +3,17 @@ import { FormValues } from "../pages/Feedback/FeedbackForm"; | |
| import { Conversation } from "../components/Header/Chat"; | ||
| const baseURL = import.meta.env.VITE_API_BASE_URL; | ||
|
|
||
| export const api = axios.create({ | ||
| export const publicApi = axios.create({ baseURL }); | ||
|
|
||
| export const adminApi = axios.create({ | ||
| baseURL, | ||
| headers: { | ||
| Authorization: `JWT ${localStorage.getItem("access")}`, | ||
| }, | ||
| }); | ||
|
|
||
| // Request interceptor to set the Authorization header | ||
| api.interceptors.request.use( | ||
| adminApi.interceptors.request.use( | ||
| (configuration) => { | ||
| const token = localStorage.getItem("access"); | ||
| if (token) { | ||
|
|
@@ -42,9 +44,14 @@ const handleSubmitFeedback = async ( | |
| } | ||
| }; | ||
|
|
||
| const handleSendDrugSummary = async (message: FormValues["message"], guid: string) => { | ||
| const handleSendDrugSummary = async ( | ||
| message: FormValues["message"], | ||
| guid: string, | ||
| ) => { | ||
| try { | ||
| const endpoint = guid ? `/v1/api/embeddings/ask_embeddings?guid=${guid}` : '/v1/api/embeddings/ask_embeddings'; | ||
| const endpoint = guid | ||
| ? `/v1/api/embeddings/ask_embeddings?guid=${guid}` | ||
| : "/v1/api/embeddings/ask_embeddings"; | ||
| const response = await api.post(endpoint, { | ||
| message, | ||
| }); | ||
|
|
@@ -58,7 +65,9 @@ const handleSendDrugSummary = async (message: FormValues["message"], guid: strin | |
|
|
||
| const handleRuleExtraction = async (guid: string) => { | ||
| try { | ||
| const response = await api.get(`/v1/api/rule_extraction_openai?guid=${guid}`); | ||
| const response = await api.get( | ||
| `/v1/api/rule_extraction_openai?guid=${guid}`, | ||
| ); | ||
| // console.log("Rule extraction response:", JSON.stringify(response.data, null, 2)); | ||
| return response.data; | ||
| } catch (error) { | ||
|
|
@@ -67,7 +76,10 @@ const handleRuleExtraction = async (guid: string) => { | |
| } | ||
| }; | ||
|
|
||
| const fetchRiskDataWithSources = async (medication: string, source: "include" | "diagnosis" | "diagnosis_depressed" = "include") => { | ||
| const fetchRiskDataWithSources = async ( | ||
| medication: string, | ||
| source: "include" | "diagnosis" | "diagnosis_depressed" = "include", | ||
| ) => { | ||
| try { | ||
| const response = await api.post(`/v1/api/riskWithSources`, { | ||
| drug: medication, | ||
|
|
@@ -90,7 +102,7 @@ interface StreamCallbacks { | |
| const handleSendDrugSummaryStream = async ( | ||
| message: string, | ||
| guid: string, | ||
| callbacks: StreamCallbacks | ||
| callbacks: StreamCallbacks, | ||
| ): Promise<void> => { | ||
| const token = localStorage.getItem("access"); | ||
| const endpoint = `/v1/api/embeddings/ask_embeddings?stream=true${ | ||
|
|
@@ -165,12 +177,18 @@ const handleSendDrugSummaryStream = async ( | |
| } | ||
| } | ||
| } catch (parseError) { | ||
| console.error("Failed to parse SSE data:", parseError, "Raw line:", line); | ||
| console.error( | ||
| "Failed to parse SSE data:", | ||
| parseError, | ||
| "Raw line:", | ||
| line, | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| } catch (error) { | ||
| const errorMessage = error instanceof Error ? error.message : "Unknown error"; | ||
| const errorMessage = | ||
| error instanceof Error ? error.message : "Unknown error"; | ||
| console.error("Error in stream:", errorMessage); | ||
| callbacks.onError?.(errorMessage); | ||
| throw error; | ||
|
|
@@ -186,7 +204,7 @@ const handleSendDrugSummaryStreamLegacy = async ( | |
| return handleSendDrugSummaryStream(message, guid, { | ||
| onContent: onChunk, | ||
| onError: (error) => console.error("Stream error:", error), | ||
| onComplete: () => console.log("Stream completed") | ||
| onComplete: () => console.log("Stream completed"), | ||
| }); | ||
| }; | ||
|
|
||
|
|
@@ -255,11 +273,16 @@ const deleteConversation = async (id: string) => { | |
| const updateConversationTitle = async ( | ||
| id: Conversation["id"], | ||
| newTitle: Conversation["title"], | ||
| ): Promise<{status: string, title: Conversation["title"]} | {error: string}> => { | ||
| ): Promise< | ||
| { status: string; title: Conversation["title"] } | { error: string } | ||
| > => { | ||
| try { | ||
| const response = await api.patch(`/chatgpt/conversations/${id}/update_title/`, { | ||
| title: newTitle, | ||
| }); | ||
| const response = await api.patch( | ||
| `/chatgpt/conversations/${id}/update_title/`, | ||
| { | ||
| title: newTitle, | ||
| }, | ||
| ); | ||
| return response.data; | ||
| } catch (error) { | ||
| console.error("Error(s) during getConversation: ", error); | ||
|
|
@@ -268,9 +291,12 @@ const updateConversationTitle = async ( | |
| }; | ||
|
|
||
| // Assistant API functions | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes here allow unauthenticated users to use the chatbot |
||
| const sendAssistantMessage = async (message: string, previousResponseId?: string) => { | ||
| const sendAssistantMessage = async ( | ||
| message: string, | ||
| previousResponseId?: string, | ||
| ) => { | ||
| try { | ||
| const response = await api.post(`/v1/api/assistant`, { | ||
| const response = await publicApi.post(`/v1/api/assistant`, { | ||
| message, | ||
| previous_response_id: previousResponseId, | ||
| }); | ||
|
|
@@ -294,5 +320,5 @@ export { | |
| handleSendDrugSummaryStream, | ||
| handleSendDrugSummaryStreamLegacy, | ||
| fetchRiskDataWithSources, | ||
| sendAssistantMessage | ||
| }; | ||
| sendAssistantMessage, | ||
| }; | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes here are formatting changes automatically made by Zed