-
Notifications
You must be signed in to change notification settings - Fork 0
Dev to qa #86
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
Dev to qa #86
Changes from all commits
a8a2123
3a24ee2
56ddd32
56293e7
8d59f4d
8b694c2
019a35c
aaf9c6f
ee8d153
398cc23
bc0dc9a
b4f0638
6a897aa
6c9b19e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Azure Function App URL for chat API | ||
| # Format: https://<environment>-alpinebot-func.azurewebsites.net | ||
| # Example for dev: https://dev-alpinebot-func.azurewebsites.net | ||
| REACT_APP_FUNCTION_APP_URL= |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -30,7 +30,7 @@ const HomePage = ({ user, onLogout }) => { | |||||
| scrollToBottom(); | ||||||
| }, [messages]); | ||||||
|
|
||||||
| const handleSend = (e) => { | ||||||
| const handleSend = async (e) => { | ||||||
| e.preventDefault(); | ||||||
| if (!inputValue.trim()) return; | ||||||
|
|
||||||
|
|
@@ -43,20 +43,62 @@ const HomePage = ({ user, onLogout }) => { | |||||
| }; | ||||||
|
|
||||||
| setMessages((prev) => [...prev, userMessage]); | ||||||
| const currentMessage = inputValue; | ||||||
| setInputValue(""); | ||||||
| setIsTyping(true); | ||||||
|
|
||||||
| // Simulate bot response (placeholder for future API integration) | ||||||
| setTimeout(() => { | ||||||
| try { | ||||||
| // Get Function App URL from environment variable | ||||||
| const functionAppUrl = process.env.REACT_APP_FUNCTION_APP_URL || ""; | ||||||
|
|
||||||
| if (!functionAppUrl) { | ||||||
| throw new Error("Function App URL not configured"); | ||||||
| } | ||||||
|
|
||||||
| // Build conversation history for API | ||||||
| const conversationHistory = messages.map((msg) => ({ | ||||||
| role: msg.type === "user" ? "user" : "assistant", | ||||||
| content: msg.text, | ||||||
| })); | ||||||
|
|
||||||
| // Call Azure Function App API | ||||||
| const response = await fetch(`${functionAppUrl}/api/chat`, { | ||||||
| method: "POST", | ||||||
| headers: { | ||||||
| "Content-Type": "application/json", | ||||||
| }, | ||||||
| body: JSON.stringify({ | ||||||
| message: currentMessage, | ||||||
| conversation_history: conversationHistory, | ||||||
| }), | ||||||
| }); | ||||||
|
|
||||||
| if (!response.ok) { | ||||||
| throw new Error(`API error: ${response.status} ${response.statusText}`); | ||||||
| } | ||||||
|
|
||||||
| const data = await response.json(); | ||||||
|
|
||||||
| const botMessage = { | ||||||
| id: Date.now() + 1, | ||||||
| type: "bot", | ||||||
| text: "I'm a placeholder response. Integration with Azure OpenAI will be implemented in future tasks.", | ||||||
| text: data.response || "I apologize, but I couldn't generate a response.", | ||||||
| timestamp: new Date(), | ||||||
| }; | ||||||
| setMessages((prev) => [...prev, botMessage]); | ||||||
| } catch (error) { | ||||||
| // Log error without sensitive details | ||||||
| console.error("Error calling chat API"); | ||||||
|
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
Suggested change
|
||||||
| const errorMessage = { | ||||||
| id: Date.now() + 1, | ||||||
| type: "bot", | ||||||
| text: "I apologize, but I'm having trouble connecting to the service. Please try again later.", | ||||||
| timestamp: new Date(), | ||||||
| }; | ||||||
| setMessages((prev) => [...prev, errorMessage]); | ||||||
|
Comment on lines
82
to
+98
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. Using |
||||||
| } finally { | ||||||
| setIsTyping(false); | ||||||
| }, 1500); | ||||||
| } | ||||||
| }; | ||||||
|
|
||||||
| const handleVote = (messageId, vote) => { | ||||||
|
|
||||||
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.
Changing the authentication level to
ANONYMOUSexposes this function endpoint to the public internet without any authentication. This means anyone can call your chat API, which could lead to significant security risks and unexpected costs from the underlying Azure OpenAI service. The function should be secured. Consider using Azure App Service's built-in authentication (Easy Auth) on the Function App as well, or revert toAuthLevel.FUNCTIONand securely provide the function key to the frontend application via its application settings.