Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
Uyarı
AnlamSal Çekirdek İşlem Çerçevesi deneyseldir, hala geliştirme aşamasındadır ve değiştirilebilir.
Genel bakış
Önceki bölümlerde, yeni ürünümüz için belge oluşturmayı otomatikleştirmemize yardımcı olacak bir süreç oluşturacağız. Sürecimiz artık ürünümüze özgü belgeler oluşturabilir ve düzeltme ve düzenleme süreci yoluyla kalite standartlarımızı karşıladığından emin olabilir. Bu bölümde, bir insanın yayımlanmadan önce belgeleri onaylamasını veya reddetmesini zorunlu kılarak bu süreci yeniden geliştireceğiz. İşlem çerçevesinin esnekliği, bunu yapmak için kullanabileceğimiz çeşitli yollar olduğu anlamına gelir, ancak bu örnekte onay istemek için bir dış pubsub sistemiyle tümleştirmeyi göstereceğiz.
İnsan müdahalesi içeren 
Yayımlamayı onay için bekletin
İşlemde yapmamız gereken ilk değişiklik, yayımlama adımının belgeleri yayımlamadan önce onayı beklemesini sağlamaktır. Seçeneklerden biri, PublishDocumentationiçindeki PublishDocumentationStep işlevine onay için ikinci bir parametre eklemektir. Bu, bir adımdaki KernelFunction işlevinin yalnızca gerekli tüm parametreleri sağlandığında çağrılacağı için çalışır.
// A process step to publish documentation
public class PublishDocumentationStep : KernelProcessStep
{
[KernelFunction]
public DocumentInfo PublishDocumentation(DocumentInfo document, bool userApproval) // added the userApproval parameter
{
// Only publish the documentation if it has been approved
if (userApproval)
{
// For example purposes we just write the generated docs to the console
Console.WriteLine($"[{nameof(PublishDocumentationStep)}]:\tPublishing product documentation approved by user: \n{document.Title}\n{document.Content}");
}
return document;
}
}
İnsan müdahaleli Python süreç davranış desteği yakında sunulacaktır.
Yukarıdaki kodla, PublishDocumentationPublishDocumentationStep işlevi yalnızca oluşturulan belgeler document parametresine gönderildiğinde ve onay sonucu userApproval parametresine gönderildiğinde çağrılır.
Artık ProofreadStep adımının mevcut mantığını yeniden kullanarak dış pubsub sistemimize yeni bir istek olduğunu insan onaylayıcısına bildirecek bir olay yayabiliriz.
// A process step to publish documentation
public class ProofReadDocumentationStep : KernelProcessStep
{
...
if (formattedResponse.MeetsExpectations)
{
// Events that are getting piped to steps that will be resumed, like PublishDocumentationStep.OnPublishDocumentation
// require events to be marked as public so they are persisted and restored correctly
await context.EmitEventAsync("DocumentationApproved", data: document, visibility: KernelProcessEventVisibility.Public);
}
...
}
Yeni oluşturulan belgeleri yazım denetleme aracısı tarafından onaylandığında yayımlamak istediğimizden, onaylanan belgeler yayımlama adımında kuyruğa alınır. Ayrıca, bir kişi, harici pubsub sistemimiz aracılığıyla en son belgeyle ilgili bir güncellemeyle bilgilendirilecektir. Şimdi süreç akışını bu yeni tasarımla eşleşecek şekilde güncelleştirelim.
İnsan müdahaleli Python süreç davranış desteği yakında sunulacaktır.
// Create the process builder
ProcessBuilder processBuilder = new("DocumentationGeneration");
// Add the steps
var infoGatheringStep = processBuilder.AddStepFromType<GatherProductInfoStep>();
var docsGenerationStep = processBuilder.AddStepFromType<GenerateDocumentationStepV2>();
var docsProofreadStep = processBuilder.AddStepFromType<ProofreadStep>();
var docsPublishStep = processBuilder.AddStepFromType<PublishDocumentationStep>();
// internal component that allows emitting SK events externally, a list of topic names
// is needed to link them to existing SK events
var proxyStep = processBuilder.AddProxyStep(["RequestUserReview", "PublishDocumentation"]);
// Orchestrate the events
processBuilder
.OnInputEvent("StartDocumentGeneration")
.SendEventTo(new(infoGatheringStep));
processBuilder
.OnInputEvent("UserRejectedDocument")
.SendEventTo(new(docsGenerationStep, functionName: "ApplySuggestions"));
// When external human approval event comes in, route it to the 'isApproved' parameter of the docsPublishStep
processBuilder
.OnInputEvent("UserApprovedDocument")
.SendEventTo(new(docsPublishStep, parameterName: "userApproval"));
// Hooking up the rest of the process steps
infoGatheringStep
.OnFunctionResult()
.SendEventTo(new(docsGenerationStep, functionName: "GenerateDocumentation"));
docsGenerationStep
.OnEvent("DocumentationGenerated")
.SendEventTo(new(docsProofreadStep));
docsProofreadStep
.OnEvent("DocumentationRejected")
.SendEventTo(new(docsGenerationStep, functionName: "ApplySuggestions"));
// When the proofreader approves the documentation, send it to the 'document' parameter of the docsPublishStep
// Additionally, the generated document is emitted externally for user approval using the pre-configured proxyStep
docsProofreadStep
.OnEvent("DocumentationApproved")
// [NEW] addition to emit messages externally
.EmitExternalEvent(proxyStep, "RequestUserReview") // Hooking up existing "DocumentationApproved" to external topic "RequestUserReview"
.SendEventTo(new(docsPublishStep, parameterName: "document"));
// When event is approved by user, it gets published externally too
docsPublishStep
.OnFunctionResult()
// [NEW] addition to emit messages externally
.EmitExternalEvent(proxyStep, "PublishDocumentation");
var process = processBuilder.Build();
return process;
Son olarak, yeni IExternalKernelProcessMessageChannel tarafından dahili olarak kullanıldığından dolayı ProxyStep arabirimi için bir uygulama sağlanmalıdır. Bu arabirim, iletileri harici olarak yaymak için kullanılır. Bu arabirimin uygulanması, kullandığınız dış sisteme bağlıdır. Bu örnekte, bir dış pubsub sistemine ileti göndermek için oluşturduğumuz özel bir istemciyi kullanacağız.
// Example of potential custom IExternalKernelProcessMessageChannel implementation
public class MyCloudEventClient : IExternalKernelProcessMessageChannel
{
private MyCustomClient? _customClient;
// Example of an implementation for the process
public async Task EmitExternalEventAsync(string externalTopicEvent, KernelProcessProxyMessage message)
{
// logic used for emitting messages externally.
// Since all topics are received here potentially
// some if else/switch logic is needed to map correctly topics with external APIs/endpoints.
if (this._customClient != null)
{
switch (externalTopicEvent)
{
case "RequestUserReview":
var requestDocument = message.EventData.ToObject() as DocumentInfo;
// As an example only invoking a sample of a custom client with a different endpoint/api route
this._customClient.InvokeAsync("REQUEST_USER_REVIEW", requestDocument);
return;
case "PublishDocumentation":
var publishedDocument = message.EventData.ToObject() as DocumentInfo;
// As an example only invoking a sample of a custom client with a different endpoint/api route
this._customClient.InvokeAsync("PUBLISH_DOC_EXTERNALLY", publishedDocument);
return;
}
}
}
public async ValueTask Initialize()
{
// logic needed to initialize proxy step, can be used to initialize custom client
this._customClient = new MyCustomClient("http://localhost:8080");
this._customClient.Initialize();
}
public async ValueTask Uninitialize()
{
// Cleanup to be executed when proxy step is uninitialized
if (this._customClient != null)
{
await this._customClient.ShutdownAsync();
}
}
}
Son olarak, işlemin ProxyStep uygulamayı IExternalKernelProcessMessageChannel kullanmasına izin vermek için, bu durumda MyCloudEventClient doğru bir şekilde yönlendirmemiz gerekir.
Yerel Çalışma Zamanı kullanılırken, StartAsync üzerinde KernelProcess sınıfını çağırdığınızda, uygulanan sınıf geçirilebilir.
KernelProcess process;
IExternalKernelProcessMessageChannel myExternalMessageChannel = new MyCloudEventClient();
// Start the process with the external message channel
await process.StartAsync(kernel, new KernelProcessEvent
{
Id = inputEvent,
Data = input,
},
myExternalMessageChannel)
Dapr Runtime kullanılırken, tesisatın projenin Program kurulumunda bağımlılık ekleme yoluyla yapılması gerekir.
var builder = WebApplication.CreateBuilder(args);
...
// depending on the application a singleton or scoped service can be used
// Injecting SK Process custom client IExternalKernelProcessMessageChannel implementation
builder.Services.AddSingleton<IExternalKernelProcessMessageChannel, MyCloudEventClient>();
İnsan müdahaleli Python süreç davranış desteği yakında sunulacaktır.
İşlem akışında iki değişiklik yapıldı:
-
HumanApprovalResponseadımınınuserApprovalparametresine yönlendirilecekdocsPublishStepadlı bir giriş olayı eklendi. -
docsPublishStep'daki KernelFunction artık iki parametreye sahip olduğundan,documentparametre adını belirtmek için mevcut yolu güncelleştirmemiz gerekir.
İşlemi daha önce yaptığınız gibi çalıştırın ve bu kez yazım denetleyicisi oluşturulan belgeleri onaylayıp document adımının docPublishStep parametresine gönderdiğinde, adımın artık çağrılmadığını çünkü userApproval parametresini beklediğini fark edin. Bu noktada, işlemi başlatmak için yaptığımız çağrı geri döner çünkü çağrılmaya hazır bir adım yoktur ve bu nedenle işlem boşta kalır. "Süreç, insan müdahalesiyle yayımlama isteğinin onaylanması veya reddedilmesi için harekete geçene kadar bu boşta durumda kalacaktır." Bu gerçekleştikten ve sonuç programımıza geri iletildikten sonra, sonuçla işlemi yeniden başlatabiliriz.
// Restart the process with approval for publishing the documentation.
await process.StartAsync(kernel, new KernelProcessEvent { Id = "UserApprovedDocument", Data = true });
İnsan müdahaleli Python süreç davranış desteği yakında sunulacaktır.
İşlem UserApprovedDocument ile yeniden başlatıldığında, kaldığı yerden devam eder, docsPublishStepuserApproval olarak ayarlanmış şekilde true'i çağırır ve belgelerimiz yayımlanır. Eğer UserRejectedDocument olayıyla yeniden başlatılırsa, işlem ApplySuggestions adımında docsGenerationStep fonksiyonunu tetikleyecek ve işlem daha önce olduğu gibi devam edecektir.
İşlem tamamlandı ve sürecimize döngü içinde insan adımını başarıyla ekledik. İşlem artık ürünümüz için belgeler oluşturmak, yazım denetlemesi yapmak ve bir insan tarafından onaylandıktan sonra yayımlamak için kullanılabilir.