This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| wiki:ai:chatbot-helpdesk-sentiment [2025/06/24 20:35] – ddehamer | wiki:ai:chatbot-helpdesk-sentiment [2025/07/02 21:10] (current) – zhein | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== AI Chatbot | + | ====== AI Chatbot |
| ===== Requirements ===== | ===== Requirements ===== | ||
| Line 12: | Line 13: | ||
| ===== Prerequisites ===== | ===== Prerequisites ===== | ||
| + | |||
| Install These | Install These | ||
| - | < | + | |
| + | < | ||
| brew install dotnet-sdk #This will be version 9 which will not work but gives you the rest of the stuff needed. | brew install dotnet-sdk #This will be version 9 which will not work but gives you the rest of the stuff needed. | ||
| brew install azure-cli | brew install azure-cli | ||
| </ | </ | ||
| + | Assuming you already have created a Resource Group named don-test-rg, | ||
| - | Assuming you already have created a Resource Group named don-test-rg, | + | Install this from the webpage |
| - | Install | + | Create a folder in your workspace and save the files at the end of this document. |
| - | [[https:// | + | |
| - | Then these | + | Open a terminal, set your folder to the one where the files are saved, then run these commands: |
| - | < | + | |
| + | These commands are only needed for Windows users: | ||
| + | <code -> | ||
| + | dotnet nuget add source https:// | ||
| + | npm install -g azure-functions-core-tools@4 --unsafe-perm true | ||
| + | dotnet nuget locals all --clear | ||
| + | dotnet restore | ||
| + | </ | ||
| + | |||
| + | The rest of the instructions are for every OS: | ||
| + | |||
| + | < | ||
| dotnet add package Microsoft.Azure.Functions.Worker.Extensions.OpenApi --version 1.4.0 | dotnet add package Microsoft.Azure.Functions.Worker.Extensions.OpenApi --version 1.4.0 | ||
| dotnet --list-sdks | dotnet --list-sdks | ||
| Line 33: | Line 47: | ||
| Create Storage Account | Create Storage Account | ||
| - | < | + | |
| + | < | ||
| az storage account create \ | az storage account create \ | ||
| --name dehamerfuncstorage \ | --name dehamerfuncstorage \ | ||
| Line 42: | Line 57: | ||
| Create Function Plan for Windows | Create Function Plan for Windows | ||
| - | < | + | |
| + | < | ||
| az functionapp plan create \ | az functionapp plan create \ | ||
| --resource-group don-test-rg \ | --resource-group don-test-rg \ | ||
| - | --name | + | --name |
| --location eastus \ | --location eastus \ | ||
| --sku B1 \ | --sku B1 \ | ||
| Line 52: | Line 68: | ||
| Create Function App | Create Function App | ||
| - | < | + | |
| + | < | ||
| az functionapp create \ | az functionapp create \ | ||
| --resource-group don-test-rg \ | --resource-group don-test-rg \ | ||
| --name dehamerfuncapp \ | --name dehamerfuncapp \ | ||
| - | --plan | + | --plan |
| --storage-account dehamerfunctstorage \ | --storage-account dehamerfunctstorage \ | ||
| --runtime dotnet-isolated \ | --runtime dotnet-isolated \ | ||
| Line 64: | Line 81: | ||
| Create TexAnalytics | Create TexAnalytics | ||
| - | < | + | |
| + | < | ||
| az cognitiveservices account create \ | az cognitiveservices account create \ | ||
| --name dehamersentimentai \ | --name dehamersentimentai \ | ||
| Line 74: | Line 92: | ||
| az cognitiveservices account update \ | az cognitiveservices account update \ | ||
| - | --name | + | --name |
| --resource-group don-test-rg \ | --resource-group don-test-rg \ | ||
| --set properties.publicNetworkAccess=Enabled | --set properties.publicNetworkAccess=Enabled | ||
| Line 80: | Line 98: | ||
| Get keys and endpoint for export and app settings | Get keys and endpoint for export and app settings | ||
| - | < | + | |
| + | < | ||
| export TEXT_ANALYTICS_ENDPOINT=`az cognitiveservices account show \ | export TEXT_ANALYTICS_ENDPOINT=`az cognitiveservices account show \ | ||
| --name dehamersentimentai \ | --name dehamersentimentai \ | ||
| Line 87: | Line 106: | ||
| export TEXT_ANALYTICS_KEY=`az cognitiveservices account keys list \ | export TEXT_ANALYTICS_KEY=`az cognitiveservices account keys list \ | ||
| - | --name | + | --name |
| --resource-group don-test-rg \ | --resource-group don-test-rg \ | ||
| --query " | --query " | ||
| Line 104: | Line 123: | ||
| export OPENAI_ENDPOINT=https:// | export OPENAI_ENDPOINT=https:// | ||
| + | |||
| + | export OPENAI_DEPLOYMENT=gpt-4.1 | ||
| az functionapp config appsettings set \ | az functionapp config appsettings set \ | ||
| - | --name | + | --name |
| --resource-group don-test-rg \ | --resource-group don-test-rg \ | ||
| --settings \ | --settings \ | ||
| OPENAI_KEY=$OPENAI_KEY \ | OPENAI_KEY=$OPENAI_KEY \ | ||
| OPENAI_ENDPOINT=$OPENAI_ENDPOINT | OPENAI_ENDPOINT=$OPENAI_ENDPOINT | ||
| + | OPENAI_DEPLOYMENT=$OPENAI_DEPLOYMENT | ||
| | | ||
| #Confirm they were set | #Confirm they were set | ||
| Line 120: | Line 142: | ||
| Create a directory to store the functionapp files | Create a directory to store the functionapp files | ||
| - | < | + | |
| + | < | ||
| mkdir ~/ | mkdir ~/ | ||
| cd ~/ | cd ~/ | ||
| Line 179: | Line 202: | ||
| // OpenAI Setup | // OpenAI Setup | ||
| - | var openaiEndpoint = Environment.GetEnvironmentVariable(" | + | var openaiEndpoint = Environment.GetEnvironmentVariable(" |
| - | var openaiKey = Environment.GetEnvironmentVariable(" | + | var openaiKey = Environment.GetEnvironmentVariable(" |
| var deployment = Environment.GetEnvironmentVariable(" | var deployment = Environment.GetEnvironmentVariable(" | ||
| Line 265: | Line 288: | ||
| Make sure this matches the version of dotnet 8.x you install. | Make sure this matches the version of dotnet 8.x you install. | ||
| + | |||
| <code - global.json> | <code - global.json> | ||
| { | { | ||
| Line 301: | Line 325: | ||
| From the FeedbackFunctionDonnet directory: | From the FeedbackFunctionDonnet directory: | ||
| - | < | + | |
| + | < | ||
| dotnet clean | dotnet clean | ||
| dotnet publish -c Release -o publish | dotnet publish -c Release -o publish | ||
| Line 311: | Line 336: | ||
| After running you will see additional files in the FeedbackFunctionDotnet directory. | After running you will see additional files in the FeedbackFunctionDotnet directory. | ||
| - | < | + | |
| + | < | ||
| ls | ls | ||
| bin | bin | ||
| Line 318: | Line 344: | ||
| To test if it is working | To test if it is working | ||
| - | < | + | |
| + | < | ||
| export FUNCTION_KEY=`az functionapp function keys list \ | export FUNCTION_KEY=`az functionapp function keys list \ | ||
| --name dehamerfuncapp \ | --name dehamerfuncapp \ | ||
| Line 331: | Line 358: | ||
| You should see something like: | You should see something like: | ||
| - | < | + | |
| + | < | ||
| {" | {" | ||
| </ | </ | ||
| Confirmation tests | Confirmation tests | ||
| - | < | + | |
| + | < | ||
| az functionapp function list --name dehamerfuncapp --resource-group don-test-rg --query " | az functionapp function list --name dehamerfuncapp --resource-group don-test-rg --query " | ||
| Name Status | Name Status | ||
| Line 343: | Line 372: | ||
| </ | </ | ||
| - | < | + | < |
| az functionapp show --name dehamerfuncapp --resource-group don-test-rg --query " | az functionapp show --name dehamerfuncapp --resource-group don-test-rg --query " | ||
| [ | [ | ||
| Line 351: | Line 380: | ||
| </ | </ | ||
| - | < | + | < |
| az functionapp function list \ | az functionapp function list \ | ||
| --name dehamerfuncapp \ | --name dehamerfuncapp \ | ||
| Line 361: | Line 390: | ||
| </ | </ | ||
| - | < | + | < |
| az functionapp function show \ | az functionapp function show \ | ||
| --name dehamerfuncapp \ | --name dehamerfuncapp \ | ||
| Line 372: | Line 401: | ||
| If true | If true | ||
| - | < | + | |
| + | < | ||
| az functionapp function update \ | az functionapp function update \ | ||
| --name dehamerfuncapp \ | --name dehamerfuncapp \ | ||
| Line 381: | Line 411: | ||
| Tailing logs if enabled. | Tailing logs if enabled. | ||
| - | < | + | |
| + | < | ||
| az webapp log tail \ | az webapp log tail \ | ||
| --name dehamerfuncapp \ | --name dehamerfuncapp \ | ||
| Line 388: | Line 419: | ||
| If you want it to autostart after issues. | If you want it to autostart after issues. | ||
| - | < | + | |
| + | < | ||
| #Optional | #Optional | ||
| az webapp config set \ | az webapp config set \ | ||
| Line 397: | Line 429: | ||
| Get a list of your functionapps | Get a list of your functionapps | ||
| - | < | + | |
| + | < | ||
| az functionapp function list \ | az functionapp function list \ | ||
| --name dehamerfuncapp \ | --name dehamerfuncapp \ | ||
| Line 407: | Line 440: | ||
| https:// | https:// | ||
| </ | </ | ||
| + | |||
| + | Only do this for testing. | ||
| + | |||
| + | <code -> | ||
| + | az functionapp cors add \ | ||
| + | --name dehamerfuncapp \ | ||
| + | --resource-group don-test-rg \ | ||
| + | --allowed-origins " | ||
| + | </ | ||
| + | |||
| + | If you have a webserver that you trust, you can create this webpage and test it: | ||
| + | |||
| + | <code - index.html> | ||
| + | < | ||
| + | <html lang=" | ||
| + | < | ||
| + | <meta charset=" | ||
| + | < | ||
| + | < | ||
| + | body { | ||
| + | background-color: | ||
| + | color: red; | ||
| + | font-family: | ||
| + | margin: 40px; | ||
| + | } | ||
| + | |||
| + | header { | ||
| + | display: flex; | ||
| + | align-items: | ||
| + | margin-bottom: | ||
| + | } | ||
| + | |||
| + | header img { | ||
| + | height: 50px; | ||
| + | margin-right: | ||
| + | } | ||
| + | |||
| + | h1 { | ||
| + | font-size: 2em; | ||
| + | } | ||
| + | |||
| + | textarea { | ||
| + | width: 100%; | ||
| + | height: 100px; | ||
| + | font-size: 1em; | ||
| + | padding: 10px; | ||
| + | } | ||
| + | |||
| + | button { | ||
| + | margin-top: 10px; | ||
| + | padding: 10px 20px; | ||
| + | font-size: 1em; | ||
| + | background-color: | ||
| + | color: white; | ||
| + | border: none; | ||
| + | cursor: pointer; | ||
| + | } | ||
| + | |||
| + | #response { | ||
| + | margin-top: 20px; | ||
| + | font-weight: | ||
| + | white-space: | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | <img src=" | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | <form id=" | ||
| + | <label for=" | ||
| + | < | ||
| + | <button type=" | ||
| + | </ | ||
| + | |||
| + | <div id=" | ||
| + | |||
| + | < | ||
| + | document.getElementById(' | ||
| + | e.preventDefault(); | ||
| + | |||
| + | const feedback = document.getElementById(' | ||
| + | const responseDiv = document.getElementById(' | ||
| + | |||
| + | responseDiv.textContent = " | ||
| + | |||
| + | try { | ||
| + | const res = await fetch(' | ||
| + | method: ' | ||
| + | headers: { | ||
| + | ' | ||
| + | }, | ||
| + | body: JSON.stringify({ feedback }) | ||
| + | }); | ||
| + | |||
| + | if (!res.ok) { | ||
| + | throw new Error(" | ||
| + | } | ||
| + | |||
| + | const data = await res.json(); | ||
| + | responseDiv.innerHTML = `< | ||
| + | } catch (err) { | ||
| + | responseDiv.textContent = " | ||
| + | } | ||
| + | }); | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== Dennis Additions ===== | ||
| + | |||
| + | ==== Azure CLI vs Azure Portal Instructions ==== | ||
| + | |||
| + | | Task | Azure CLI Command | Azure Portal Steps | | ||
| + | | Create Resource Group | az group create --name don-test-rg --location eastus | Go to Azure Portal > Resource Groups > Create | | ||
| + | | Create Storage Account | az storage account create --name dehamerfuncstorage --location eastus --resource-group don-test-rg --sku Standard_LRS | Go to Storage Accounts > Create | | ||
| + | | Create Function App | az functionapp create --resource-group don-test-rg --consumption-plan-location eastus --runtime dotnet-isolated --functions-version 4 --name dehamerfuncapp --storage-account dehamerfuncstorage | Go to Function Apps > Create > Choose .NET Isolated | | ||
| + | | Deploy Code via Zip | az functionapp deployment source config-zip --src publish.zip --name dehamerfuncapp --resource-group don-test-rg | Go to Function App > Deployment Center > Zip Deploy | | ||
| + | | Create Cognitive Services Resource | az cognitiveservices account create --name dehamersentimentai --resource-group don-test-rg --kind TextAnalytics --sku S --location eastus --yes | Search ' | ||
| + | | Set App Settings | az functionapp config appsettings set --name dehamerfuncapp --resource-group don-test-rg --settings KEY=value | Go to Configuration > Application Settings > Add New | | ||
| + | |||
| + | ==== Successful Deployment Steps ==== | ||
| + | |||
| + | After resolving early build issues and switching from Linux to a Windows-hosted function plan due to SDK compatibility, | ||
| + | |||
| + | - Rewrote the function class to eliminate naming conflicts\\ - Set AuthorizationLevel to Anonymous to permit open feedback submission\\ - Used curl to verify responses from the deployed function\\ - Created an HTML frontend to POST feedback to the function endpoint | ||
| + | |||
| + | ==== Architectural Diagram ==== | ||
| + | |||
| + | {{: | ||
| + | |||
| + | [[ai_knowledge|AI Knowledge]] | ||
| + | |||