Chatgpt 简明教程
How to Create Your Own ChatGPT Plugin?
插件是任何用于让人们轻松完成事情的软件,如果手动完成,这些事情通常会非常耗时。ChatGPT 插件会是一些在其制作中使用了 ChatGPT 的东西。目前已有 230 多个 ChatGPT 插件可用。在本章中,我们将展示如何创建您自己的插件。
A plugin is any software that is used to make things easy for people which would have been otherwise time-consuming if done manually. A ChatGPT plugin would be something that would use ChatGPT in its making. There are already 230+ ChatGPT plugins available. In this chapter, we will show how you can create a plugin of your own.
What is ChatGPT Plugin?
ChaGPT 插件是用于解决用户或组织遇到的问题的软件。通常,它们可以让人们和开发人员的生活更轻松。一些流行的 ChatGPT 插件类型包括 ChatGPT 检索插件、翻译插件、面向任务的插件、社交媒体以及娱乐插件。
ChaGPT plugins are software used to solve a problem that a user or organization comes across. Usually, these make lives easier for people and developers. Some of the popular types of ChatGPT plugins are ChatGPT retrieval plugins, Translation Plugins, Task-Oriented Plugins, Social Media, and Entertainment Plugins.
一些流行的 ChatGPT 插件包括 Wolfram、Zappier、Speak 和 OpenTable。还有很多其他插件(总共约 230 多个)。
A few of the popular ChatGPT plugins available out there are Wolfram, Zappier, Speak, and OpenTable. There are so many others as well (approximately 230+ as a whole).
How to Create a ChatGPT Plugin?
对于我们即将创建的 ChatGPT 插件,我们将使用 ChatGPT API 创建一个笑话生成器插件。现在让我们详细了解整个教程!
For the ChatGPT Plugin we are going to create, we will create a Joke Generator Plugin using the ChatGPT API. Let us go through the entire step-by-step tutorial now!
Step 1 − 登录您的 OpenAI 帐户或注册一个新帐户。如果您注册新帐户或创建了新近帐户,您将获得 18 个免费积分,有效期为 3 个月。
Step 1 − Log in to your OpenAI account or sign up for a new account. If you sign up for a new account or have created a recent account, you’ll get 18 free credits for 3 months.
Step 2 − 前往右上角的您的帐户并访问 API 密钥。创建新的 API 密钥并将其存储在某个地方,以便您不会丢失它。
Step 2 − Go to your account in the top right corner and access your API keys. Create a new API key and store it somewhere so that you don’t lose it.
Step 3 − 创建项目文件夹和文件以在您喜欢的语言中添加代码。对于这个,我们将使用 Python。因此,我们将其命名为“chatgpt-plugin.py”。
Step 3 − Create a project folder and a file to add your code in your preferred language. We will use Python for this one. So, let’s name it “chatgpt-plugin.py”.
Step 4 − 打开您的终端并安装 OpenAI 库。
Step 4 − Open your terminal and install the OpenAI library.
pip install openai
Step 5 − 在您的“chatgpt-plugin.py”python 文件中导入 openai 库。
Step 5 − Import the openai library in your “chatgpt-plugin.py” python file.
import openai
Step 6 - 将你在 OpenAI 网站上获取的 API 秘钥,添加到“import openai”的下方。
Step 6 − The API key that you got from the OpenAI website, add it here below “import openai”.
openai.api_key = "YOUR_API_KEY"
Step 7 - 接下来是实际的代码。我们将创建一个名为 get_chatgpt_response 的函数来接收用户输入/提示,并通过调用 API 的创建函数来存储响应。
Step 7 − Its time for the actual code. Well create a function called get_chatgpt_response to take in the user input/prompt and store the response by calling the API’s create function.
def get_chatgpt_response(user_input):
response = openai.Completion.create(
engine="text-davinci-002", # Replace with the appropriate engine for your API version
prompt=user_input,
max_tokens=100
)
return response["choices"][0]["text"].strip()
Step 8 - 现在,我们将通过调用之前创建的函数来测试我们的代码。
Step 8 − We will call test our code now by calling the created function that we created before.
def test_plugin():
user_input = "Tell me a joke."
response = get_chatgpt_response(user_input)
print("User Input:", user_input)
print("ChatGPT Response:", response)
if __name__ == "__main__":
test_plugin()
Step 9 - 让我们立即查看输出。运行 Python 文件以检查输出。
Step 9 − Lets check the output now. Run the python file to check the output.
python chatgpt_plugin.py
Output
Step 10 - 如果你想部署此应用程序插件,你可以这么做。为此,有很多部署服务,例如 Netlify、Heroku 等等。或者使用云平台或服务器,甚至可能是外部模型。选择你认为最好的,然后开始吧。
Step 10 − If you want to deploy this application plugin, you can do that. For this, there are many deployment services like Netlify, Heroku, etc. Or a cloud platform or server or maybe even an external model. Choose what you think is the best and go for it.
这就是我们可以使用 Python 创建 ChatGPT 插件的方式。我们了解了什么是 ChatGPT 插件,并通过了创建插件的所有步骤。
And that is how we can create a ChatGPT Plugin using Python. We learned what a ChatGPT plugin is and also went through all the steps to create one.
FAQs
1. How to use ChatGPT Plugins?
添加 ChatGPT 插件后,重要的是提供正确的提示来激活该插件。例如,要访问 PromptPerfect 插件,你必须在提示前添加“Perfect”。
Once you have added a ChatGPT plugin, it is important that you provide the right prompt to activate that plugin. For example, to access the PromptPerfect plugin, you have to add 'Perfect' in front of your prompt.
2. How to add a Plugin to ChatGPT?
你需要 ChatGPT 的付费版本,即 GPT-4,才能访问插件。有了 GPT-4 后,通过单击你的个人资料转到设置,单击 Beta 功能,单击插件,单击插件 [Beta],然后单击未启用任何插件。这会将你带到插件商店,你可以在那里购买适合你需求的插件,选择一个并启用它。
You need the paid version of ChatGPT, GPT-4 to access plugins. Once you have GPT-4, go to the settings by clicking on your profile, click on Beta features, click on Plugins, click on Plugins [Beta], and then click on no plugins enabled. This will take you to the Plugin store where you can shop for the plugin that suits your needs, choose the one, and enable it.
3. What are Some of the Most Popular ChatGPT Plugins?
有许多插件可以增强 ChatGPT 的功能。最受欢迎的插件包括 PromptPerfect、Zapier、Canva、OpenTable、Wolfram、Kayak、Argil AI、Speak、Link Reader 等。
There are several plugins that enhance ChatGPT capabilities. The most popular ones are PromptPerfect, Zapier, Canva, OpenTable, Wolfram, kayak, Argil AI, Speak, Link Reader, and more.