Skip to content

Commit

Permalink
updated the model
Browse files Browse the repository at this point in the history
  • Loading branch information
vieiraae committed Feb 6, 2025
1 parent 08c868e commit 65137e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
2 changes: 2 additions & 0 deletions labs/token-metrics-emitting/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ param apimSku string
param openAIConfig array = []
param openAIModelName string
param openAIModelVersion string
param openAIModelSKU string
param openAIDeploymentName string
param openAIAPIVersion string = '2024-02-01'

Expand Down Expand Up @@ -67,6 +68,7 @@ module openAIModule '../../modules/cognitive-services/v1/openai.bicep' = {
openAIDeploymentName: openAIDeploymentName
openAIModelName: openAIModelName
openAIModelVersion: openAIModelVersion
openAIModelSKU: openAIModelSKU
apimPrincipalId: apimModule.outputs.principalId
lawId: lawId
}
Expand Down
50 changes: 21 additions & 29 deletions labs/token-metrics-emitting/token-metrics-emitting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@
"### Result\n",
"![result](result.png)\n",
"\n",
"### TOC\n",
"- [0️⃣ Initialize notebook variables](#0)\n",
"- [1️⃣ Verify the Azure CLI and the connected Azure subscription](#1)\n",
"- [2️⃣ Create deployment using 🦾 Bicep](#2)\n",
"- [3️⃣ Get the deployment outputs](#3)\n",
"- [🧪 Test the API using a direct HTTP call](#requests)\n",
"- [🧪 Execute multiple runs for each subscription using the Azure OpenAI Python SDK](#sdk)\n",
"- [🔍 Analyze Application Insights custom metrics with a KQL query](#kql)\n",
"- [🔍 Plot the custom metrics results](#plot)\n",
"- [🔍 See the metrics on the Azure Portal](#portal)\n",
"- [🗑️ Clean up resources](#clean)\n",
"\n",
"### Prerequisites\n",
"- [Python 3.12 or later version](https://www.python.org/) installed\n",
"- [Pandas Library](https://pandas.pydata.org/) and matplotlib installed\n",
Expand Down Expand Up @@ -69,18 +57,18 @@
"\n",
"deployment_name = os.path.basename(os.path.dirname(globals()['__vsc_ipynb_file__']))\n",
"resource_group_name = f\"lab-{deployment_name}\" # change the name to match your naming style\n",
"resource_group_location = \"westeurope\"\n",
"resource_group_location = \"uksouth\"\n",
"\n",
"apim_sku = 'Basicv2'\n",
"\n",
"openai_resources = [\n",
" {\"name\": \"openai1\", \"location\": \"swedencentral\"}\n",
"]\n",
"openai_resources = [ {\"name\": \"openai1\", \"location\": \"uksouth\"}]\n",
"\n",
"\n",
"openai_model_name = \"gpt-35-turbo\"\n",
"openai_model_version = \"0613\"\n",
"openai_deployment_name = \"gpt-35-turbo\"\n",
"openai_api_version = \"2024-02-01\"\n",
"openai_model_name = \"gpt-4o-mini\"\n",
"openai_model_version = \"2024-07-18\"\n",
"openai_model_sku = \"GlobalStandard\"\n",
"openai_deployment_name = \"gpt-4o-mini\"\n",
"openai_api_version = \"2024-10-21\"\n",
"\n",
"utils.print_ok('Notebook initialized')"
]
Expand Down Expand Up @@ -142,6 +130,7 @@
" \"openAIDeploymentName\": { \"value\": openai_deployment_name },\n",
" \"openAIModelName\": { \"value\": openai_model_name },\n",
" \"openAIModelVersion\": { \"value\": openai_model_version },\n",
" \"openAIModelSKU\": { \"value\": openai_model_sku },\n",
" \"openAIAPIVersion\": { \"value\": openai_api_version }\n",
" }\n",
"}\n",
Expand Down Expand Up @@ -341,7 +330,8 @@
"table = output.json_data['tables'][0]\n",
"df = pd.DataFrame(table.get(\"rows\"), columns = [col.get(\"name\") for col in table.get('columns')])\n",
"df['timestamp'] = pd.to_datetime(df['timestamp']).dt.strftime('%H:%M')\n",
"df"
"\n",
"df\n"
]
},
{
Expand All @@ -363,12 +353,14 @@
"import matplotlib as mpl\n",
"\n",
"mpl.rcParams['figure.figsize'] = [15, 7]\n",
"ax = df.plot(kind = 'line', x = 'timestamp', y = 'value', legend = False)\n",
"plt.title('Total token usage over time')\n",
"plt.xlabel('Time')\n",
"plt.ylabel('Tokens')\n",
"\n",
"plt.show()"
"if df.empty:\n",
" print(\"No data to plot\")\n",
"else:\n",
" ax = df.plot(kind = 'line', x = 'timestamp', y = 'value', legend = False)\n",
" plt.title('Total token usage over time')\n",
" plt.xlabel('Time')\n",
" plt.ylabel('Tokens')\n",
" plt.show()"
]
},
{
Expand Down Expand Up @@ -397,7 +389,7 @@
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -411,7 +403,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.8"
"version": "3.12.9"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 65137e8

Please sign in to comment.