Hello everyone, I am a beginner.
I am trying to write a PopClip extension to translate selected text into English.
This is the content of translation.py:
#!/Users/zmke/opt/anaconda3/bin/python
# -*- coding:utf-8 -*-
import openai
import sys
openai.api_key = 'XXXXXXXXX'
response = openai.Completion.create(
engine="text-davinci-003",
prompt=sys.argv[1] + "\nTranslate the above text to English:",
temperature=0.5,
max_tokens=60
)
print(response.choices[0].text.strip())
This file works properly in the Terminal.app.
The Config.plist is here:
There is another icon.png file, but it’s not important.
I installed this plugin normally, but when I selected text and the pop-up dialog box appeared, the Translate to English button was grayed out and I couldn’t click it. I don’t know where the error is, to be honest, these codes and files were generated by chatGPT for me.
Does anyone know what went wrong? Where do I need to make changes to properly execute the code?
Thanks in advanced!
If you really wanna go the Python route, you can do it, just need to get the Config.plist right and change the method of argument passing. I can go through it later if I get time, let me know if you want to do it.
Wow, this is so magical, so simple yet it really works.
I’m not familiar with Javascript, to put it more directly, I only know a little bit of Python. I also want to continue to write more Popclip extensions that are suitable for my own use with chatGPT. Therefore, if you have some free time, please help me to implement the translation function in Python, at least so I know how Python works in Popclip.
Thank you for your reply, it really excites me.
The code is valid but there is one mistake. The line “import sys” needs to be changed to “import os”.
Another question is that I read the OpenAI documentation today, which mentions that the GPT-3.5-Turbo model now has the same effect as Text-Davinci-003, but at only one tenth of the cost.
What do you think of this model? I tried to modify the engine parameters but it didn’t work.
In terms of model selection, I don’t really have a strong opinion, but it makes sense to use the latest and lowest cost one. I would have thought changing it to gpt-3.5-turbo would do the trick presuming it is already working with text-davinci-003. https://platform.openai.com/docs/models/gpt-3-5
4 is more capable of course but only usable if you have access to the closed beta.