It has made multiple errors and incorrect assumptions; too many to go through one by one.
The main problem is it has hallucinated the “Argument” field for passing the text parameter; in fact this field does not exist.
Rather than try to correct it, I suggest using this instead:
// #popclip
// name: Translate to English
// icon: circle en
// language: javascript
// after: paste-result
// entitlements: [network]
const apikey = 'INSERT YOUR API KEY HERE';
const openai = require("axios").create({
baseURL: 'https://api.openai.com/v1/',
headers: { Authorization: `Bearer ${apikey}` }
});
const { data } = await openai.post('completions', {
model: 'text-davinci-003',
max_tokens: 2048,
prompt: popclip.input.text + "\n\n" + "Translate the above text to English:"
});
return data.choices[0].text.trim();
(The above block is an extension snippet — select it then click “Install Extension” in PopClip.)
You’ll need to copy and paste it to a text editor to put your one API key in.