The-3Labs-Team / tinymce-chatgpt-plugin

🤖 A TinyMCE plugin for ChatGPT (gpt model) OpenAI or Custom LLM compatible endpoints
https://3labs.it
MIT License
14 stars 3 forks source link

Uncaught TypeError: Cannot read properties of undefined (reading 'prompts') #4

Closed gtraxx closed 5 months ago

gtraxx commented 6 months ago

Hi, I tested your plugin as an internal plugin but impossible to make it work (same with the version presented)

plugin.min.js:1 Uncaught TypeError: Cannot read properties of undefined (reading 'prompts')
    at openDialog (plugin.min.js:1:374)
    at Object.onAction (plugin.min.js:1:4864)
    at theme.min.js:4:308714
    at theme.min.js:4:145149
    at theme.min.js:4:308683
    at theme.min.js:4:30442
    at L (theme.min.js:4:2411)
    at run (theme.min.js:4:30427)
    at theme.min.js:4:31294
    at theme.min.js:4:795

Capture d’écran 2024-03-21 à 15 57 57

Best Regards Aurélien

murdercode commented 6 months ago

Hi, can you provide the config without the api key? Are you using tiny 5/6/7 ? Best,

gtraxx commented 6 months ago

@murdercode Hi here is my modified script for the beginning, the rest is the original one. TinyMCE v 6.7.2


tinymce.PluginManager.add('chatgpt', function (editor) {
    const OPENAI = editor.getParam('openai')
    var prompts =  [
        "Translate from English to Italian",
        "Summarize",
        "Proofread",
        "Write a blog post about",
    ]
    var apiKey = "sk-****";
    var model= "text-davinci-003";
    var temperature= 0.5;
    var maxTokens= 150;
    const openDialog = function () {`
murdercode commented 6 months ago

I was actually referring to the configuration, as per the README (https://github.com/The-3Labs-Team/tinymce-chatgpt-plugin?tab=readme-ov-file#installation). Was it followed correctly? That error says it can't find the configuration parameters, that is, at the time you instantiate the editor.

What you have done I understand is to modify the plugin to force the creation of the variables, but they are taken directly from init.

gtraxx commented 6 months ago

@murdercode I deleted my variables and placed the following code in the config, but I got exactly the same error. As it is internal and not external, I declared the plugin in the plugin table in addition to toolbar. Is it because of the model or something else ?


chatgpt: {
            apiKey: "sk-******", // Your OpenAI API key
            model: "text-davinci-003",
            temperature: 0.5,
            maxTokens: 150,
            prompts: [
                "Translate from English to Italian",
                "Summarize",
                "Proofread",
                "Write a blog post about",
            ],
        },
charlypolka8 commented 5 months ago

I think i've solved it, you can rename the tinymce param "chatgpt" which contains the prompts by "openai" :

external_plugins: {
  chatgpt:
    'https://cdn.jsdelivr.net/gh/The-3Labs-Team/tinymce-chatgpt-plugin@1/dist/chatgpt.min.js'
},
openai: {
  apiKey: 'sk-***', // OpenAI API key
  model: 'text-davinci-003',
  temperature: 0.5,
  maxTokens: 150,
  prompts: [
    //
  ]
}
gtraxx commented 5 months ago

I think i've solved it, you can rename the tinymce param "chatgpt" which contains the prompts by "openai" :

external_plugins: {
  chatgpt:
    'https://cdn.jsdelivr.net/gh/The-3Labs-Team/tinymce-chatgpt-plugin@1/dist/chatgpt.min.js'
},
openai: {
  apiKey: 'sk-***', // OpenAI API key
  model: 'text-davinci-003',
  temperature: 0.5,
  maxTokens: 150,
  prompts: [
    //
  ]
}

Hi, Thanks, have you tested the plugin locally? My goal is to not use "external_plugins" and to be able to put a key in an (external) js variable :)

Best Regards :)

murdercode commented 5 months ago

I think i've solved it, you can rename the tinymce param "chatgpt" which contains the prompts by "openai" :

external_plugins: {
  chatgpt:
    'https://cdn.jsdelivr.net/gh/The-3Labs-Team/tinymce-chatgpt-plugin@1/dist/chatgpt.min.js'
},
openai: {
  apiKey: 'sk-***', // OpenAI API key
  model: 'text-davinci-003',
  temperature: 0.5,
  maxTokens: 150,
  prompts: [
    //
  ]
}

Nice catch, it was a typo in JS config :) Readme is fixed now 👍

I think i've solved it, you can rename the tinymce param "chatgpt" which contains the prompts by "openai" :

external_plugins: {
  chatgpt:
    'https://cdn.jsdelivr.net/gh/The-3Labs-Team/tinymce-chatgpt-plugin@1/dist/chatgpt.min.js'
},
openai: {
  apiKey: 'sk-***', // OpenAI API key
  model: 'text-davinci-003',
  temperature: 0.5,
  maxTokens: 150,
  prompts: [
    //
  ]
}

Hi, Thanks, have you tested the plugin locally? My goal is to not use "external_plugins" and to be able to put a key in an (external) js variable :)

Best Regards :)

The plugin as it stands reads the variable from the env, if you need to put it out you should fork the project, it is not meant to have this support.

May I ask what benefit you would get? Just to consider whether you should apply a new behaviour, but in case I ask you to create a new issue, let's discuss it there :)

Bye :)