Problem/Motivation

The current ECA ChatGPT promot plugin takes only one token input. However, a prompt can and will likely include multiple tokens sometimes.

Steps to reproduce

- When the "OpenAI ChatGPT ECA" is installed and configured, add a new ECA task for OpenAI/ChatGPT Chat.
- "Token input" under "Custom properties" takes only one token. If you try to input multiple tokens (i.e., comma-separated), it saves, but the task errors when token replacement is triggered in the prompt.

Proposed resolution

- Add possibility to accept multiple "Token input" in comma-separated format
- Add capability to replace multiple tokens in the prompt

Remaining tasks

- Patch / Merge request in Chat.php
- Perhaps apply this to other plugins/tasks
- Change UI labels or descriptions to indicate the possibility of entering multiple tokens in comma-separated format
- Add OpenAI ECA to the issue tracker (to be able to log such issues to that component)

User interface changes

- Naming with descriptions to guide users with the ability to input multiple tokens in comma-separated format

API changes

None.

Data model changes

None.

Issue fork openai-3413325

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Mohammed J. Razem created an issue. See original summary.

mohammed j. razem’s picture

Status: Active » Needs review
mohammed j. razem’s picture

Issue summary: View changes
kevinquillen’s picture

Does this really need to change or can this be facilitated with other Actions? I tried to keep it minimal so this slotted in to ECA as chainable workflows.

From Jurgen:

You can use the https://ecaguide.org/plugins/eca/base/actions/eca_token_set_value/ action and concatenate tokens in the Value of the token field, e.g. The combined value of user [user:id] is now [node:title] from [user:name], so the new token now has that string with multiple tokens being resolved there. Of course, that way you can also just concatenate token values without any other fixed strings in-between. Is it that what you were looking for?

jurgenhaas’s picture

Well, it depends upon the field definition in the configuration form. Currently, token_input is defined like this:

    $form['token_input'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Token input'),
      '#default_value' => $this->configuration['token_input'],
      '#description' => $this->t('The data input for OpenAI.'),
      '#weight' => -10,
      '#eca_token_reference' => TRUE,
    ];

This means, ECA expects the name of a token - exactly one and really only a name. So you couldn't even use node:body here.

For the use case of providing "The data input for OpenAI.", this field configuration is not ideal, I guess. I should probably be more like this:

    $form['token_input'] = [
      '#type' => 'textarea',
      '#title' => $this->t('Token input'),
      '#default_value' => $this->configuration['token_input'],
      '#description' => $this->t('The data input for OpenAI. This field supports tokens.'),
      '#weight' => -10,
    ];

In that case, the input could be [node:body] or any sequence of text, containing any number of tokens.

Note, the current token_input with the '#eca_token_reference' => TRUE, really just expects a token name without the brackets and uses that token's data for further processing. It helps us to validate the configuration form, so that this is not providing any non-valid token name.

Whenever arbitrary text content should be allowed, this is not the correct format, then it should be a text-area that allows for any input, including tokens or just a token. But then with real token syntax, i.e. with the surrounding brackets.

alfthecat’s picture

My suggestion for an ideal solution would be to not require an "Input token" but simply allow tokens inside of the "Prompt" field. I think that is in line with what @jurgenhaas is suggesting.

I have noticed that if I store data inside of tokens, I can use those tokens in the Prompt field. But it does not support prompts like, "Summarize [entity:body]".