Skip to content

Commit

Permalink
Resolve merge from main
Browse files Browse the repository at this point in the history
  • Loading branch information
crickman committed Oct 16, 2024
2 parents d202b8d + 8b4a149 commit 170a1f8
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 65 deletions.
41 changes: 19 additions & 22 deletions .github/workflows/dotnet-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,42 +104,39 @@ jobs:
dotnet test -c ${{ matrix.configuration }} $project --no-build -v Normal --logger trx
done
env:
AzureOpenAI__Label: azure-text-davinci-003
AzureOpenAIEmbedding__Label: azure-text-embedding-ada-002
# Azure OpenAI Deployments
AzureOpenAI__Endpoint: ${{ secrets.AZUREOPENAI__ENDPOINT }}
AzureOpenAI__DeploymentName: ${{ vars.AZUREOPENAI__DEPLOYMENTNAME }}
AzureOpenAI__ChatDeploymentName: ${{ vars.AZUREOPENAI__CHATDEPLOYMENTNAME }}
AzureOpenAIEmbeddings__Endpoint: ${{ secrets.AZUREOPENAI__ENDPOINT }}
AzureOpenAIEmbeddings__DeploymentName: ${{ vars.AZUREOPENAIEMBEDDING__DEPLOYMENTNAME }}
AzureOpenAI__Endpoint: ${{ secrets.AZUREOPENAI__ENDPOINT }}
AzureOpenAIEmbeddings__Endpoint: ${{ secrets.AZUREOPENAI_EASTUS__ENDPOINT }}
AzureOpenAI__ApiKey: ${{ secrets.AZUREOPENAI__APIKEY }}
AzureOpenAIEmbeddings__ApiKey: ${{ secrets.AZUREOPENAI_EASTUS__APIKEY }}
Planners__AzureOpenAI__ApiKey: ${{ secrets.PLANNERS__AZUREOPENAI__APIKEY }}
AzureOpenAITextToAudio__Endpoint: ${{ secrets.AZUREOPENAITEXTTOAUDIO__ENDPOINT }}
AzureOpenAITextToAudio__DeploymentName: ${{ vars.AZUREOPENAITEXTTOAUDIO__DEPLOYMENTNAME }}
AzureOpenAIAudioToText__Endpoint: ${{ secrets.AZUREOPENAIAUDIOTOTEXT__ENDPOINT }}
AzureOpenAIAudioToText__DeploymentName: ${{ vars.AZUREOPENAIAUDIOTOTEXT__DEPLOYMENTNAME }}
AzureOpenAITextToImage__Endpoint: ${{ secrets.AZUREOPENAITEXTTOIMAGE__ENDPOINT }}
AzureOpenAITextToImage__DeploymentName: ${{ vars.AZUREOPENAITEXTTOIMAGE__DEPLOYMENTNAME }}
Planners__AzureOpenAI__Endpoint: ${{ secrets.PLANNERS__AZUREOPENAI__ENDPOINT }}
Planners__AzureOpenAI__DeploymentName: ${{ vars.PLANNERS__AZUREOPENAI__DEPLOYMENTNAME }}
Planners__OpenAI__ApiKey: ${{ secrets.PLANNERS__OPENAI__APIKEY }}
Planners__OpenAI__ModelId: ${{ vars.PLANNERS__OPENAI__MODELID }}
# OpenAI Models
OpenAI__ApiKey: ${{ secrets.OPENAI__APIKEY }}
OpenAI__ChatModelId: ${{ vars.OPENAI__CHATMODELID }}
OpenAIEmbeddings__ApiKey: ${{ secrets.OPENAIEMBEDDINGS__APIKEY }}
OpenAIEmbeddings__ModelId: ${{ vars.OPENAIEMBEDDINGS__MODELID }}
OpenAITextToAudio__ApiKey: ${{ secrets.OPENAITEXTTOAUDIO__APIKEY }}
OpenAITextToAudio__ModelId: ${{ vars.OPENAITEXTTOAUDIO__MODELID }}
OpenAIAudioToText__ApiKey: ${{ secrets.OPENAIAUDIOTOTEXT__APIKEY }}
OpenAIAudioToText__ModelId: ${{ vars.OPENAIAUDIOTOTEXT__MODELID }}
OpenAITextToImage__ApiKey: ${{ secrets.OPENAITEXTTOIMAGE__APIKEY }}
OpenAITextToImage__ModelId: ${{ vars.OPENAITEXTTOIMAGE__MODELID }}
OpenAIEmbeddings__ApiKey: ${{ secrets.OPENAIEMBEDDINGS__APIKEY }}
OpenAIEmbeddings__ModelId: ${{ vars.OPENAIEMBEDDINGS__MODELID }}
AzureOpenAITextToAudio__ApiKey: ${{ secrets.AZUREOPENAITEXTTOAUDIO__APIKEY }}
AzureOpenAITextToAudio__Endpoint: ${{ secrets.AZUREOPENAITEXTTOAUDIO__ENDPOINT }}
AzureOpenAITextToAudio__DeploymentName: ${{ vars.AZUREOPENAITEXTTOAUDIO__DEPLOYMENTNAME }}
AzureOpenAIAudioToText__ApiKey: ${{ secrets.AZUREOPENAIAUDIOTOTEXT__APIKEY }}
AzureOpenAIAudioToText__Endpoint: ${{ secrets.AZUREOPENAIAUDIOTOTEXT__ENDPOINT }}
AzureOpenAIAudioToText__DeploymentName: ${{ vars.AZUREOPENAIAUDIOTOTEXT__DEPLOYMENTNAME }}
AzureOpenAITextToImage__ApiKey: ${{ secrets.AZUREOPENAITEXTTOIMAGE__APIKEY }}
AzureOpenAITextToImage__Endpoint: ${{ secrets.AZUREOPENAITEXTTOIMAGE__ENDPOINT }}
AzureOpenAITextToImage__DeploymentName: ${{ vars.AZUREOPENAITEXTTOIMAGE__DEPLOYMENTNAME }}
Planners__OpenAI__ApiKey: ${{ secrets.PLANNERS__OPENAI__APIKEY }}
Planners__OpenAI__ModelId: ${{ vars.PLANNERS__OPENAI__MODELID }}
# Bing Web Search
Bing__ApiKey: ${{ secrets.BING__APIKEY }}
# Google Web Search
Google__SearchEngineId: ${{ secrets.GOOGLE__SEARCHENGINEID }}
Google__ApiKey: ${{ secrets.GOOGLE__APIKEY }}
OpenAI__ApiKey: ${{ secrets.OPENAI__APIKEY }}
OpenAI__ChatModelId: ${{ vars.OPENAI__CHATMODELID }}
# Azure AI Inference Endpoint
AzureAIInference__ApiKey: ${{ secrets.AZUREAIINFERENCE__APIKEY }}
AzureAIInference__Endpoint: ${{ secrets.AZUREAIINFERENCE__ENDPOINT }}

Expand Down
31 changes: 14 additions & 17 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"prettier.enable": true,
"css.lint.validProperties": [
"composes"
],
"css.lint.validProperties": ["composes"],
"editor.formatOnType": true,
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
Expand All @@ -15,13 +13,9 @@
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active",
"python.formatting.provider": "autopep8",
"python.formatting.autopep8Args": [
"--max-line-length=120"
],
"python.formatting.autopep8Args": ["--max-line-length=120"],
"notebook.output.textLineLimit": 500,
"python.analysis.extraPaths": [
"./python/src"
],
"python.analysis.extraPaths": ["./python/src"],
"javascript.updateImportsOnFileMove.enabled": "always",
"search.exclude": {
"**/node_modules": true,
Expand Down Expand Up @@ -71,31 +65,34 @@
"**/Thumbs.db": true
},
"cSpell.words": [
"Dapr",
"Partitioner",
"Pregel",
"Prompty",
"SKEXP"
"SKEXP",
"superstep",
"Supersteps",
"typeref"
],
"[java]": {
"editor.formatOnSave": false,
"editor.tabSize": 4,
"editor.codeActionsOnSave": {
"source.fixAll": "never"
},
}
},
"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\.java$",
"cmd": "java -Xmx128m -jar ${workspaceFolder}/java/utilities/google-java-format-1.17.0-all-deps.jar --replace --aosp ${file}"
},
],
}
]
},
"java.debug.settings.onBuildFailureProceed": true,
"java.compile.nullAnalysis.mode": "disabled",
"dotnet.defaultSolution": "dotnet\\SK-dotnet.sln",
"python.testing.pytestArgs": [
"python/tests"
],
"python.testing.pytestArgs": ["python/tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public virtual void PopulateUserInputs(UserInputState state)
/// <returns>A <see cref="ValueTask"/></returns>
public override ValueTask ActivateAsync(KernelProcessStepState<UserInputState> state)
{
state.State ??= _state;
_state = state.State;

Check failure on line 47 in dotnet/samples/GettingStartedWithProcesses/SharedSteps/ScriptedUserInputStep.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, ubuntu-latest, Release, true, integration)

A readonly field cannot be assigned to (except in a constructor or init-only setter of the type in which the field is defined or a variable initializer)

Check failure on line 47 in dotnet/samples/GettingStartedWithProcesses/SharedSteps/ScriptedUserInputStep.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, ubuntu-latest, Release, true, integration)

A readonly field cannot be assigned to (except in a constructor or init-only setter of the type in which the field is defined or a variable initializer)

Check failure on line 47 in dotnet/samples/GettingStartedWithProcesses/SharedSteps/ScriptedUserInputStep.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Debug)

A readonly field cannot be assigned to (except in a constructor or init-only setter of the type in which the field is defined or a variable initializer)

Check failure on line 47 in dotnet/samples/GettingStartedWithProcesses/SharedSteps/ScriptedUserInputStep.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Debug)

A readonly field cannot be assigned to (except in a constructor or init-only setter of the type in which the field is defined or a variable initializer)

Check failure on line 47 in dotnet/samples/GettingStartedWithProcesses/SharedSteps/ScriptedUserInputStep.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Release)

A readonly field cannot be assigned to (except in a constructor or init-only setter of the type in which the field is defined or a variable initializer)

Check failure on line 47 in dotnet/samples/GettingStartedWithProcesses/SharedSteps/ScriptedUserInputStep.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Release)

A readonly field cannot be assigned to (except in a constructor or init-only setter of the type in which the field is defined or a variable initializer)

PopulateUserInputs(_state);
PopulateUserInputs(_state!);

return ValueTask.CompletedTask;
}
Expand Down
16 changes: 11 additions & 5 deletions dotnet/src/Experimental/Process.Abstractions/KernelProcessEdge.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Runtime.Serialization;

namespace Microsoft.SemanticKernel;

/// <summary>
/// A serializable representation of an edge between a source <see cref="KernelProcessStep"/> and a <see cref="KernelProcessFunctionTarget"/>.
/// </summary>
[DataContract]
[KnownType(typeof(KernelProcessFunctionTarget))]
public sealed class KernelProcessEdge
{
/// <summary>
/// The unique identifier of the source Step.
/// </summary>
public string SourceStepId { get; }
[DataMember]
public string SourceStepId { get; init; }

/// <summary>
/// The collection of <see cref="KernelProcessFunctionTarget"/>s that are the output of the source Step.
/// </summary>
public KernelProcessFunctionTarget OutputTarget { get; }
[DataMember]
public KernelProcessFunctionTarget OutputTarget { get; init; }

/// <summary>
/// Creates a new instance of the <see cref="KernelProcessEdge"/> class.
/// </summary>
public KernelProcessEdge(string sourceStepId, KernelProcessFunctionTarget outputTargets)
public KernelProcessEdge(string sourceStepId, KernelProcessFunctionTarget outputTarget)
{
Verify.NotNullOrWhiteSpace(sourceStepId);
Verify.NotNull(outputTargets);
Verify.NotNull(outputTarget);

this.SourceStepId = sourceStepId;
this.OutputTarget = outputTargets;
this.OutputTarget = outputTarget;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Runtime.Serialization;

namespace Microsoft.SemanticKernel;

/// <summary>
/// A serializable representation of a specific parameter of a specific function of a specific Step.
/// </summary>
[DataContract]
public record KernelProcessFunctionTarget
{
/// <summary>
Expand All @@ -24,20 +27,24 @@ public KernelProcessFunctionTarget(string stepId, string functionName, string? p
/// <summary>
/// The unique identifier of the Step being targeted.
/// </summary>
[DataMember]
public string StepId { get; init; }

/// <summary>
/// The name if the Kernel Function to target.
/// </summary>
[DataMember]
public string FunctionName { get; init; }

/// <summary>
/// The name of the parameter to target. This may be null if the function has no parameters.
/// </summary>
[DataMember]
public string? ParameterName { get; init; }

/// <summary>
/// The unique identifier for the event to target. This may be null if the target is not a sub-process.
/// </summary>
[DataMember]
public string? TargetEventId { get; init; }
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Runtime.Serialization;

namespace Microsoft.SemanticKernel;

/// <summary>
/// Represents the state of a process.
/// </summary>
[DataContract]
public sealed record KernelProcessState : KernelProcessStepState
{
/// <summary>
/// Initializes a new instance of the <see cref="KernelProcessStepState"/> class.
/// Initializes a new instance of the <see cref="KernelProcessState"/> class.
/// </summary>
/// <param name="name">The name of the associated <see cref="KernelProcessStep"/></param>
/// <param name="id">The Id of the associated <see cref="KernelProcessStep"/></param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@ public KernelProcessStepInfo(Type innerStepType, KernelProcessStepState state, D
this.InnerStepType = innerStepType;
this._outputEdges = edges;
this._state = state;

// Register the state as a know type for the DataContractSerialization used by Dapr.
KernelProcessState.RegisterDerivedType(state.GetType());
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,51 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Microsoft.SemanticKernel;

/// <summary>
/// Represents the state of an individual step in a process.
/// </summary>
[DataContract]
[KnownType(nameof(GetKnownTypes))]
public record KernelProcessStepState
{
/// <summary>
/// A set of known types that may be used in serialization.
/// </summary>
private readonly static HashSet<Type> s_knownTypes = [];

/// <summary>
/// Used to dynamically provide the set of known types for serialization.
/// </summary>
/// <returns></returns>
private static HashSet<Type> GetKnownTypes() => s_knownTypes;

/// <summary>
/// Registers a derived type for serialization. Types registered here are used by the KnownType attribute
/// to support DataContractSerialization of derived types as required to support Dapr.
/// </summary>
/// <param name="derivedType">A Type that derives from <typeref name="KernelProcessStepState"/></param>
internal static void RegisterDerivedType(Type derivedType)
{
s_knownTypes.Add(derivedType);
}

/// <summary>
/// The identifier of the Step which is required to be unique within an instance of a Process.
/// This may be null until a process containing this step has been invoked.
/// </summary>
[DataMember]
public string? Id { get; init; }

/// <summary>
/// The name of the Step. This is itended to be human readable and is not required to be unique. If
/// The name of the Step. This is intended to be human readable and is not required to be unique. If
/// not provided, the name will be derived from the steps .NET type.
/// </summary>
[DataMember]
public string Name { get; init; }

/// <summary>
Expand All @@ -37,12 +66,14 @@ public KernelProcessStepState(string name, string? id = null)
/// Represents the state of an individual step in a process that includes a user-defined state object.
/// </summary>
/// <typeparam name="TState">The type of the user-defined state.</typeparam>
[DataContract]
public sealed record KernelProcessStepState<TState> : KernelProcessStepState where TState : class, new()
{
/// <summary>
/// The user-defined state object associated with the Step.
/// </summary>
public TState? State { get; set; }
[DataMember]
public TState? State { get; init; }

/// <summary>
/// Initializes a new instance of the <see cref="KernelProcessStepState"/> class.
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/Experimental/Process.Core/Internal/EndStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.SemanticKernel;
/// </summary>
internal sealed class EndStep : ProcessStepBuilder
{
private const string EndStepValue = "END";
private const string EndStepValue = "Microsoft.SemanticKernel.Process.EndStep";

/// <summary>
/// The name of the end step.
Expand Down
16 changes: 16 additions & 0 deletions dotnet/src/Experimental/Process.Core/ProcessBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ public ProcessStepBuilder AddStepFromType<TStep>(string? name = null) where TSte
return stepBuilder;
}

/// <summary>
/// Adds a step to the process and define it's initial user-defined state.
/// </summary>
/// <typeparam name="TStep">The step Type.</typeparam>
/// <typeparam name="TState">The state Type.</typeparam>
/// <param name="initialState">The initial state of the step.</param>
/// <param name="name">The name of the step. This parameter is optional.</param>
/// <returns>An instance of <see cref="ProcessStepBuilder"/></returns>
public ProcessStepBuilder AddStepFromType<TStep, TState>(TState initialState, string? name = null) where TStep : KernelProcessStep<TState> where TState : class, new()
{
var stepBuilder = new ProcessStepBuilder<TStep>(name, initialState);
this._steps.Add(stepBuilder);

return stepBuilder;
}

/// <summary>
/// Adds a sub process to the process.
/// </summary>
Expand Down
17 changes: 16 additions & 1 deletion dotnet/src/Experimental/Process.Core/ProcessStepBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,21 @@ protected ProcessStepBuilder(string name)
/// </summary>
public sealed class ProcessStepBuilder<TStep> : ProcessStepBuilder where TStep : KernelProcessStep
{
/// <summary>
/// The initial state of the step. This may be null if the step does not have any state.
/// </summary>
private readonly object? _initialState;

/// <summary>
/// Creates a new instance of the <see cref="ProcessStepBuilder"/> class. If a name is not provided, the name will be derived from the type of the step.
/// </summary>
public ProcessStepBuilder(string? name = null)
/// <param name="name">Optional: The name of the step.</param>
/// <param name="initialState">Optional: The initial state of the step.</param>
internal ProcessStepBuilder(string? name = null, object? initialState = default)
: base(name ?? typeof(TStep).Name)
{
this.FunctionsDict = this.GetFunctionMetadataMap();
this._initialState = initialState;
}

/// <summary>
Expand All @@ -221,7 +229,14 @@ internal override KernelProcessStepInfo BuildStep()
var stateType = typeof(KernelProcessStepState<>).MakeGenericType(userStateType);
Verify.NotNull(stateType);

// If the step has a user-defined state then we need to validate that the initial state is of the correct type.
if (this._initialState is not null && this._initialState.GetType() != userStateType)
{
throw new KernelException($"The initial state provided for step {this.Name} is not of the correct type. The expected type is {userStateType.Name}.");
}

stateObject = (KernelProcessStepState?)Activator.CreateInstance(stateType, this.Name, this.Id);
stateType.GetProperty(nameof(KernelProcessStepState<object>.State))?.SetValue(stateObject, this._initialState);
}
else
{
Expand Down
Loading

0 comments on commit 170a1f8

Please sign in to comment.