如何零基础使用Python写一个ChatGPT机器人 | 在线网页

作者:FancyPig | 发布时间: | 更新时间:

相关阅读

当然,你如果追求更多功能、好看的界面、用户体验,可以参考下面的文章

data-postsbox="{"id":32445,"title":"如何制作一个ChatGPT聊天页面 | ChatGPT国产化思路","author":"FancyPig","author_id":1,"cover_image":"https://static.pigsec.cn/wp-content/uploads/2023/02/20230216014624643.png","cover_video":"","views":92244,"comment_count":16,"category":"knowledge","is_forum_post":false}">{"id":32445,"title":"如何制作一个ChatGPT聊天页面 | ChatGPT国产化思路","author":"FancyPig","author_id":1,"cover_image":"https://static.pigsec.cn/wp-content/uploads/2023/02/20230216014624643.png","cover_video":"","views":92244,"comment_count":16,"category":"knowledge","is_forum_post":false}

其他的一些有趣的ChatGPT玩法分享

data-postsbox="{"id":32636,"title":"如何通过Todesk溯源黑客的手机号/邮箱 | ChatGPT编写自动化脚本","author":"FancyPig","author_id":1,"cover_image":"https://static.pigsec.cn/wp-content/uploads/2023/02/20230224010030220.png","cover_video":"","views":3696,"comment_count":6,"category":"knowledge","is_forum_post":false}">{"id":32636,"title":"如何通过Todesk溯源黑客的手机号/邮箱 | ChatGPT编写自动化脚本","author":"FancyPig","author_id":1,"cover_image":"https://static.pigsec.cn/wp-content/uploads/2023/02/20230224010030220.png","cover_video":"","views":3696,"comment_count":6,"category":"knowledge","is_forum_post":false}
data-postsbox="{"id":32736,"title":"抖音如何批量取消关注?| 全网首发 | 使用ChatGPT写一个自动化JS脚本","author":"FancyPig","author_id":1,"cover_image":"https://static.pigsec.cn/wp-content/uploads/2023/02/20230221082930613.png","cover_video":"","views":3138,"comment_count":11,"category":"knowledge","is_forum_post":false}">{"id":32736,"title":"抖音如何批量取消关注?| 全网首发 | 使用ChatGPT写一个自动化JS脚本","author":"FancyPig","author_id":1,"cover_image":"https://static.pigsec.cn/wp-content/uploads/2023/02/20230221082930613.png","cover_video":"","views":3138,"comment_count":11,"category":"knowledge","is_forum_post":false}
data-postsbox="{"id":32109,"title":"基于AI制作虚拟数字人动画 | 零基础手把手教程","author":"FancyPig","author_id":1,"cover_image":"https://static.pigsec.cn/wp-content/uploads/2023/02/20230210154202567.png","cover_video":"https://v.pigsec.cn/Create%20Your%20Own%20AI%20Animated%20Avatar-%20A%20Step-by-Step%20Guide_ts.m3u8","views":4606,"comment_count":9,"category":"knowledge","is_forum_post":false}">{"id":32109,"title":"基于AI制作虚拟数字人动画 | 零基础手把手教程","author":"FancyPig","author_id":1,"cover_image":"https://static.pigsec.cn/wp-content/uploads/2023/02/20230210154202567.png","cover_video":"https://v.pigsec.cn/Create%20Your%20Own%20AI%20Animated%20Avatar-%20A%20Step-by-Step%20Guide_ts.m3u8","views":4606,"comment_count":9,"category":"knowledge","is_forum_post":false}
data-postsbox="{"id":31554,"title":"我用ChatGPT写了一个射击游戏 | ChatGPT玩法介绍","author":"FancyPig","author_id":1,"cover_image":"https://static.pigsec.cn/wp-content/uploads/2023/02/20230131163521695.png","cover_video":"https://v.pigsec.cn/I%20Made%20a%20Game%20with%20ChatGPT..._ts.m3u8","views":3825,"comment_count":5,"category":"knowledge","is_forum_post":false}">{"id":31554,"title":"我用ChatGPT写了一个射击游戏 | ChatGPT玩法介绍","author":"FancyPig","author_id":1,"cover_image":"https://static.pigsec.cn/wp-content/uploads/2023/02/20230131163521695.png","cover_video":"https://v.pigsec.cn/I%20Made%20a%20Game%20with%20ChatGPT..._ts.m3u8","views":3825,"comment_count":5,"category":"knowledge","is_forum_post":false}
[postsbox post_id="28178"]

视频讲解

本期视频,我将教你如何从零开始创建你自己的ChatGPT聊天机器人,即便你从来没有接触过代码,但你对创建自己的ChatGPT机器人感兴趣,你也可以来观看本视频。我将演示三个不同版本的聊天机器人,从最简单的开始。你只需要使用Visual Studio Code,Python和一个带有ApiKey的OpenAI账户,简单四行代码便可以实现最基础的功能。接着,我将向你展示如何构建一个基于ChatGPT的聊天机器人,它可以记住以前的对话,建立上下文关系,甚至还可以教你如何测试它。在视频的最后一部分,我将介绍一个新工具,让你可以在浏览器中使用聊天机器人并与他人分享。

相关资料

相关代码

ChatGPT API Tutorial.zip
zip文件

如果你懒得下载,也可以直接从下面代码中复制

01 chatgpt simple.py

import openai

openai.api_key = "####"

completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Give me 3 ideas for apps I could build with openai apis "}])
print(completion.choices[0].message.content)

02 chatgpt chat assistant copy.py

import openai

openai.api_key = "####"

messages = []
system_msg = input("What type of chatbot would you like to create?\n")
messages.append({"role": "system", "content": system_msg})

print("Your new assistant is ready!")
while input != "quit()":
    message = input()
    messages.append({"role": "user", "content": message})
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=messages)
    reply = response["choices"][0]["message"]["content"]
    messages.append({"role": "assistant", "content": reply})
    print("\n" + reply + "\n")

03 chatgpt chat assistant website.py

import openai
import gradio

openai.api_key = "####"

messages = [{"role": "system", "content": "You are a financial experts that specializes in real estate investment and negotiation"}]

def CustomChatGPT(user_input):
    messages.append({"role": "user", "content": user_input})
    response = openai.ChatCompletion.create(
        model = "gpt-3.5-turbo",
        messages = messages
    )
    ChatGPT_reply = response["choices"][0]["message"]["content"]
    messages.append({"role": "assistant", "content": ChatGPT_reply})
    return ChatGPT_reply

demo = gradio.Interface(fn=CustomChatGPT, inputs = "text", outputs = "text", title = "Real Estate Pro")

demo.launch(share=True)
标签:ChatGPT, openai, openai官网, openai是哪个公司的, chatgpt官网, chatgpt国内能用吗, chatgpt怎么下载, chatgpt是什么意思, openai chatgpt, chatGPT机器人对话聊天软件, ChatGPT机器人怎么画, ChatGPT机器人图片, 在微信上搭建ChatGpt机器人