制作自己的ChatGPT
Feb 11, 20235 min read
推荐:使用 NSDT场景设计器 快速搭建 3D场景。
众所周知,ChatGPT 目前能够取得令人印象深刻的壮举。 很可能许多人都有在他们自己的项目中使用该技术的想法。 不过需要注意的是,ChatGPT 目前并没有官方的 API。 使用非官方 API 可能会导致困难。
目前需要手动获取access token和cloudflare token才能使用API。 此外,这些令牌必须每两小时手动更改一次。
1、ChatGPT
ChatGPT 在其设计中使用了 GPT-3 模型,并在此基础上开发了一个新模型。 因此,新模型的输出结果往往与 GPT-3 相似。 在撰写本文时,新模型的 ChatGPT 中使用了 text-davinci-002-render 模型,但目前尚未向公众开放。
虽然 ChatGPT 可能不是开创性的,但它提供了一个利用现有技术的新界面。 通过利用强大的提示和高效的记忆窗口。 因此,我们可以使用 LLM Chain 方法复制其功能,而不是破解 ChatGPT 的非官方 API。
2、LangChain
Langchain 是一个新的 python 包,它为LLM链提供了一个标准接口,与其他工具的大量集成,以及用于常见应用程序的端到端链。
LangChain 旨在协助四个主要领域,此处按复杂性递增的顺序列出:
LLM和提示
链
代理
记忆
在此处的官方文档中了解有关 langchain 的更多信息。
3、安装
要使用 langchain 包,你可以从 pypi 安装它。
pip install langchain
要从 langchain 获取最新更新,你可以使用这种安装方法。
pip install "git+https://github.com/hwchase17/langchain.git"
更多安装选项请阅读此处。
4、示例项目
你可以使用 ChatGPT 做很多事情,其中一个有趣的事情是为学生作业建立问答。 所以这次我们将创建 AI 版的 Brainly。
下面是我们将从 ChatGPT 中得到的。
下面是 langchain 的提示:
from langchain.llms import OpenAI
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain.chains import SimpleSequentialChainllm = OpenAI(temperature=.7)
template = """You are a teacher in physics for High School student. Given the text of question, it is your job to write a answer that question with example.
Question: {text}
Answer:
"""
prompt_template = PromptTemplate(input_variables=["text"], template=template)
answer_chain = LLMChain(llm=llm, prompt=prompt_template)
answer = answer_chain.run("What is the formula for Gravitational Potential Energy (GPE)?")
print(answer)
这是我们使用 langchain 从 GPT-3 获得的结果:
The formula for Gravitational Potential Energy (GPE) is GPE = mgh, where m is the mass of an object, g is the acceleration due to gravity, and h is the height of the object. For example, if an object with a mass of 10 kg is at a height of 5 meters, then the GPE would be GPE = 10 x 9.8 x 5 = 490 Joules.
5、聊天机器人
如果你需要创建像 AI 这样的聊天机器人,你可以使用 langchain 的内存。 这是如何操作的示例。
from langchain.chains.conversation.memory import ConversationBufferMemory
from langchain import OpenAI, LLMChain, PromptTemplatetemplate = """You are a teacher in physics for High School student. Given the text of question, it is your job to write a answer that question with example.
{chat_history}
Human: {question}
AI:
"""
prompt_template = PromptTemplate(input_variables=["chat_history","question"], template=template)
memory = ConversationBufferMemory(memory_key="chat_history")llm_chain = LLMChain(llm=OpenAI(),prompt=prompt_template,verbose=True,memory=memory,
)llm_chain.predict(question="What is the formula for Gravitational Potential Energy (GPE)?")result = llm_chain.predict(question="What is Joules?")
print(result)
结果会是这样的:
$ python3 memory.py> Entering new LLMChain chain...
Prompt after formatting:
You are a teacher in physics for High School student. Given the text of question, it is your job to write a answer that question with example.Human: What is the formula for Gravitational Potential Energy (GPE)?
AI:> Finished LLMChain chain.> Entering new LLMChain chain...
Prompt after formatting:
You are a teacher in physics for High School student. Given the text of question, it is your job to write a answer that question with example.Human: What is the formula for Gravitational Potential Energy (GPE)?
AI:
The formula for Gravitational Potential Energy (GPE) is GPE = mgh, where m is the mass of the object, g is the acceleration due to gravity, and h is the height of the object.For example, if an object has a mass of 10 kg and is at a height of 5 meters, then the gravitational potential energy of the object is GPE = 10 kg x 9.8 m/s2 x 5 m = 490 Joules.
Human: What is Joules?
AI:> Finished LLMChain chain.
Joules (J) is the SI unit of energy. It is defined as the amount of energy required to move an object of one kilogram at a speed of one meter per second. It is also equal to the work done when a force of one Newton is applied to an object and moved one meter in the direction of the force.
6、结束语
ChatGPT 是一个基于 GPT-3 的聊天机器人,目前没有官方 API。 使用 LangChain,开发人员可以复制 ChatGPT 的功能,例如创建聊天机器人或问答系统,而无需使用非官方 API。
LangChain 为常见应用程序提供标准接口、大量集成和端到端链。 它可以从 pypi 安装,更多信息可以在官方文档中找到。
制作自己的ChatGPT相关推荐
- 【3分钟高效制作PPT】ChatGPT搭配闪击PPT生成PPT,你只需要输入一个标题
Hello,大家好,我是你的好伙伴AI博士 今天我来分享一下,怎么用ChatGPT配合闪击PPT,只输入一个标题,怎么生成一份高颜值的PPT. 第一步:了解闪击PPT的[文字转PPT]功能 闪击PPT ...
- 最新免费版 Office 全家桶Copilot,Gamma+MindShow 两大ChatGPT AI创意工具GPT-4神器助力高效智能制作 PPT,一键生成,与AI智能对话修改PPT(免安装)
目录 前言 ChatGPT + MindShow 1. 使用ChatGPT工具生成PPT内容 2. 使用MindShow工具一键智能制作PPT MindShow简介 使用网页版制作 pdf转ppt G ...
- 太高效了!ChatGPT一分钟助你完成精美PPT制作
前言 在之前的文章中,我们借助ChatGPT和Xmind,仅用一分钟就成功地创建了一幅详细的思维导图: 用ChatGPT 三分钟生成思维导图技巧 这篇文章将沿用相同的方法,让大家感受一下快速生成PPT ...
- 用ChatGPT实现变现的多种方法
ChatGPT作为人工智能文本生成工具的领导者,可以帮助未经训练的作家们构思文章,创建自己的博客或微信公众号,并最终从中受益.在本文中,我们将告诉您如何利用ChatGPT创造价值并获得收入的多种方式. ...
- 变现 起航篇! 手把手交你用chatgpt快速生成视频!
Chatgpt 很多同学都用的非常熟练了,但是都停留在文字阶段,有没有更好玩的用法,可以深度的利用chatgpt做一些事情呢? 今天菜哥就找一个方法可以快速利用chatgpt制作视频,整个过程大概3分 ...
- 探索AI助手ChatGPT实际应用场景
使用 Prompt 是使用 ChatGPT 的关键点之一.Prompt 是针对机器学习模型的输入,它提供了一个清晰.简洁的问题描述,并指示模型生成合适的答案.正确的 Prompt 可以帮助 ChatG ...
- 学生作业形同虚设!ChatGPT作弊成风!OpenAI:正在自研审核工具
本文来源 机器之心 编辑:泽南.蛋酱 「对学生有负面影响」,这么大责任 OpenAI 可担不起. 语言生成模型来了,学校的作业会不会从此变得形同虚设?近日,纽约市教育官员宣布禁止学生在公立学校使用 ...
- ChatGPT中文版提示词学习手册, 学完工作效率提升百倍!
既然你对ChatGPT及其功能有了⼀些了解,让我们更深入地了解⼀下ChatGPT是什么以及它是如何工作的. 那么ChatGPT是如何工作的呢?在高层次上,这个过程可以分解为以下步骤: 1. 用户将文本 ...
- 你应该知道的人工智能机器人 ChatGPT 提示语
公众号关注 「奇妙的 Linux 世界」 设为「星标」,每天带你玩转 Linux ! ChatGPT 自上线以来,凭借其优异的自然语言理解和输出能力,仅花 5天就成为了活跃用户过百万的现象级产品. ...
最新文章
- 智能安防赛道上 国产AI芯片力挫群雄
- 自动注册 IIS6 的 MIME 类型
- vue中怎么清空tab选项卡的缓存_vue Tab切换以及缓存页面处理的几种方式
- 史上最全阿里云服务器上Docker部署Springboot项目 实战 每一步都带详细图解!!!
- 06_Android中ArrayAdapter的使用
- lua运行外部程序_一起聊聊redis(5)——c#的lua脚本应用实例之高并发抢口罩
- 模拟Spring Security上下文进行单元测试
- DNN-两种矩阵相乘的理解
- ubuntu安装pip,setuptools
- 微信大改版,更新前必看的4个东西
- python如何用pip升级_手把手教你怎么用Python pip怎么升级pip?,专家详解
- android tv 应用安装器,论Android智能电视盒子必装应用之——QQ音乐TV版
- 屏幕小于6英寸的手机_这3款手机屏幕小于6英寸,单手操控没压力
- java excel下拉框_Java设置Excel下拉列表
- storm throw 口袋妖怪_pokemon go游戏术语都有哪些 口袋妖怪go玩法术语攻略
- 图文详情展示html,图文展示新闻网站模板
- 前端学习-CSS京东导航栏
- IntelliJ IDEA 2020.3.3 遇到Cannot resolve table ‘goods’
- 惠普linux进入bios设置u盘启动,如何进入bios设置,手把手教你惠普如何进入bios设置u盘启动...
- 由歌词引发的模式思考之上篇(FactoryMethod模式)