- Issue created by @wouters_f
- π§πͺBelgium wouters_f Leuven
I've ported the module BUT
1. I made it more granular.
You can toggle each of the assistands ON or OFF2. Via the new settings screen
3. Its Using the AI under the hood , so now it's AI agnostic!
4. QUestion for MArcus:
How do I replace the moderation request (that's the only thing that I need to move from openai to /ai).
Not sure how to do that.Summary:
All of these work already
This one is still using the old ways
- Status changed to Needs review
2 months ago 10:40pm 12 July 2024 - π§πͺBelgium wouters_f Leuven
Another question: Do I still need the StringHelper::prepareText if we do normalisation?
- π§πͺBelgium wouters_f Leuven
Ok So i changed some more things:
1. You can only do the moderation stuff to OPENAI.
others will block you for that, so hardcoded that check to not allow this.2. Removed the dependeny on StringHelper::prepareText
- π§πͺBelgium wouters_f Leuven
Marcus sent me this:
Currently only OpenAI provider has moderation endpoint, it works like this:
$ai_provider = \Drupal::service('ai.provider')->createInstance('openai'); // Normalized $response will be a ModerationResponse object. $prompt = 'I fucking hate you, you fucking idiot (the goal is to Hate speech here to trigger the moderation) !'; $response = $ai_provider->moderation($input, 'text-moderation-latest', ["your_module_name"])->getNormalized();
Don't send that message to any other endpoint
The answer will be a Drupal\ai\OperationType\Moderation\ModerationResponse that has a boolean from the isFlagged method if the moderation endpoint thought the prompt was provoking and an array of information from getInformation method.
Note that the getInformation method is not normalized, so if you want to show that you probably need to do something like this if you want normalized output that is somewhat readable (or look into trace debugging tools styling like Tracy or Whoops):echo '<pre>'; print_r($response->getInformation()); //or var_dump echo '</pre>';
I ended up with this working code:
$response = $ai_provider->moderation($target_field_value, 'text-moderation-latest', ["ai_content"])->getNormalized(); $content = []; if ($response->isFlagged()) { $categories = $response->getInformation(); $content['heading'] = [ '#markup' => '<p>' . t('Violation(s) found for these categories:') . '</p>', ]; $violations = []; foreach ($categories as $category => $did_violate) { $violations[] = Unicode::ucfirst($category); } $content['results'] = [ '#theme' => 'item_list', '#list_type' => 'ul', '#items' => $violations, ]; /*and so on**/
- πΊπΈUnited States kevinquillen
Throwing one thing in here, it would be helpful to change the tone drop down from a hard coded list to a taxonomy select (so users can add in several bespoke tone options).
- πΊπΈUnited States kevinquillen
OpenAI returns score values with the moderation results, it could be useful to include that somehow. I don't know if OpenAI has made the scoring very interpretable, but I always considered the possibility someone may want to set violation thresholds for what they are willing to accept (i.e. up to .5). Looks like they do not return anything clear, yet. The docs say between 0 and 1 but sometimes you can get some huge numbers.
- π§πͺBelgium wouters_f Leuven
Would be great if someone could test the module and approve it. Thanks!
- Merge request !13Resolve #3461081 "Port openaicontent to ai module" β (Closed) created by wouters_f
- π©πͺGermany Marcus_Johansson
I did do major rewrites here instead of doing a code review, check: https://git.drupalcode.org/project/ai/-/merge_requests/16
It does:
- Move everything to a service, so the module file/procedural code is kept at minimum.
- Add the possibility to choose model for each of the asssistative tools.
- Abstract away the last hard coded connections to OpenAI - moderation is provider agnostic as the other tools.
- Issue was unassigned.
- Status changed to RTBC
2 months ago 7:39am 17 July 2024 - π©πͺGermany Marcus_Johansson
Tested and rewritten certain parts. Unless someone opposes it, it will be merged tonight CET.
- Status changed to Fixed
2 months ago 8:39am 18 July 2024 Automatically closed - issue fixed for 2 weeks with no activity.