We can use appropriate prompts to ask ChatGPT answere in structured JSON data which is much more flexible. This tutorial is inspiring. Then we can assign more target fields, i.e.: sentiment, named entites, summary and other results you can imagine.

This way, we can save lots of money, because we just send tokens for once.

CommentFileSizeAuthor
#7 image (1).png47.46 KBeleonel
#7 image.png40.32 KBeleonel

Comments

fishfree created an issue. See original summary.

murrayw’s picture

Hi fishfree. The tutorial looks good. It has a lot of prompts which could easily be wrapped up as Augmentors and exposed in the WYSIWYG or as field widgets. There are a lot of good ideas in there.

In regards to the structure data... if I get the gist of it I believe this is the prompt you are referring to:

Can you provide a report on the paragraph? The report should include document statistics, vocabulary statistics, readability score, tone type (available options are Formal, Informal, Optimistic, Worried, Friendly, Curious, Assertive, Encouraging, Surprised, or Cooperative), intent type (available options are Inform, Describe, Convince, or Tell A Story), audience type (available options are General, Knowledgeable, or Expert), style type (available options are Formal or Informal), emotion type (available options are Mild or Strong), and domain type (available options are General, Academic, Business, Technical, Creative, or Casual).

ChatGPT retiurns data back as text - list items. From what I can see this is not JSON, although, i may be mistaken. Aslo, does ChatGPT always return data in exactly the same format.

My hunch is that the text feedback is not going to be structured enough... or it won't be structured wnough for general cases at least. If you believe that it is possible, then you could implement a specialised ChatGPT augmentor to return the data back in a structure you liked.
Augmentors do returned a keyed array, and so, they do support some structure - pretrty much what you are discussing.

For example, your Augmentor could return a structure like:
{
"score": ["10"],
"tone": ["simple"]
}

The trick will be working out how to extract the structure. Please refer to the "safe search" augmentor from Google Cloud Vision to see a bunch of keys with different values in them:
https://git.drupalcode.org/project/augmentor_google_cloud_vision/-/blob/...

I'm not sure that we would have success trying to build that into the standard ChatGPT Augmentor. The "Drupal way" would allow a hook to transform the result and so this might be onbe avenue worther considering if you needed that.

In short, I would recommend implementing your own Augmentor which is apple to translate the results to something which is more structured.

fishfree’s picture

@murrayw I've test by using the prompt "Please answer in JSON format", and it worked! Maybe you can have a try.

fishfree’s picture

Can we implement a JSON parser widget just as AugmentorSelectRegexWidget.php to make it?

mindaugasd’s picture

fishfree’s picture

Although ai_interpolator module is going to implement this feature, it is still neccessary for augmentor to make it. Because augmentor is used on the editing page with human manual curation, ai_interpolator is used totallay automatically.

eleonel’s picture

StatusFileSize
new40.32 KB
new47.46 KB

I'm planning to work on the "Output Format" feature vert soon. It's a straightforward addition that shouldn't take long to implement. Currently, our system supports targeting multiple fields with a single API request.

For instance, take a look at this screenshot: https://www.drupal.org/files/Screenshot%202022-10-31%20at%2015-39-23%20E.... This example utilizes the Google Cloud Safe Search endpoint to analyze images for potential explicit content (more details at https://www.drupal.org/project/augmentor_google_cloud_vision).

In the widget's configuration, we have the following setup (refer to the attached image for clarity):

COnfig

Target fields:
{
  "0": {"target_field": "field__image_racy", "key": "racy"},
  "1": {"target_field": "field_image_spoof", "key": "spoof"},
  "2": {"target_field": "field_image_adult", "key": "adult"},
  "3": {"target_field": "field_image_violence", "key": "violence"},
  "4": {"target_field": "field_image_medical", "key": "medical"}
}

These keys like "racy", "medical", etc., correspond to the root-level keys returned by the augmentor. To enhance this, we're considering the introduction of multi-level key selection. This would allow configurations like `root-level:second-level:third-level` to navigate through a response structure like:

{
  "root-level": {
    "second-level": {
      "third-level": "value"
    }
  }
}

config

This feature will provide more flexibility in handling complex data structures returned by the augmentor.