ChatGpt大模型入门
环境配置
conda 环境
建议创建一个新的虚拟环境,避免安装依赖冲突,conda下载:
https://docs.conda.io/en/latest/miniconda.html
conda安装:
https://zhuanlan.zhihu.com/p/591091259
conda环境创建,llm是环境名,可以随意命名:
conda create -name llm python=3.9
conda切换环境
conda activate llm
其他后续可能需要的依赖:
pip install langchain
pip install tqdm
pip install openai
pip install javascript
pip install chromadb
pip install guardrails-ai
pip insatll jupyter
pytorch
pip install pytorch
编辑器
编辑器可以随意,不过最好装下jupyter插件,或者直接下载jupyter,jupyter notebook方便调试。
ChatGpt
账户注册网上可以找到,这里就不说了。不过要使用api的话就需要充值,充值需要国外信用卡,可以参考以下链接:
https://savokiss.com/tech/chatgpt-api-open.html
https://savokiss.com/tech/gpt-plus-onekey.html
充值后就可以生成api key:
https://platform.openai.com/account/api-keys
如果注册和充值麻烦,可以直接从银河录像局买现成的:
https://nf.video/
chatgpt
https://chat.openai.com/?model=text-davinci-002-render-sha
openai文档:
https://platform.openai.com/docs/guides/gpt/completions-api中文文档:
https://openai.xiniushu.com/
例子:
import openaiopenai.api_key = "sk-xxx" # 替换为你自己的keycompletion = openai.ChatCompletion.create(model="gpt-3.5-turbo",messages=[{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Who won the world series in 2020?"},{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},{"role": "user", "content": "Where was it played?"}]
)
print(completion.choices[0].message)
import openaiopenai.api_key = "sk-xxx" # 替换为你自己的keyresponse = openai.Completion.create(model="text-davinci-003",prompt="Write a tagline for an ice cream shop."
)
print(response)
prompt
https://lilianweng.github.io/posts/2023-03-15-prompt-engineering/#instruction-prompting
https://lslfd0slxc.feishu.cn/docx/Nqm9dX81hotVYUxFQuxcVR82n2g
https://www.promptingguide.ai/zh
https://mp.weixin.qq.com/s/MCsFoisMd6pB9wdhlQtd6Q
1. 指定格式输出时,要说明空和非空情况下两种输出格式,不然llm会强行设置一些无用的信息。例如:{"状态条件": []},这种格式,会让llm以为必须有内容,即使说明了可以空,也会出问题,替换为{"状态条件": ""或者[]}会更好。
2. 如果指定了格式,llm还是输出一些无关的描述,在规则中添加"不要总结、解释和注释",能够减少无用输出。
3. 通过history提醒输出错误,可以让他回顾规则第几点或者参考例子进行修正。作用不大。
4. 任务做不好,再拆分可能会有奇效。
5. 让llm对prompt进行标准转化,再提问,输出结果和原来提问的进行对比,让llm选择更好的结果,对提问进行标准化转换可能会有奇效。
6. 可以将相关文档缓存到向量数据库,可以用提问在数据库里找到相关的内容,一起发送给llm。
7. 尽量避免复杂的逻辑。
LangChain,api使用进阶
lainchain地址:
https://github.com/langchain-ai/langchain
langchain文档:
https://python.langchain.com/docs/modules/agents/
中文文档:
https://www.langchain.com.cn/modules/chains/generic/sequential_chains
其他文档:
https://juejin.cn/post/7217759646881742903
agent
https://lilianweng.github.io/posts/2023-06-23-agent/
工具
rail
https://shreyar.github.io/guardrails/rail/
chroma(embedding database)
https://docs.trychroma.com/
大模型应用项目
Voyager,应用在我的世界
https://github.com/MineDojo/Voyager/
https://voyager.minedojo.org/
本地部署大模型
开源的大模型有很多,这里只介绍chatglm6b,链接:
https://github.com/THUDM/ChatGLM2-6B
https://github.com/THUDM/ChatGLM-6B
https://huggingface.co/THUDM/chatglm-6b
https://cloud.tsinghua.edu.cn/d/fb9f16d6dc8f482596c2/?p=%2F&mode=grid
部署教程:
https://zhuanlan.zhihu.com/p/617644321?utm_id=0
微调:
https://github.com/lich99/ChatGLM-finetune-LoRA
https://blog.csdn.net/bmfire/article/details/131064677
https://github.com/THUDM/ChatGLM-6B/tree/main/ptuning
LangChain-ChatGLM
本地部署glm加上langchain
https://github.com/chatchat-space/langchain-ChatGLM
深度学习
https://courses.d2l.ai/zh-v2/
https://space.bilibili.com/1567748478/channel/seriesdetail?sid=358497
https://learn.deeplearning.ai/
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
