Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>BasicChat_06OpenAIAPIs</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>82dba96a-152d-496e-8762-c2e93f97059c</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI" Version="9.7.1" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.7.1-preview.1.25365.4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.7" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.7" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.7" />
<PackageReference Include="OpenAI" Version="2.2.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
using System.Text;

var openai_apikey = Environment.GetEnvironmentVariable("APIKEY");
if (string.IsNullOrEmpty(openai_apikey))
{
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
openai_apikey = config["APIKEY"];
}

IChatClient client =
new OpenAI.Chat.ChatClient("gpt-4.1-mini", openai_apikey)
.AsIChatClient();

// here we're building the prompt
StringBuilder prompt = new StringBuilder();
prompt.AppendLine("You will analyze the sentiment of the following product reviews. Each line is its own review. Output the sentiment of each review in a bulleted list and then provide a general sentiment of all reviews. ");
prompt.AppendLine("I bought this product and it's amazing. I love it!");
prompt.AppendLine("This product is terrible. I hate it.");
prompt.AppendLine("I'm not sure about this product. It's okay.");
prompt.AppendLine("I found this product based on the other reviews. It worked for a bit, and then it didn't.");

// send the prompt to the model and wait for the text completion
var response = await client.GetResponseAsync(prompt.ToString());

// display the response
Console.WriteLine(response.Text);
19 changes: 17 additions & 2 deletions 03-CoreGenerativeAITechniques/src/CoreGenerativeAITechniques.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35514.174
# Visual Studio Version 18
VisualStudioVersion = 18.0.10829.221 main
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicChat-01MEAI", "BasicChat-01MEAI\BasicChat-01MEAI.csproj", "{F924B9FC-D806-4350-BEC8-C0D4BB9E7C6D}"
EndProject
Expand Down Expand Up @@ -105,6 +105,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MCP-01-HuggingFace", "MCP-0
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MCP-02-HuggingFace-Ollama", "MCP-02-HuggingFace-Ollama\MCP-02-HuggingFace-Ollama.csproj", "{CB155DBA-0E2D-437D-AB29-FF5B65B44A27}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicChat-06OpenAIAPIs", "BasicChat-06OpenAIAPIs\BasicChat-06OpenAIAPIs.csproj", "{48371925-76C4-40BD-A6F4-95E983771191}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -559,6 +561,18 @@ Global
{CB155DBA-0E2D-437D-AB29-FF5B65B44A27}.Release|x64.Build.0 = Release|Any CPU
{CB155DBA-0E2D-437D-AB29-FF5B65B44A27}.Release|x86.ActiveCfg = Release|Any CPU
{CB155DBA-0E2D-437D-AB29-FF5B65B44A27}.Release|x86.Build.0 = Release|Any CPU
{48371925-76C4-40BD-A6F4-95E983771191}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48371925-76C4-40BD-A6F4-95E983771191}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48371925-76C4-40BD-A6F4-95E983771191}.Debug|x64.ActiveCfg = Debug|Any CPU
{48371925-76C4-40BD-A6F4-95E983771191}.Debug|x64.Build.0 = Debug|Any CPU
{48371925-76C4-40BD-A6F4-95E983771191}.Debug|x86.ActiveCfg = Debug|Any CPU
{48371925-76C4-40BD-A6F4-95E983771191}.Debug|x86.Build.0 = Debug|Any CPU
{48371925-76C4-40BD-A6F4-95E983771191}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48371925-76C4-40BD-A6F4-95E983771191}.Release|Any CPU.Build.0 = Release|Any CPU
{48371925-76C4-40BD-A6F4-95E983771191}.Release|x64.ActiveCfg = Release|Any CPU
{48371925-76C4-40BD-A6F4-95E983771191}.Release|x64.Build.0 = Release|Any CPU
{48371925-76C4-40BD-A6F4-95E983771191}.Release|x86.ActiveCfg = Release|Any CPU
{48371925-76C4-40BD-A6F4-95E983771191}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -601,6 +615,7 @@ Global
{07F43AC9-EBB1-4F21-BC51-6DAD0F2F0E55} = {1248F5FA-C7D6-4876-8313-A15A942F84FE}
{769320A2-CE09-41EF-A345-8BE6ABBE2696} = {3D13EC01-716A-41D9-BC54-1871EC14D3DE}
{CB155DBA-0E2D-437D-AB29-FF5B65B44A27} = {3D13EC01-716A-41D9-BC54-1871EC14D3DE}
{48371925-76C4-40BD-A6F4-95E983771191} = {1248F5FA-C7D6-4876-8313-A15A942F84FE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {961EEBAB-4149-4AA4-BEE7-9DAAE4C94133}
Expand Down
Loading