webMethods.io: Transformation Service, part 2

webMethods.io: Transformation Service, part 2

We continue to build our transformation service for ChatGPT completion response. We can define service steps with the input and output documents in place.

Let's reiterate what are It's a good time to take a break and design transformation steps:

  1. We check if the incoming message contains ChatGPT completion responses and throw an error if it does not.
  2. For each completion message in the response list, complete the transformations:
    • Trim trailing and leading spaces;
    • Remove the outmost pair of quotes, single or double;
    • Trim extra spaces after that.
  1. Drop all service attributes and return only optimized reply strings.

Let's replicate this little algorithm as a flow service.

  1. Open your webMethods.io integration project, switch to the Flow services tab on the left, and select the service we saved before.
Click on the step activates drop down menu.
  1. Start typing "if.." to populate the drop-down menu with matching options. Select the second one, "If ... Else ...". Your new line transforms into the conditional flow.
New If ... Else steps.
  1. Click on the "Choose from options" drop-down and select "choices" from the list of all objects. Pick "not exists" from the second drop-down to test if the list of messages is in the income message. The context menu icon on the right brings up the advanced expression builder to help you with complex evaluations.
Test if Completion exists
  1. To finish execution, if the "choices" list does not exist, add the "Throw error ..." operator and put the error message to notify the caller that something has gone wrong.
  2. Every ChatGPT API call returns more than one completion to make announcements unique. To process all of them, click on step #4 and find the operation "Repeat."
  3. Keep it as "Repeat for each item in the list" and select "choices" from the drop-down.
  4. Step #5 is the innermost step in the loop and will be executed for each item in the completion response. Click on it and locate the "trim" function.
  5. Click the "View/Edit Pipeline" icon on the right to configure parameters.
Pipeline Configuration
  1. Expand the pipeline input on the right until you locate the "/choices/message/content" string.
  2. With the left mouse button, grab the "content" and drag it to the "inString" input parameter.
  3. Pull the output "value" to the same field on the left in the pipeline output.
"Show only mapped" simplifies the screen
  1. Let's save the service (the "floppy drive" icon in the main menu) and close the function pipeline ( the "✖️" icon in the right corner of the pipeline panel).
  2. Hover the mouse pointer over the loop line until a small blue ➕ icon appears. Click on it to add the new inner step.
  3. Find and select a function "replace." Save the service before we continue.
  4. Open the "replace" string pipeline configuration with the View/edit Pipeline icon on the right.
  5. Expand the pipeline input on the right until you locate the "/choices/message/content" string.
  6. Drag the "content" to the "inString" parameter and connect them.
  7. Map output "value" to the pipeline output "/choices/message/content."
  8. Set constants for the other parameters by right-clicking on the parameter name and choosing "Set value." Set parameters values as below:
  • searchString = ^['"](.*?)["']?
  • replaceString = $1
  • useRegex = true
  1. Expand pipeline output data structures to see all completion fields. Using the "Expand/Collapse" controls right under pipeline headers, you could expand and collapse all items at once.
  2. Select all pipeline output documents and attributes except the "/choices/message/content" and drop them from the pipeline output. To do so
    • Select a document or attribute and then use the drop filed ⤵︎ action.
    • Or, right-click on the element name and select the "Drop field."
Search, Replace, and Drop.
  1. Close the Replace pipeline and save your service.
  2. Right-click on step #5 and select "Duplicate" from the service context menu. You should have two identical function calls with all parameters in place.
  3. Right-click on the new line and select "Move step down." At this point, the repeat loop contains three pipelines.
  4. Select the "Exit" for step #8 by signaling "Success."
  5. Save your project progress.

I use three single-function pipelines instead of a single transform pipeline with three function calls because I need to apply those operations in a specific order. Separate service steps are numbered, and the engine guarantees the execution order. On the contrary, the transform pipeline steps are unordered, and the service engine will eventually do its best to execute them all.


Previous posts in the Flow service series: