Creating new Field in Media Type raises error

Created on 21 March 2024, 9 months ago

Problem/Motivation

When I try to create a Text (formatted, long) field in Media Type: Document, I get an error.

Steps to reproduce

I am using the tutorial in this link: Link Here: to read PDF's using this module. I have followed succesfully the tutorial up to the stage where he is trying to create field in the Media Type Document. When I try to create a Formatted Text Long field I get the following error:

Fatal error: Declaration of Drupal\ai_interpolator_convertapi\TextDocument::generate(string $prompt, Drupal\Core\Entity\ContentEntityInterface $entity, Drupal\Core\Field\FieldDefinitionInterface $fieldDefinition, array $interpolatorConfig) must be compatible with Drupal\ai_interpolator\Annotation\AiInterpolatorFieldRule::generate(Drupal\Core\Entity\ContentEntityInterface $entity, Drupal\Core\Field\FieldDefinitionInterface $fieldDefinition, array $interpolatorConfig) in /var/www/html/web/modules/contrib/ai_interpolator_convertapi/src/TextDocument.php on line 135

I have tried make a Unformatted Text Long field and I have the same issue, however, when I try to create an Unformatted Text Short field is looks like it's working just fine. I don't know what is the issue.

Looking into the code, I see that the line 135 from that file is this function:

<?php
  public function generate(string $prompt, ContentEntityInterface $entity, FieldDefinitionInterface $fieldDefinition, array $interpolatorConfig) {
    // Field and api key has to be set.
    if (empty($entity->{$interpolatorConfig['base_field']}) || !$this->apiKey) {
      return [];
    }
    $values = [];
    ConvertApi::setApiSecret($this->apiKey);
    foreach ($entity->{$interpolatorConfig['base_field']} as $wrapperEntity) {
      $fileEntity = $wrapperEntity->entity;
      // Just allow PDF, Excel and Word files.
      if (in_array($fileEntity->getMimeType(), [
        'application/msword',
        'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        'application/vnd.ms-powerpoint',
        'application/vnd.openxmlformats-officedocument.presentationml.presentation',
        'application/vnd.ms-excel',
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'application/pdf',
      ])) {
        $result = ConvertApi::convert('txt', ['File' => $fileEntity->getFileUri()]);
        $values[] = $result->getFile()->getContents();
      }
    }
    return $values;
  }
?>

I don't really know what is happening in this function to be honest, I hope someone can help.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇨🇾Cyprus chrisk8r

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @chrisk8r
  • 🇨🇾Cyprus chrisk8r

    Also going a bit later into the abovementioned tutorial I'm following, when he chooses Choose AI Interpolator Rulefrom the field settings, he has the Option to choose, OpenAI Text Long and Text From Document, whereas me, in my feilds (Note: I haven't been able to create a Long Text Formatted or Unformatted, I just create a short text because it allows me to create one) i only have the option in CHoose AI Interpolator Rule the Option: Open AI Text. I suppose that the option in this field are depending on the type of field that I am creating. So I guess I cannot continue without being able to create a Long Text Field.

  • 🇨🇾Cyprus chrisk8r

    So after some trial and errors, I found out that the module's version was 1.0.0-alpha1. Updating to 1.0.0-alpha3 resolved this issue.

Production build 0.71.5 2024