Skip to content

Commit a43b886

Browse files
authored
Merge pull request #136 from microsoft/bruno-fix-issue-135
Add MEAIFunctionsAzureOpenAI project and functionality
2 parents 1145f05 + f84cdf1 commit a43b886

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

03-CoreGenerativeAITechniques/src/CoreGenerativeAITechniques.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DockerModels-01-Chat", "Doc
7575
EndProject
7676
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DockerModels-02-MEAI-Chat", "DockerModels-02-MEAI-Chat\DockerModels-02-MEAI-Chat.csproj", "{73644053-4698-A9AF-9C25-380A6D70517E}"
7777
EndProject
78+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MEAIFunctionsAzureOpenAI", "MEAIFunctionsAzureOpenAI\MEAIFunctionsAzureOpenAI.csproj", "{5D39F3CE-CA22-4DD2-BED0-DEA510245AE9}"
79+
EndProject
7880
Global
7981
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8082
Debug|Any CPU = Debug|Any CPU
@@ -409,6 +411,18 @@ Global
409411
{73644053-4698-A9AF-9C25-380A6D70517E}.Release|x64.Build.0 = Release|Any CPU
410412
{73644053-4698-A9AF-9C25-380A6D70517E}.Release|x86.ActiveCfg = Release|Any CPU
411413
{73644053-4698-A9AF-9C25-380A6D70517E}.Release|x86.Build.0 = Release|Any CPU
414+
{5D39F3CE-CA22-4DD2-BED0-DEA510245AE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
415+
{5D39F3CE-CA22-4DD2-BED0-DEA510245AE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
416+
{5D39F3CE-CA22-4DD2-BED0-DEA510245AE9}.Debug|x64.ActiveCfg = Debug|Any CPU
417+
{5D39F3CE-CA22-4DD2-BED0-DEA510245AE9}.Debug|x64.Build.0 = Debug|Any CPU
418+
{5D39F3CE-CA22-4DD2-BED0-DEA510245AE9}.Debug|x86.ActiveCfg = Debug|Any CPU
419+
{5D39F3CE-CA22-4DD2-BED0-DEA510245AE9}.Debug|x86.Build.0 = Debug|Any CPU
420+
{5D39F3CE-CA22-4DD2-BED0-DEA510245AE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
421+
{5D39F3CE-CA22-4DD2-BED0-DEA510245AE9}.Release|Any CPU.Build.0 = Release|Any CPU
422+
{5D39F3CE-CA22-4DD2-BED0-DEA510245AE9}.Release|x64.ActiveCfg = Release|Any CPU
423+
{5D39F3CE-CA22-4DD2-BED0-DEA510245AE9}.Release|x64.Build.0 = Release|Any CPU
424+
{5D39F3CE-CA22-4DD2-BED0-DEA510245AE9}.Release|x86.ActiveCfg = Release|Any CPU
425+
{5D39F3CE-CA22-4DD2-BED0-DEA510245AE9}.Release|x86.Build.0 = Release|Any CPU
412426
EndGlobalSection
413427
GlobalSection(SolutionProperties) = preSolution
414428
HideSolutionNode = FALSE
@@ -441,6 +455,7 @@ Global
441455
{5173D88E-9325-126E-8B69-7BD1C8D5702E} = {E1AC4045-355A-4A18-8DD2-14FA8695C007}
442456
{587E5613-8A8A-281C-8D73-97CD71D2358F} = {DB695299-EBB6-430A-BAE3-FFB4A592EA92}
443457
{73644053-4698-A9AF-9C25-380A6D70517E} = {DB695299-EBB6-430A-BAE3-FFB4A592EA92}
458+
{5D39F3CE-CA22-4DD2-BED0-DEA510245AE9} = {F5798C6F-98D6-4411-A5F0-F928CBA64095}
444459
EndGlobalSection
445460
GlobalSection(ExtensibilityGlobals) = postSolution
446461
SolutionGuid = {961EEBAB-4149-4AA4-BEE7-9DAAE4C94133}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<UserSecretsId>4d370f85-d104-4a7c-ba38-0eb292b92116</UserSecretsId>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
13+
<PackageReference Include="Azure.Identity" Version="1.13.2" />
14+
<PackageReference Include="Microsoft.Extensions.AI" Version="9.4.3-preview.1.25230.7" />
15+
<PackageReference Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.4.3-preview.1.25230.7" />
16+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.4.3-preview.1.25230.7" />
17+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Azure.AI.OpenAI;
2+
using Microsoft.Extensions.AI;
3+
using Microsoft.Extensions.Configuration;
4+
using System.ClientModel;
5+
using System.ComponentModel;
6+
7+
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
8+
9+
var endpoint = config["endpoint"];
10+
var apiKey = new ApiKeyCredential(config["apikey"]);
11+
var deploymentName = "gpt-4.1-mini";
12+
13+
IChatClient client = new AzureOpenAIClient(new Uri(endpoint), apiKey)
14+
.GetChatClient(deploymentName)
15+
.AsIChatClient()
16+
.AsBuilder()
17+
.UseFunctionInvocation()
18+
.Build();
19+
20+
[Description("Get the weather")]
21+
static string GetWeather()
22+
{
23+
var temperature = Random.Shared.Next(5, 20);
24+
var condition = Random.Shared.Next(0, 1) == 0 ? "sunny" : "rainy";
25+
return $"The weather is {temperature} degree C and {condition}";
26+
}
27+
28+
var chatOptions = new ChatOptions
29+
{
30+
Tools = [AIFunctionFactory.Create(GetWeather)],
31+
ModelId = deploymentName
32+
};
33+
34+
client.AsBuilder()
35+
.UseFunctionInvocation()
36+
.Build();
37+
38+
var funcCallingResponseOne = await client.GetResponseAsync("What is today's date?", chatOptions);
39+
var funcCallingResponseTwo = await client.GetResponseAsync("Why don't you tell me about today's temperature?", chatOptions);
40+
var funcCallingResponseThree = await client.GetResponseAsync("Should I bring an umbrella with me today?", chatOptions);
41+
42+
Console.WriteLine($"Response 1: {funcCallingResponseOne}");
43+
Console.WriteLine($"Response 2: {funcCallingResponseTwo}");
44+
Console.WriteLine($"Response 3: {funcCallingResponseThree}");

0 commit comments

Comments
 (0)