Skip to content

Commit fee931d

Browse files
authored
Update azure-functions-samples.md
Fixed up code blocks
1 parent a763d12 commit fee931d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

articles/ai-services/agents/how-to/tools/azure-functions-samples.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ For any issues with the TypeScript code, create an issue on the [sample code rep
308308
### Prerequisites
309309
To make a function call we need to create and deploy the Azure function. In the code snippet below, we have an example of function on C# which can be used by the code above.
310310

311-
```csharp
311+
```csharp
312312
namespace FunctionProj
313313
{
314314
public class Response
@@ -356,29 +356,29 @@ To make a function call we need to create and deploy the Azure function. In the
356356
}
357357
}
358358
}
359-
```
359+
```
360360

361361
In this code we define function input and output class: `Arguments` and `Response` respectively. These two data classes will be serialized in JSON. It is important that these both contain field `CorrelationId`, which is the same between input and output.
362362

363363
In our example the function will be stored in the storage account, created with the AI hub. For that we need to allow key access to that storage. In Azure portal go to Storage account > Settings > Configuration and set "Allow storage account key access" to Enabled. If it is not done, the error will be displayed "The remote server returned an error: (403) Forbidden." To create the function resource that will host our function, install azure-cli python package and run the next command:
364364

365-
```shell
365+
```shell
366366
pip install -U azure-cli
367367
az login
368368
az functionapp create --resource-group your-resource-group --consumption-plan-location region --runtime dotnet-isolated --functions-version 4 --name function_name --storage-account storage_account_already_present_in_resource_group --app-insights existing_or_new_application_insights_name
369-
```
369+
```
370370

371371
This function writes data to the output queue and hence needs to be authenticated to Azure, so we will need to assign the function system identity and provide it `Storage Queue Data Contributor`. To do that in Azure portal select the function, located in `your-resource-group` resource group and in Settings>Identity, switch it on and click Save. After that assign the `Storage Queue Data Contributor` permission on storage account used by our function (storage_account_already_present_in_resource_group in the script above) for just assigned System Managed identity.
372372

373373
Now we will create the function itself. Install [.NET](https://dotnet.microsoft.com/download) and [Core Tools](https://go.microsoft.com/fwlink/?linkid=2174087) and create the function project using next commands.
374374

375-
```console
375+
```console
376376
func init FunctionProj --worker-runtime dotnet-isolated --target-framework net8.0
377377
cd FunctionProj
378378
func new --name foo --template "HTTP trigger" --authlevel "anonymous"
379379
dotnet add package Azure.Identity
380380
dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues --prerelease
381-
```
381+
```
382382

383383
**Note:** There is a "Azure Queue Storage trigger", however the attempt to use it results in error for now.
384384
We have created a project, containing HTTP-triggered azure function with the logic in `Foo.cs` file. As far as we need to trigger Azure function by a new message in the queue, we will replace the content of a Foo.cs by the C# sample code above.
@@ -390,21 +390,21 @@ To deploy the function run the command from dotnet project folder:
390390

391391
In the `storage_account_already_present_in_resource_group` select the `Queue service` and create two queues: `azure-function-foo-input` and `azure-function-tool-output`. Note that the same queues are used in our sample. To check that the function is working, place the next message into the `azure-function-foo-input` and replace `storage_account_already_present_in_resource_group` by the actual resource group name, or just copy the output queue address.
392392

393-
```json
393+
```json
394394
{
395395
"OutputQueueUri": "https://storage_account_already_present_in_resource_group.queue.core.windows.net/azure-function-tool-output",
396396
"CorrelationId": "42"
397397
}
398-
```
398+
```
399399

400400
Next, we will monitor the output queue or the message. You should receive the next message.
401401

402-
```json
402+
```json
403403
{
404404
"Value": "Bar",
405405
"CorrelationId": "42"
406406
}
407-
```
407+
```
408408
Please note that the input `CorrelationId` is the same as output.
409409
*Hint:* Place multiple messages to input queue and keep second internet browser window with the output queue open and hit the refresh button on the portal user interface, so that you will not miss the message. If the message instead went to `azure-function-foo-input-poison` queue, the function completed with error, please check your setup.
410410
After we have tested the function and made sure it works, please make sure that the Azure AI Project have the next roles for the storage account: `Storage Account Contributor`, `Storage Blob Data Contributor`, `Storage File Data Privileged Contributor`, `Storage Queue Data Contributor` and `Storage Table Data Contributor`. Now the function is ready to be used by the agent.

0 commit comments

Comments
 (0)