How to build an OpenAI Connector prompt from an array

I am trying to build the prompt for an OpenAI query from an array in Camunda 8 SaaS. The array is built with information from a Camunda form via a repeating text field dynamically as follows:

[
  {
    "city": "Berlin"
    "distance": "100km",
  },
  {
    "city": "London",
    "distance": "1000km",
  },
  {
    "city": "San Francisco",
    "distance": "8000km",
  }
]

I would like to build the following text prompt for the OpenAI Connector prompt field:

If I am 100km away from Berlin, 1000km away from London and 8000km away from San Francisco, where am I?

Note: the input array can be of length 1..n as the user can choose how many cities to define in the form, and the prompt field accepts either plain text or a FEEL expression.

Is there a way to use a for loop to stich such text together? An alternative solution could be to dump the array to json and provide the json text to chatGPT?

Is there any native Camunda 8 SaaS way to achieve this?

Hey @macolo, assumung this is your input:

{"cities": [
  {
    "city": "Berlin",
    "distance": "100km"
  },
  {
    "city": "London",
    "distance": "1000km"
  },
  {
    "city": "San Francisco",
    "distance": "8000km"
  }
]}

You can concatenate the prompt like this using FEEL:

"If I am " + string join(for city in cities
return string(city.distance) + " away from " + city.city, ", ") + " where am I?"

You can try it out here:

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.