ChatGpt大模型入门

环境配置

创建虚拟环境

建议创建一个新的虚拟环境,避免安装依赖冲突,

conda下载:
https://docs.conda.io/en/latest/miniconda.html
conda安装:
https://zhuanlan.zhihu.com/p/591091259

或者使用venv

使用参考:https://vra.github.io/2021/01/03/venv-intro/

其他后续可能需要的依赖:

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 torch torchvision torchaudio

编辑器

编辑器可以随意,不过最好装下jupyter插件,或者直接下载jupyter,jupyter notebook方便调试。

ChatGpt

账户注册网上可以找到,这里就不说了。不过要使用api的话就需要充值,充值需要国外xy卡,可以参考以下链接:

https://savokiss.com/tech/chatgpt-api-open.html
https://savokiss.com/tech/gpt-plus-onekey.html

pay后就可以生成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 openai

openai.api_key = "sk-xxx" # 替换为你自己的key

completion = 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 openai

openai.api_key = "sk-xxx" # 替换为你自己的key

response = 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. 最好先看一遍langchain,学习langchain的一些思路。
  2. 指定格式输出时,要说明空和非空情况下两种输出格式,不然llm会强行设置一些无用的信息。
    例如:{“状态条件”: []},这种格式,会让llm以为必须有内容,即使说明了可以空,也会出问题,替换为{“状态条件”: ""或者[]}会更好。
  3. 如果指定了格式,llm还是输出一些无关的描述,在规则中添加"不要总结、解释和注释",能够减少无用输出。
  4. 通过history提醒输出错误,可以让他回顾规则第几点或者参考例子进行修正。作用不大。
  5. 任务做不好,再拆分可能会有奇效。
  6. 让llm对prompt进行标准转化,再提问,输出结果和原来提问的进行对比,让llm选择更好的结果,对提问进行标准化转换可能会有奇效。
  7. 可以将相关文档缓存到向量数据库,可以用提问在数据库里找到相关的内容,一起发送给llm。
  8. 尽量避免复杂的逻辑。
  9. 也可以参考guardrails from_rail的格式:
 Given below is XML that describes the information to extract from this document and the tags to extract it      │
│ into.                                                                                                           │
│                                                                                                                 │
│ <output>                                                                                                        │
│     <list name="tasks">                                                                                         │
│         <object name="task">                                                                                    │
│             <string name="type" description="任务类型"/>                                                        │
│             <string name="content" description="任务内容"/>                                                     │
│         </object>                                                                                               │
│     </list>                                                                                                     │
│     <integer name="logic" description="1:与  2:或" format="valid-choices: choices=[1, 2]"/>                   │
│ </output>                                                                                                       │
│                                                                                                                 │
│                                                                                                                 │
│ ONLY return a valid JSON object (no other text is necessary), where the key of the field in JSON is the `name`  │
│ attribute of the corresponding XML, and the value is of the type specified by the corresponding XML's tag. The  │
│ JSON MUST conform to the XML format, including any types and format requests e.g. requests for lists, objects   │
│ and specific types. Be correct and concise.                                                                     │
│                                                                                                                 │
│ Here are examples of simple (XML, JSON) pairs that show the expected behavior:                                  │
│ - `<string name='foo' format='two-words lower-case' />` => `{'foo': 'example one'}`                             │
│ - `<list name='bar'><string format='upper-case' /></list>` => `{"bar": ['STRING ONE', 'STRING TWO', etc.]}`     │
│ - `<object name='baz'><string name="foo" format="capitalize two-words" /><integer name="index"                  │
│ format="1-indexed" /></object>` => `{'baz': {'foo': 'Some String', 'index': 1}}`                                │
│                                                                                                                 │
│                                                                                                                 │
│                                                                                                                 │
│ Json Output:

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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值