Discover how to integrate the powerful capabilities of OpenAI’s .NET API into your WorkflowGen Form Designer (ASP.NET webforms) with this sample implementation.
By combining the flexibility of WorkflowGen’s process automation with the intelligence of OpenAI’s API, you can unlock a variety of innovative possibilities. For example, you can automate content generation, create intelligent form validation that adapts to user inputs, and provide contextual suggestions and completions directly within your forms, enhancing user experience.
This article walks you through the essential configurations and setup to help you seamlessly integrate OpenAI into your WorkflowGen-powered workflows.
Note: The example is for illustrative purposes only. It’s crucial to properly sanitize any user-provided input data before sending messages to the chat.
Getting started
References
- OpenAI NuGet Package: This link includes additional integration examples and detailed how-to guides for leveraging the OpenAI .NET API.
Prerequisites
- The API key from your OpenAI account.
Configuring the webforms IIS web app
-
Install the OpenAI NuGet package.
An easy way to do this is by opening your
/wfgen/wfapps/webforms
IIS web app in Visual Studio (inadministrator
mode) as a project and adding theOpenAI
package to the web app using the NuGet Package Manager.If you don’t have access to Visual Studio, you can install the package manually using NuGet CLI. To do this:
Step 1: Ensure NuGet CLI is Installed
- If you haven’t already, download
NuGet.exe
from the official NuGet downloads page. - Place
NuGet.exe
in a folder included in your system’sPATH
or use the full path to execute it.
Step 2: Create or update
packages.config
Manually create a
packages.config
file if your web application doesn’t already have apackages.config
file, in the root directory of your web app (\wfgen\wfapps\webforms
). The content of the file should look like this:<?xml version="1.0" encoding="utf-8"?> <packages> <package id="Microsoft.Bcl.AsyncInterfaces" version="6.0.0" targetFramework="net48" /> <package id="OpenAI" version="2.1.0" targetFramework="net48" /> <package id="System.Buffers" version="4.5.1" targetFramework="net48" /> <package id="System.ClientModel" version="1.2.1" targetFramework="net48" /> <package id="System.Diagnostics.DiagnosticSource" version="6.0.1" targetFramework="net48" /> <package id="System.Memory" version="4.5.4" targetFramework="net48" /> <package id="System.Memory.Data" version="6.0.0" targetFramework="net48" /> <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" /> <package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net48" /> <package id="System.Text.Encodings.Web" version="6.0.0" targetFramework="net48" /> <package id="System.Text.Json" version="6.0.10" targetFramework="net48" /> <package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" /> <package id="System.ValueTuple" version="4.5.0" targetFramework="net48" /> </packages>
Step 3: Restore the packages
Run the following command in the directory where
packages.config
is located (your web app root\wfgen\wfapps\webforms
):nuget restore packages.config -PackagesDirectory packages
Step 4: Copy DLLs to the
bin
folderAfter restoring the packages, manually copy the required
.dll
files from eachpackages
folder to your web app’sbin
folder:- Navigate to:
\wfgen\wfapps\webforms\packages\*\lib\netstandard2.0
or\wfgen\wfapps\webforms\packages\*\lib\net461
. - Copy the specific package
.dll
into\wfgen\wfapps\webforms\bin
.
You can use the following
PowerShell
commands to facilitate the file copy.- Update the
DRIVE:\inetpub\wwwroot\wfgen\wfapps\webforms
example path with your actual path. - Run both commands in this order (first for
netstandard2.0
thennet461
).
Get-ChildItem -Path "DRIVE:\inetpub\wwwroot\wfgen\wfapps\webforms\packages" -Recurse -Include "*.dll" | Where-Object { $_.FullName -like "*\lib\netstandard2.0\*" } | Copy-Item -Destination "DRIVE:\inetpub\wwwroot\wfgen\wfapps\webforms\bin" -Force
Get-ChildItem -Path "DRIVE:\inetpub\wwwroot\wfgen\wfapps\webforms\packages" -Recurse -Include "*.dll" | Where-Object { $_.FullName -like "*\lib\net461\*" } | Copy-Item -Destination "DRIVE:\inetpub\wwwroot\wfgen\wfapps\webforms\bin" -Force
- If you haven’t already, download
-
Add or update the
\wfgen\wfapps\webforms\web.config
file to target.NET Framework 4.8
and reference all the packages and dependencies (includingnetstandard 2.0
) if this isn’t already the case. The content of the file should look like this:<?xml version="1.0"?> <configuration> <system.web> <compilation debug="false" targetFramework="4.8"> <assemblies> <add assembly="System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=CC7B13FFCD2DDD51"/> </assemblies> </compilation> <httpRuntime targetFramework="4.8"/> </system.web> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-6.0.0.10" newVersion="6.0.0.10"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-6.0.0.1" newVersion="6.0.0.1"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
Sample process configuration in WorkflowGen
-
Import the OPENAI_DOTNET_API_CHATv1.xml sample process XPDL into WorkflowGen.
-
Set your OpenAI API key in the form code-behind. To do this:
- Open the process and go to the Form tab.
- Switch to the ASP.NET code-behind editor.
- Replace the text
OPENAI_API_KEY
with your OpenAI API key. - Save the form.
protected void CHAT_SEND_Click(object sender, EventArgs e) { OpenAI.Chat.ChatClient client = new OpenAI.Chat.ChatClient("gpt-4o", "OPENAI_API_KEY"); OpenAI.Chat.ChatCompletion completion = client.CompleteChat(CHAT_MESSAGE.Text); CHAT_RESPONSE.Text = "[ASSISTANT]: " + completion.Content[0].Text; }
-
You should now be ready to launch a new request and start sending chat messages to OpenAI within your webform.