askerakbar / gpt-trix-editor

The GPT Trix Editor is a form field component for the Filament PHP framework that enhances the Trix editor with OpenAI GPT features.
https://filamentphp.com/plugins/asker-akbar-gpt-trix-editor
MIT License
38 stars 14 forks source link

Bug: doesn't load existing data on edit or it seems not to #11

Closed jlpellicer closed 2 months ago

jlpellicer commented 3 months ago

I have a database with a column named description. I am using Filamentphp TextArea to display and edit it. When I use gpt-trix-editor, it shows the data on view, but when I edit the record it doesn't load the description. No errors, just doesn't display the existing description. Nothing fancy:

GptTrixEditor::make('description')
    ->label(__('products.description'))
    ->columnSpanFull(),

Config file as is, no modifications:

<?php

return [

    /*
     * Set the model to use for the GPT API.
     */
    'model' => env('TRIX_GPT_MODEL', 'gpt-3.5-turbo-instruct'),

    /*
        max_tokens
        The maximum number of tokens to generate in the completion.
        https://platform.openai.com/docs/api-reference/completions/create#completions/create-max_tokens
    */

    'max_tokens' => 1000,

    /*
        temperature
        What sampling temperature to use, between 0 and 2.
        Higher values like 0.8 will make the output more random, while lower values like 0.2
        will make it more focused and deterministic.
        https://platform.openai.com/docs/api-reference/completions/create#completions/create-temperature
    */

    'temperature' => 0,

    /*
        If set to true, notifications will be enabled for successfull gpt api calls.
    */
    'enable_notifications'  => true,

    /*
    |
    | Prompt labels and propmpts that are currently listed on the dropdown menu
    |
    | for example: if the Text area content is "Write a poem about Space" and
    | when you click run, as default that content will be appended with the following and send to GPT
    | Complete the following text and return back with the same HTML : Write a poem about Space
    |
    |
    */

    'prompt-prefixes'   =>  [
        [
            'prefix_key'    => 'run',
            'prefix_label'  => 'prompt_prefixes.run',
            'prefix'        =>  'Complete the following and return the same HTML format:',
        ],
        [
            'prefix_key'    => 'run_on_selected_text',
            'prefix_label'  => 'prompt_prefixes.run_on_selected_text',
            'prefix'        => 'Complete the following and return the same HTML format:',
            'on_selected'  => true
        ],
        [
            'prefix_key'    => 'check_grammar',
            'prefix_label'  => 'prompt_prefixes.check_grammar',
            'prefix'        => 'Check only the grammar and return the same HTML format:',
        ],
        [
            'prefix_key'    => 'fix_grammar_on_selected_text',
            'prefix_label'  => 'prompt_prefixes.check_grammar_on_selected_text',
            'prefix'        => 'Fix the grammar and spelling issues and return the same HTML format without changes:',
            'on_selected'  => true
        ]
    ]

];

Filamentphp v3.2.105 PHP 8.2.22 Laravel 11.21

image image

Hope you can help. Thank you

askerakbar commented 2 months ago

I tried the latest plugin on my local and it worked for me. I'm really sorry, but you'll have to debug it to find the issue.

errnerr commented 2 months ago

@jlpellicer - Hi, did you get to the bottom of this? I'm seeing the same behaviour.

jlpellicer commented 2 months ago

No, sorry @errnerr, I just went back to Filament's RichEditor

askerakbar commented 2 months ago

Hey @jlpellicer @errnerr,

There were some updates in the latest rich editor from filament.

I've made some changes that might fix your issue.
Check the commit for details: https://github.com/askerakbar/gpt-trix-editor/commit/5ce54a68603f3bc4669fccb238e6cee1faea2442

You'll need to either remove and reinstall the whole pacakge or manually update the following files with the changes from commit:

public/js/askerakbar/gpt-trix-editor/components/gpt-trix-editor.js  
vendor/askerakbar/gpt-trix-editor/resources/views/trix-editor.blade.php  
errnerr commented 2 months ago

Amazing! Thank you @askerakbar That has fixed the issue for me.