This repository has been archived by the owner on Aug 21, 2023. It is now read-only.
forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move playfab examples to their own project
- Loading branch information
1 parent
d745cfb
commit ab6a71c
Showing
12 changed files
with
299 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
dotnet/samples/PlayFabExamples/Common/Configuration/ConfigurationNotFoundException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
namespace PlayFabExamples.Common.Configuration; | ||
public sealed class ConfigurationNotFoundException : Exception | ||
{ | ||
public string? Section { get; } | ||
public string? Key { get; } | ||
|
||
public ConfigurationNotFoundException(string section, string key) | ||
: base($"Configuration key '{section}:{key}' not found") | ||
{ | ||
this.Section = section; | ||
this.Key = key; | ||
} | ||
|
||
public ConfigurationNotFoundException(string section) | ||
: base($"Configuration section '{section}' not found") | ||
{ | ||
this.Section = section; | ||
} | ||
|
||
public ConfigurationNotFoundException() : base() | ||
{ | ||
} | ||
|
||
public ConfigurationNotFoundException(string? message, Exception? innerException) : base(message, innerException) | ||
{ | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
dotnet/samples/PlayFabExamples/Common/Configuration/Env.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace PlayFabExamples.Common.Configuration; | ||
|
||
#pragma warning disable CA1812 // instantiated by AddUserSecrets | ||
internal sealed class Env | ||
#pragma warning restore CA1812 | ||
{ | ||
/// <summary> | ||
/// Simple helper used to load env vars and secrets like credentials, | ||
/// to avoid hard coding them in the sample code | ||
/// </summary> | ||
/// <param name="name">Secret name / Env var name</param> | ||
/// <returns>Value found in Secret Manager or Environment Variable</returns> | ||
internal static string Var(string name) | ||
{ | ||
var configuration = new ConfigurationBuilder() | ||
.AddUserSecrets<Env>() | ||
.Build(); | ||
|
||
var value = configuration[name]; | ||
if (!string.IsNullOrEmpty(value)) | ||
{ | ||
return value; | ||
} | ||
|
||
value = Environment.GetEnvironmentVariable(name); | ||
if (string.IsNullOrEmpty(value)) | ||
{ | ||
throw new ConfigurationNotFoundException($"Secret / Env var not set: {name}"); | ||
} | ||
|
||
return value; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
dotnet/samples/PlayFabExamples/Common/Configuration/TestConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Runtime.CompilerServices; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace PlayFabExamples.Common.Configuration; | ||
public sealed class TestConfiguration | ||
{ | ||
private IConfigurationRoot _configRoot; | ||
private static TestConfiguration? s_instance; | ||
|
||
private TestConfiguration(IConfigurationRoot configRoot) | ||
{ | ||
this._configRoot = configRoot; | ||
} | ||
|
||
public static void Initialize(IConfigurationRoot configRoot) | ||
{ | ||
s_instance = new TestConfiguration(configRoot); | ||
} | ||
|
||
public static AzureOpenAIConfig AzureOpenAI => LoadSection<AzureOpenAIConfig>(); | ||
|
||
public static BingConfig Bing => LoadSection<BingConfig>(); | ||
public static PlayFabConfig PlayFab => LoadSection<PlayFabConfig>(); | ||
|
||
private static T LoadSection<T>([CallerMemberName] string? caller = null) | ||
{ | ||
if (s_instance == null) | ||
{ | ||
throw new InvalidOperationException( | ||
"TestConfiguration must be initialized with a call to Initialize(IConfigurationRoot) before accessing configuration values."); | ||
} | ||
|
||
if (string.IsNullOrEmpty(caller)) | ||
{ | ||
throw new ArgumentNullException(nameof(caller)); | ||
} | ||
return s_instance._configRoot.GetSection(caller).Get<T>() ?? | ||
throw new ConfigurationNotFoundException(section: caller); | ||
} | ||
|
||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. | ||
|
||
public class AzureOpenAIConfig | ||
{ | ||
public string ServiceId { get; set; } | ||
public string DeploymentName { get; set; } | ||
public string ChatDeploymentName { get; set; } | ||
public string Endpoint { get; set; } | ||
public string ApiKey { get; set; } | ||
} | ||
|
||
public class BingConfig | ||
{ | ||
public string ApiKey { get; set; } | ||
} | ||
|
||
public class PlayFabConfig | ||
{ | ||
public string Endpoint { get; set; } | ||
public string TitleId { get; set; } | ||
public string TitleSecretKey { get; set; } | ||
public string SwaggerEndpoint { get; set; } | ||
public string ReportsCosmosDBEndpoint { get; set; } | ||
public string ReportsCosmosDBKey { get; set; } | ||
public string ReportsCosmosDBDatabaseName { get; set; } | ||
public string ReportsCosmosDBContainerName { get; set; } | ||
} | ||
|
||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. | ||
} |
35 changes: 35 additions & 0 deletions
35
dotnet/samples/PlayFabExamples/Common/Logging/ConsoleLogger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
namespace PlayFabExamples.Common.Logging; | ||
/// <summary> | ||
/// Basic logger printing to console | ||
/// </summary> | ||
internal static class ConsoleLogger | ||
{ | ||
internal static ILogger Logger => LogFactory.CreateLogger<object>(); | ||
|
||
private static ILoggerFactory LogFactory => s_loggerFactory.Value; | ||
|
||
private static readonly Lazy<ILoggerFactory> s_loggerFactory = new(LogBuilder); | ||
|
||
private static ILoggerFactory LogBuilder() | ||
{ | ||
return LoggerFactory.Create(builder => | ||
{ | ||
builder.SetMinimumLevel(LogLevel.Warning); | ||
// builder.AddFilter("Microsoft", LogLevel.Trace); | ||
// builder.AddFilter("Microsoft", LogLevel.Debug); | ||
// builder.AddFilter("Microsoft", LogLevel.Information); | ||
// builder.AddFilter("Microsoft", LogLevel.Warning); | ||
// builder.AddFilter("Microsoft", LogLevel.Error); | ||
builder.AddFilter("Microsoft", LogLevel.Warning); | ||
builder.AddFilter("System", LogLevel.Warning); | ||
builder.AddConsole(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 4 additions & 7 deletions
11
...rnelSyntaxExamples/Skills/SegmentSkill.cs → ...ples/Example02_Generative/SegmentSkill.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
...ples/Example00_03_OpenApiSkill_PlayFab.cs → ...03_SegmentQuery/Example03_SegmentQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<LangVersion>11</LangVersion> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<UserSecretsId>4447f5a3-3bc4-4697-a289-b87c718828fc</UserSecretsId> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Azure.Identity" /> | ||
<PackageReference Include="Microsoft.Azure.Cosmos" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" /> | ||
<PackageReference Include="Microsoft.Extensions.Http" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" /> | ||
<PackageReference Include="Newtonsoft.Json" /> | ||
<PackageReference Include="Polly" /> | ||
<PackageReference Include="System.Linq.Async" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Connectors\Connectors.AI.OpenAI\Connectors.AI.OpenAI.csproj" /> | ||
<ProjectReference Include="..\..\src\Extensions\Planning.ActionPlanner\Planning.ActionPlanner.csproj" /> | ||
<ProjectReference Include="..\..\src\Extensions\Planning.SequentialPlanner\Planning.SequentialPlanner.csproj" /> | ||
<ProjectReference Include="..\..\src\Extensions\Planning.StepwisePlanner\Planning.StepwisePlanner.csproj" /> | ||
<ProjectReference Include="..\..\src\PF-Extensions\Planning.ChatStepwisePlanner\Planning.ChatStepwisePlanner.csproj" /> | ||
<ProjectReference Include="..\..\src\SemanticKernel.Abstractions\SemanticKernel.Abstractions.csproj" /> | ||
<ProjectReference Include="..\..\src\Skills\Skills.Core\Skills.Core.csproj" /> | ||
<ProjectReference Include="..\..\src\Skills\Skills.OpenAPI\Skills.OpenAPI.csproj" /> | ||
<ProjectReference Include="..\..\src\SemanticKernel\SemanticKernel.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.