Jave Script inline Text Replacement with OpenAI API does not work with gpt-4 but works with get-3.5-turbo

I have installed the inline replacement named-trigger using Java Script to access the OpenAI API. I have an API Key approved for gpt-4 and I have been using it for a while. I have used the Java Script as given on the folivora site and works fine if I leave the gpt model version to be gpt-3.5-turbo. However, if I replace that with gpt-4 I get an error. Since I do not get to see the system response I am not sure what the error is, but I have tested my API key independently and works fine with gpt-4. I am wondering if I need to modify something else in Java Script? In other interfaces (e.g. iOS Shortcuts, I use the two version of the gpt models interchangeably without having to modify anything else in the code).

Many thanks for any insight!!

I'd recommend to use the dedicated chatgpt action in the latest version. It allows to specify the model to use

Thank you Andreas. That's true but I like the inline replacement option because it can be quicker when doing code development in an editor of Jupyter notebook.

the "transform selected text with ChatGPT" action does also do inline replacement!
I'm currently not on my computer but can post a. example on how to configure it later

Thank you so much Andreas that would be super helpful!

oh and I forgot: this might require the latest alpha version

Here is an example with BTT 4.070:

Everything works fine now, thank you!

Hi Andreas, now that with your help I got the basic ChatGPT text replacement functionality to work, I would like to experiment with combining this functionality with DeepL to translate ChatGPT inputs/outputs form/to other languages. I much prefer DeepL for translations over ChatGPT's translation capabilities, at least for certain languages. I tried using raw Apple Script with Apple Shortcuts but I could not properly figure out the UI elements of DeepL to interact with. I am wondering if BTT can make it easier to implement this idea?

P.S. I was experimenting with the MacOS App of DeepL, but they also provide a Web API: DeepL Translate: The world's most accurate translator

OK, I figured it out, I am using a Python Script to call the DeepL API and I am invoking the script through the Shortcuts app and then created a trigger in BTT to invoke it and replace text. Works great.

It would be nice if you could share the python and shortcut (or share the link to the shortcut) code :slight_smile:

Edit: Made a better solution for deepl I think :wink: Use the Action: Transform and Replace selection with Java Script and then use this Transformer - YOU HAVE TO ADD THE API KEY!!!! and also change the target language for your needs.

async (clipboardContentString) => {
    var response = await fetch('https://api-free.deepl.com/v2/translate', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      body: `auth_key=DEEPL_API_KEY&text=${clipboardContentString}&target_lang=DE`
	var data = await response.json();
	var translatedText = data.translations[0].text;
   return translatedText;

Thanks, this looks good. I will clean-up a little my python and shortcut because I left them in a messy debugging state while I turned my attention to other things and I will post and update everyone on this topic.

Hi @Andreas_Hegenberg,

Thank you for this incredible app and ingenious action!

Unfortunately, it seems that the "transform selected text with ChatGPT" action does not work with a custom model (specifically gpt-4) and API key.

Although the action does generate output, it appears to be based on GPT-3 instead of GPT-4.

I followed your instructions precisely as shown in the screenshot you shared. Do you have any suggestions for what might be causing this issue?

Edit: Adding a screenshot below showing that the API keys are not used (I have tested two API keys just to be on the safe side)

Edit 2: Just digged into log files and can confirm that the action continues using GPT-3.5-Turbo despite changing the action to the custom model & providing the respective API key

Any reaction? (@Andreas_Hegenberg )

Yes I fixed it in one of the recent alphas, sorry - forgot to update here!

Brilliant! Can confirm that it works now :slightly_smiling_face: Thank you for the speedy fix & the awesome app, @Andreas_Hegenberg!

Thanks for your time and awesome work on BTT!

Using a custom model seems broken again; my OpenAI API key never gets used. Only the built-in gpt-3.5-turbo model is working. (I tried gpt-4, gpt-4-turbo-preview, and curiously, even gpt-3.5-turbo, but with my own API key.)

Can you please take a look? :slightly_smiling_face:

which version are you on?

4.401 | 44011

Let me know if you're unable to reproduce the issue. If so, I can provide more info as needed. Just let me know what and how.

When I use my own OpenAI API Key, I just get "(null)" back as the output of the named trigger. To troubleshoot, I've tried creating new API keys, but that didn't fix anything.

Mhh, I just tried but it seems to work fine here.
Do you maybe have a tool like Proxyman installed that let's you record the HTTP traffic?

Could you try whether your API key works when you use it directly via curl? (Replace YOUR_API_KEY_HERE with your key and run this in terminal)

curl 'https://api.openai.com/v1/chat/completions' \
-H 'Host: api.openai.com' \
-H 'Connection: keep-alive' \
-H 'Accept: */*' \
-H 'Authorization: Bearer YOUR_API_KEY_HERE' \
-H 'Content-Type: application/json' \
--data-raw '{"model":"gpt-4-turbo-preview","messages":[{"content":"You are a helpful assistant who interprets every input as raw text unless instructed otherwise. Your answers do not include a description unless prompted to do so.","role":"system"},{"content":"Say  Hello","role":"user"}]}' \
--proxy http://localhost:9090