├── .gitignore
├── .nojekyll
├── 00~导论
└── README.md
├── 99~参考资料
├── 2023~Numbers every LLM Developer should know.md
├── 2023~吴恩达~《Building Systems with the ChatGPT API》
│ ├── 1.Introduction.md
│ ├── 10.Evaluation-part2.ipynb
│ ├── 11.conclusion.md
│ ├── 2.Language Models, the Chat Format and Tokens.ipynb
│ ├── 3.Classification.ipynb
│ ├── 4.Moderation.ipynb
│ ├── 5.Chain of Thought Reasoning.ipynb
│ ├── 6.Chaining Prompts.ipynb
│ ├── 7.Check Outputs.ipynb
│ ├── 8.Evaluation.ipynb
│ ├── 9.Evaluation-part1.ipynb
│ ├── products.json
│ ├── readme.md
│ ├── utils_en.py
│ └── utils_zh.py
├── 2023~吴恩达~《ChatGPT Prompt Engineering for Developers》
│ ├── 00.README.md
│ ├── 01. 简介.md
│ ├── 02. 提示原则 Guidelines.ipynb
│ ├── 03. 迭代优化 Iterative.ipynb
│ ├── 04. 文本概括 Summarizing.ipynb
│ ├── 05. 推断 Inferring.ipynb
│ ├── 06. 文本转换 Transforming.ipynb
│ ├── 07. 文本扩展 Expanding.ipynb
│ ├── 08. 聊天机器人 Chatbot.ipynb
│ └── 09. 总结.md
├── 2023~吴恩达~《LangChain for LLM Application Development》
│ ├── 1.开篇介绍.md
│ ├── 2.模型、提示和解析器.ipynb
│ ├── 3.存储.ipynb
│ ├── 4.模型链.ipynb
│ ├── 5.文档问答.ipynb
│ ├── 6.评估.ipynb
│ ├── 7.代理.ipynb
│ ├── 8.课程总结.md
│ ├── Data.csv
│ ├── OutdoorClothingCatalog_1000.csv
│ └── readme.md
└── 2023~陆奇~我的大模型世界观.md
├── INTRODUCTION.md
├── LICENSE
├── LLM
└── README.link
├── README.md
├── _sidebar.md
├── header.svg
├── index.html
├── 循环神经网络
└── README.md
├── 经典自然语言
├── 主题模型
│ └── LDA.md
├── 统计语言模型
│ ├── Word2Vec.md
│ ├── 基础文本处理.md
│ ├── 统计语言模型.md
│ └── 词表示.md
├── 词嵌入
│ ├── 99~参考资料
│ │ └── 2023~Embeddings: What they are and why they matter.md
│ ├── 概述.md
│ └── 词向量
│ │ └── 基于 Gensim 的 Word2Vec 实践.md
└── 语法语义分析
│ ├── 1_nlp_basics_tokenization_segmentation.ipynb.txt
│ └── 命名实体识别.md
└── 行业应用
├── 机器人问答
└── README.md
└── 聊天对话
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore all
2 | *
3 |
4 | # Unignore all with extensions
5 | !*.*
6 |
7 | # Unignore all dirs
8 | !*/
9 |
10 | .DS_Store
11 |
12 | # Logs
13 | logs
14 | *.log
15 | npm-debug.log*
16 | yarn-debug.log*
17 | yarn-error.log*
18 |
19 | # Runtime data
20 | pids
21 | *.pid
22 | *.seed
23 | *.pid.lock
24 |
25 | # Directory for instrumented libs generated by jscoverage/JSCover
26 | lib-cov
27 |
28 | # Coverage directory used by tools like istanbul
29 | coverage
30 |
31 | # nyc test coverage
32 | .nyc_output
33 |
34 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
35 | .grunt
36 |
37 | # Bower dependency directory (https://bower.io/)
38 | bower_components
39 |
40 | # node-waf configuration
41 | .lock-wscript
42 |
43 | # Compiled binary addons (https://nodejs.org/api/addons.html)
44 | build/Release
45 |
46 | # Dependency directories
47 | node_modules/
48 | jspm_packages/
49 |
50 | # TypeScript v1 declaration files
51 | typings/
52 |
53 | # Optional npm cache directory
54 | .npm
55 |
56 | # Optional eslint cache
57 | .eslintcache
58 |
59 | # Optional REPL history
60 | .node_repl_history
61 |
62 | # Output of 'npm pack'
63 | *.tgz
64 |
65 | # Yarn Integrity file
66 | .yarn-integrity
67 |
68 | # dotenv environment variables file
69 | .env
70 |
71 | # next.js build output
72 | .next
73 |
--------------------------------------------------------------------------------
/.nojekyll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wx-chevalier/NLP-Notes/11ac6ed37b1c1e001b8d2139d218629a717eb625/.nojekyll
--------------------------------------------------------------------------------
/00~导论/README.md:
--------------------------------------------------------------------------------
1 | # NLP 通用技术
2 |
3 | ## 文本生成
4 |
5 | 文本生成是使用计算机模拟人来生成文本的技术,可以分为 text-to-text,image-to-text,以及 data-to-text 等。文本生成的应用领域包括机器翻译、QA、文本摘要、文字改写、新闻报道(体育、气象、财经、医疗等)、报告的自动生成等。
6 |
7 | 随着深度学习等技术在文本生成领域的应用,近年来文本生成技术发展比较快,特别是源于机器翻译的 seq2seq 结构,广泛应用到了文本生成的各个领域。但是应用中还是存在很多诸如创新度不够、不流畅、语句之间相关性不强等问题。文本生成的难度在于,由于人类的语言表达是多种多样的,因此文本生成的结果的质量没有确定的标准,难以评估模型效果,同时对于结果质量和多样性的的平衡也很难把握。
8 |
9 | ## 情感分析
10 |
11 | 文本情感分析(Sentiment Analysis),又称意见挖掘(Opinion Mining),是自然语言处理领域的一个重要研究方向,在工业界和学术界都有广泛的研究和应用,在每年的国际顶会中(例如:ACL、EMNLP、IJCAI、AAAI、WWW 等)都有大量的论文。
12 |
13 | 简单而言,它是对带有情感色彩的主观性文本进行分析、处理、归纳和推理的过程。相对于客观文本,主观文本包含了用户个人的想法或态度,是用户群体对某产品或事件,从不同角度、不同需求和自身体验去分析评价的结果,这些评价具有主观能动性和多样性,具有情感分析的意义和价值。
14 |
--------------------------------------------------------------------------------
/99~参考资料/2023~Numbers every LLM Developer should know.md:
--------------------------------------------------------------------------------
1 |
21 |
22 | # Numbers every LLM Developer should know
23 |
24 | When I was at Google, there was a document put together by [Jeff Dean](https://en.wikipedia.org/wiki/Jeff_Dean), the legendary engineer, called [Numbers every Engineer should know](http://brenocon.com/dean_perf.html). It’s really useful to have a similar set of numbers for LLM developers to know that are useful for back-of-the envelope calculations. Here we share particular numbers we at Anyscale use, why the number is important and how to use it to your advantage.
25 |
26 | ## Notes on the Github version
27 |
28 | Last updates: 2023-05-17
29 |
30 | If you feel there's an issue with the accuracy of the numbers, please file an issue. Think there are more numbers that should be in this doc? Let us know or file a PR.
31 |
32 | We are thinking the next thing we should add here is some stats on tokens per second of different models.
33 |
34 | ## Prompts
35 |
36 | ### 40-90%[^1]: Amount saved by appending “Be Concise” to your prompt
37 |
38 | It’s important to remember that you pay by the token for responses. This means that asking an LLM to be concise can save you a lot of money. This can be broadened beyond simply appending “be concise” to your prompt: if you are using GPT-4 to come up with 10 alternatives, maybe ask it for 5 and keep the other half of the money.
39 |
40 | ### 1.3: Average tokens per word
41 |
42 | LLMs operate on tokens. Tokens are words or sub-parts of words, so “eating” might be broken into two tokens “eat” and “ing”. A 750 word document in English will be about 1000 tokens. For languages other than English, the tokens per word increases depending on their commonality in the LLM's embedding corpus.
43 |
44 | Knowing this ratio is important because most billing is done in tokens, and the LLM’s context window size is also defined in tokens.
45 |
46 | ## Prices[^2]
47 |
48 | Prices are of course subject to change, but given how expensive LLMs are to operate, the numbers in this section are critical. We use OpenAI for the numbers here, but prices from other providers you should check out ([Anthropic](https://cdn2.assets-servd.host/anthropic-website/production/images/model_pricing_may2023.pdf), [Cohere](https://cohere.com/pricing)) are in the same ballpark.
49 |
50 | ### ~50: Cost Ratio of GPT-4 to GPT-3.5 Turbo[^3]
51 |
52 | What this means is that for many practical applications, it’s much better to use GPT-4 for things like generation and then use that data to fine tune a smaller model. It is roughly 50 times cheaper to use GPT-3.5-Turbo than GPT-4 (the “roughly” is because GPT-4 charges differently for the prompt and the generated output) – so you really need to check on how far you can get with GPT-3.5-Turbo. GPT-3.5-Turbo is more than enough for tasks like summarization for example.
53 |
54 | ### 5: Cost Ratio of generation of text using GPT-3.5-Turbo vs OpenAI embedding
55 |
56 | This means it is way cheaper to look something up in a vector store than to ask an LLM to generate it. E.g. “What is the capital of Delaware?” when looked up in an neural information retrieval system costs about 5x[^4] less than if you asked GPT-3.5-Turbo. The cost difference compared to GPT-4 is a whopping 250x!
57 |
58 | ### 10: Cost Ratio of OpenAI embedding to Self-Hosted embedding
59 |
60 | > Note: this number is sensitive to load and embedding batch size, so please consider this approximate.
61 |
62 | In our blog post, we noted that using a g4dn.4xlarge (on-demand price: $1.20/hr) we were able to embed at about 9000 tokens per second using HuggingFace’s SentenceTransformers (which are pretty much as good as OpenAI’s embeddings). Doing some basic math of that rate and that node type indicates it is considerably cheaper (factor of 10 cheaper) to self-host embeddings (and that is before you start to think about things like ingress and egress fees).
63 |
64 | ### 6: Cost Ratio of OpenAI base vs fine tuned model queries
65 |
66 | It costs you 6 times as much to serve a fine tuned model as it does the base model on OpenAI. This is pretty exorbitant, but might make sense because of the possible multi-tenancy of base models. It also means it is far more cost effective to tweak the prompt for a base model than to fine tune a customized model.
67 |
68 | ### 1: Cost Ratio of Self-Hosted base vs fine-tuned model queries
69 |
70 | If you’re self hosting a model, then it more or less costs the same amount to serve a fine tuned model as it does to serve a base one: the models have the same number of parameters.
71 |
72 | ## Training and Fine Tuning
73 |
74 | ### ~$1 million: Cost to train a 13 billion parameter model on 1.4 trillion tokens
75 |
76 | The [LLaMa paper](https://arxiv.org/abs/2302.13971) mentions it took them 21 days to train LLaMa using 2048 GPUs A100 80GB GPUs. We considered training our own model on the Red Pajama training set, then we ran the numbers. The above is assuming everything goes right, nothing crashes, and the calculation succeeds on the first time, etc. Plus it involves the coordination of 2048 GPUs. That’s not something most companies can do (shameless plug time: of course, we at Anyscale can – that’s our [bread and butter](https://www.anyscale.com/blog/training-175b-parameter-language-models-at-1000-gpu-scale-with-alpa-and-ray)! Contact us if you’d like to learn more). The point is that training your own LLM is possible, but it’s not cheap. And it will literally take days to complete each run. Much cheaper to use a pre-trained model.
77 |
78 | ### < 0.001: Cost ratio of fine tuning vs training from scratch
79 |
80 | This is a bit of a generalization, but the cost of fine tuning is negligible. We showed for example that you can fine tune a [6B parameter model for about 7](https://www.anyscale.com/blog/how-to-fine-tune-and-serve-llms-simply-quickly-and-cost-effectively-using). Even at OpenAI’s rate for its most expensive fine-tunable model, Davinci, it is 3c per 1000 tokens. That means to fine tune on the entire works of Shakespeare (about 1 million words), you’re looking at $40[^5]. However, fine tuning is one thing and training from scratch is another …
81 |
82 | ## GPU Memory
83 |
84 | If you’re self-hosting a model, it’s really important to understand GPU memory because LLMs push your GPU’s memory to the limit. The following statistics are specifically about inference. You need considerably more memory for training or fine tuning.
85 |
86 | ### V100: 16GB, A10G: 24GB, A100: 40/80GB: GPU Memory Capacities
87 |
88 | It may seem strange, but it’s important to know the amount of memory different types of GPUs have. This will cap the number of parameters your LLM can have. Generally, we like to use A10Gs because they cost $1.50 to $2 per hour each at AWS on-demand prices and have 24G of GPU memory, vs the A100s which will run you about $5 each at AWS on-demand prices.
89 |
90 | ### 2x number of parameters: Typical GPU memory requirements of an LLM for serving
91 |
92 | For example, if you have a 7 billion parameter model, it takes about 14GB of GPU space. This is because most of the time, one 16-bit float (or 2 bytes) is required per parameter. There’s usually no need to go beyond 16-bit accuracy, and most of the time when you go to 8-bit accuracy you start to lose resolution (though that may be acceptable in some cases). Of course there are efforts to reduce this, notably llama.cpp which runs a 13 billion parameter model on a 6GB GPU by quantizing aggressively down to 4 bits (and 8 bits without too much impact), but that’s atypical.
93 |
94 | ### ~1GB: Typical GPU memory requirements of an embedding model
95 |
96 | Whenever you are doing sentence embedding (a very typical thing you do for clustering, semantic search and classification tasks), you need an embedding model like [sentence transformers](https://www.sbert.net/docs/pretrained_models.html#sentence-embedding-models/). OpenAI also has its own embeddings that they provide commercially.
97 |
98 | You typically don’t have to worry about how much memory embeddings take on the GPU, they’re fairly small. We’ve even had the embedding and the LLM on the same GPU.
99 |
100 | ### >10x: Throughput improvement from batching LLM requests
101 |
102 | Running an LLM query through a GPU is very high latency: it may take, say, 5 seconds, with a throughput of 0.2 queries per second. The funny thing is, though, if you run two tasks, it might only take 5.2 seconds. This means that if you can bundle 25 queries together, it would take about 10 seconds, and our throughput has improved to 2.5 queries per second. However, see the next point.
103 |
104 | ### ~1 MB: GPU Memory required for 1 token of output with a 13B parameter model
105 |
106 | The amount of memory you need is directly proportional to the maximum number of tokens you want to generate. So for example, if you want to generate outputs of up to 512 tokens (about 380 words), you need 512MB. No big deal you might say – I have 24GB to spare, what’s 512MB? Well, if you want to run bigger batches it starts to add up. So if you want to do batches of 16, you need 8GB of space. There are some techniques being developed that overcome this, but it’s still a real issue.
107 |
108 | # Cheatsheet
109 |
110 |
111 |
112 | # Next Steps
113 |
114 | See our earlier [blog series on solving Generative AI infrastructure](https://www.anyscale.com/blog/ray-common-production-challenges-for-generative-ai-infrastructure) and [using LangChain with Ray](https://www.anyscale.com/blog/llm-open-source-search-engine-langchain-ray). \
115 | \
116 | If you are interested in learning more about Ray, see [Ray.io](http://ray.io/) and [Docs.Ray.io](http://docs.ray.io/). \
117 | \
118 | To connect with the Ray community join #LLM on the [Ray Slack](https://docs.google.com/forms/d/e/1FAIpQLSfAcoiLCHOguOm8e7Jnn-JJdZaCxPGjgVCvFijHB5PLaQLeig/viewform) or our [Discuss forum](https://discuss.ray.io/). \
119 | \
120 | If you are interested in our Ray hosted service for ML Training and Serving, see [Anyscale.com/Platform ](http://www.anyscale.com/platform)and click the 'Try it now' button
121 |
122 | **Ray Summit 2023:** If you are interested to learn much more about how Ray can be used to build performant and scalable LLM applications and fine-tune/train/serve LLMs on Ray, join [Ray Summit](https://raysummit.anyscale.com/) on September 18-20th! We have a set of great keynote speakers including John Schulman from OpenAI and Aidan Gomez from Cohere, community and tech talks about Ray as well as [practical training focused on LLMs](https://github.com/ray-project/ray-educational-materials/blob/main/NLP_workloads/Text_generation/LLM_finetuning_and_batch_inference.ipynb).
123 |
124 |
125 |
126 | ## Notes
127 |
128 | [^1]: Based on experimentation with GPT-3.5-Turbo using a suite of prompts on 2023-05-08.
129 | [^2]: Retrieved from [http://openai.com/pricing](http://openai.com/pricing) on 2023-05-08.
130 | [^3]: **GPT-4**: 6c/1k tokens for the prompt, 12c/1k tokens for the generation (32,000 window version, 8,000 window version is half that). **GPT-3.5 Turbo**: 0.2c/1k tokens.
131 | [^4]: This assumes the vector lookup is “free.” It’s not, but it uses CPUs (much cheaper) and is fairly fast.
132 | [^5]: 1 million words / 0.75 tokens/word / 1000\*0.03 = $40.
133 |
--------------------------------------------------------------------------------
/99~参考资料/2023~吴恩达~《Building Systems with the ChatGPT API》/1.Introduction.md:
--------------------------------------------------------------------------------
1 | # 使用 ChatGPT API 搭建系统
2 |
3 | ## 简介
4 |
5 | 欢迎来到课程《使用 ChatGPT API 搭建系统》👏🏻👏🏻
6 |
7 | 本课程由吴恩达老师联合 OpenAI 开发,旨在指导开发者如何基于 ChatGPT 搭建完整的智能问答系统。
8 |
9 | ### 📚 课程基本内容
10 |
11 | 使用ChatGPT不仅仅是一个单一的提示或单一的模型调用,本课程将分享使用LLM构建复杂应用的最佳实践。
12 |
13 | 以构建客服助手为例,使用不同的指令链式调用语言模型,具体取决于上一个调用的输出,有时甚至需要从外部来源查找信息。
14 |
15 | 本课程将围绕该主题,逐步了解应用程序内部的构建步骤,以及长期视角下系统评估和持续改进的最佳实践。
16 |
17 |
18 | ### 🌹致谢课程重要贡献者
19 |
20 | 感谢来自OpenAI团队的Andrew Kondrick、Joe Palermo、Boris Power和Ted Sanders,
21 | 以及来自DeepLearning.ai团队的Geoff Ladwig、Eddie Shyu和Tommy Nelson。
--------------------------------------------------------------------------------
/99~参考资料/2023~吴恩达~《Building Systems with the ChatGPT API》/11.conclusion.md:
--------------------------------------------------------------------------------
1 | ## 吴恩达 用ChatGPT API构建系统 总结篇
2 |
3 | ## Building Systems with the ChatGPT API
4 |
5 | 本次简短课程涵盖了一系列 ChatGPT 的应用实践,包括处理处理输入、审查输出以及评估等,实现了一个搭建系统的完整流程。
6 |
7 | ### 📚 课程回顾
8 |
9 | 本课程详细介绍了LLM工作原理,包括分词器(tokenizer)等微妙之处、评估用户输入的质量和安全性的方法、使用思维链作为提示词、通过链提示分割任务以及返回用户前检查输出等。
10 |
11 | 本课程还介绍了评估系统长期性能以监控和改进表现的方法。
12 |
13 | 此外,课程也涉及到构建负责任的系统以保证模型提供合理相关的反馈。
14 |
15 | ### 💪🏻 出发~去探索新世界吧~
16 |
17 | 实践是掌握真知的必经之路。开始构建令人激动的应用吧~
18 |
--------------------------------------------------------------------------------
/99~参考资料/2023~吴恩达~《Building Systems with the ChatGPT API》/3.Classification.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "attachments": {},
5 | "cell_type": "markdown",
6 | "id": "63651c26",
7 | "metadata": {},
8 | "source": [
9 | "第三章 评估输入——分类"
10 | ]
11 | },
12 | {
13 | "attachments": {},
14 | "cell_type": "markdown",
15 | "id": "b12f80c9",
16 | "metadata": {},
17 | "source": [
18 | "在本节中,我们将专注于评估输入的任务,这对于确保系统的质量和安全性非常重要。\n",
19 | "\n",
20 | "对于需要处理不同情况下的许多独立指令集的任务,首先对查询类型进行分类,然后根据该分类确定要使用哪些指令会很有好处。\n",
21 | "\n",
22 | "这可以通过定义固定的类别和hard-coding与处理给定类别任务相关的指令来实现。\n",
23 | "\n",
24 | "例如,在构建客户服务助手时,首先对查询类型进行分类,然后根据该分类确定要使用哪些指令可能比较重要。\n",
25 | "\n",
26 | "因此,例如,如果用户要求关闭其帐户,您可能会给出不同的辅助指令,而如果用户询问特定产品,则可能会添加其他产品信息。\n"
27 | ]
28 | },
29 | {
30 | "attachments": {},
31 | "cell_type": "markdown",
32 | "id": "87d9de1d",
33 | "metadata": {},
34 | "source": [
35 | "## Setup\n",
36 | "加载 API_KEY 并封装一个调用 API 的函数"
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": 9,
42 | "id": "55ee24ab",
43 | "metadata": {},
44 | "outputs": [],
45 | "source": [
46 | "import os\n",
47 | "import openai\n",
48 | "from dotenv import load_dotenv, find_dotenv\n",
49 | "_ = load_dotenv(find_dotenv()) # read local .env file\n",
50 | "openai.api_key = os.environ['OPENAI_API_KEY']\n"
51 | ]
52 | },
53 | {
54 | "cell_type": "code",
55 | "execution_count": 2,
56 | "id": "0318b89e",
57 | "metadata": {},
58 | "outputs": [],
59 | "source": [
60 | "def get_completion_from_messages(messages, \n",
61 | " model=\"gpt-3.5-turbo\", \n",
62 | " temperature=0, \n",
63 | " max_tokens=500):\n",
64 | " response = openai.ChatCompletion.create(\n",
65 | " model=model,\n",
66 | " messages=messages,\n",
67 | " temperature=temperature, \n",
68 | " max_tokens=max_tokens,\n",
69 | " )\n",
70 | " return response.choices[0].message[\"content\"]"
71 | ]
72 | },
73 | {
74 | "attachments": {},
75 | "cell_type": "markdown",
76 | "id": "f2b55807",
77 | "metadata": {},
78 | "source": [
79 | "#### 对用户指令进行分类"
80 | ]
81 | },
82 | {
83 | "attachments": {},
84 | "cell_type": "markdown",
85 | "id": "c3216166",
86 | "metadata": {},
87 | "source": [
88 | "在这里,我们有我们的系统消息,它是对整个系统的指导,并且我们正在使用这个分隔符——#。\n",
89 | "\n",
90 | "分隔符只是一种分隔指令或输出不同部分的方式,它有助于模型确定不同的部分。\n",
91 | "\n",
92 | "因此,对于这个例子,我们将使用#作为分隔符。\n",
93 | "\n",
94 | "这是一个很好的分隔符,因为它实际上被表示为一个token。"
95 | ]
96 | },
97 | {
98 | "cell_type": "code",
99 | "execution_count": 3,
100 | "id": "3b406ba8",
101 | "metadata": {},
102 | "outputs": [],
103 | "source": [
104 | "delimiter = \"####\""
105 | ]
106 | },
107 | {
108 | "attachments": {},
109 | "cell_type": "markdown",
110 | "id": "049d0d82",
111 | "metadata": {},
112 | "source": [
113 | "这是我们的系统消息,我们正在以下面的方式询问模型。"
114 | ]
115 | },
116 | {
117 | "cell_type": "code",
118 | "execution_count": 4,
119 | "id": "29e2d170",
120 | "metadata": {},
121 | "outputs": [],
122 | "source": [
123 | "system_message = f\"\"\"\n",
124 | "You will be provided with customer service queries. \\\n",
125 | "The customer service query will be delimited with \\\n",
126 | "{delimiter} characters.\n",
127 | "Classify each query into a primary category \\\n",
128 | "and a secondary category. \n",
129 | "Provide your output in json format with the \\\n",
130 | "keys: primary and secondary.\n",
131 | "\n",
132 | "Primary categories: Billing, Technical Support, \\\n",
133 | "Account Management, or General Inquiry.\n",
134 | "\n",
135 | "Billing secondary categories:\n",
136 | "Unsubscribe or upgrade\n",
137 | "Add a payment method\n",
138 | "Explanation for charge\n",
139 | "Dispute a charge\n",
140 | "\n",
141 | "Technical Support secondary categories:\n",
142 | "General troubleshooting\n",
143 | "Device compatibility\n",
144 | "Software updates\n",
145 | "\n",
146 | "Account Management secondary categories:\n",
147 | "Password reset\n",
148 | "Update personal information\n",
149 | "Close account\n",
150 | "Account security\n",
151 | "\n",
152 | "General Inquiry secondary categories:\n",
153 | "Product information\n",
154 | "Pricing\n",
155 | "Feedback\n",
156 | "Speak to a human\n",
157 | "\n",
158 | "\"\"\""
159 | ]
160 | },
161 | {
162 | "cell_type": "code",
163 | "execution_count": 5,
164 | "id": "61f4b474",
165 | "metadata": {},
166 | "outputs": [],
167 | "source": [
168 | "# 中文 Prompt\n",
169 | "system_message = f\"\"\"\n",
170 | "你将获得客户服务查询。\n",
171 | "每个客户服务查询都将用{delimiter}字符分隔。\n",
172 | "将每个查询分类到一个主要类别和一个次要类别中。\n",
173 | "以JSON格式提供你的输出,包含以下键:primary和secondary。\n",
174 | "\n",
175 | "主要类别:计费(Billing)、技术支持(Technical Support)、账户管理(Account Management)或一般咨询(General Inquiry)。\n",
176 | "\n",
177 | "计费次要类别:\n",
178 | "取消订阅或升级(Unsubscribe or upgrade)\n",
179 | "添加付款方式(Add a payment method)\n",
180 | "收费解释(Explanation for charge)\n",
181 | "争议费用(Dispute a charge)\n",
182 | "\n",
183 | "技术支持次要类别:\n",
184 | "常规故障排除(General troubleshooting)\n",
185 | "设备兼容性(Device compatibility)\n",
186 | "软件更新(Software updates)\n",
187 | "\n",
188 | "账户管理次要类别:\n",
189 | "重置密码(Password reset)\n",
190 | "更新个人信息(Update personal information)\n",
191 | "关闭账户(Close account)\n",
192 | "账户安全(Account security)\n",
193 | "\n",
194 | "一般咨询次要类别:\n",
195 | "产品信息(Product information)\n",
196 | "定价(Pricing)\n",
197 | "反馈(Feedback)\n",
198 | "与人工对话(Speak to a human)\n",
199 | "\n",
200 | "\"\"\""
201 | ]
202 | },
203 | {
204 | "attachments": {},
205 | "cell_type": "markdown",
206 | "id": "e6a932ce",
207 | "metadata": {},
208 | "source": [
209 | "现在我们来看一个用户消息的例子,我们将使用以下内容。"
210 | ]
211 | },
212 | {
213 | "cell_type": "code",
214 | "execution_count": 26,
215 | "id": "2b2df0bf",
216 | "metadata": {},
217 | "outputs": [],
218 | "source": [
219 | "user_message = f\"\"\"\\ \n",
220 | "I want you to delete my profile and all of my user data\"\"\""
221 | ]
222 | },
223 | {
224 | "cell_type": "code",
225 | "execution_count": 6,
226 | "id": "3b8070bf",
227 | "metadata": {},
228 | "outputs": [],
229 | "source": [
230 | "user_message = f\"\"\"\\ \n",
231 | "我希望你删除我的个人资料和所有用户数据。\"\"\""
232 | ]
233 | },
234 | {
235 | "attachments": {},
236 | "cell_type": "markdown",
237 | "id": "3a2c1cf0",
238 | "metadata": {},
239 | "source": [
240 | "将这个消息格式化为一个消息列表,系统消息和用户消息使用####\"进行分隔。\n",
241 | "\n",
242 | "让我们想一想,作为人类,这句话什么意思:\"我想让您删除我的个人资料。\"\n",
243 | "\n",
244 | "这句话看上去属于\"Account Management\"类别,也许是属于\"Close account\"这一项。"
245 | ]
246 | },
247 | {
248 | "cell_type": "code",
249 | "execution_count": 7,
250 | "id": "6e2b9049",
251 | "metadata": {},
252 | "outputs": [],
253 | "source": [
254 | "messages = [ \n",
255 | "{'role':'system', \n",
256 | " 'content': system_message}, \n",
257 | "{'role':'user', \n",
258 | " 'content': f\"{delimiter}{user_message}{delimiter}\"}, \n",
259 | "]"
260 | ]
261 | },
262 | {
263 | "attachments": {},
264 | "cell_type": "markdown",
265 | "id": "4b295207",
266 | "metadata": {},
267 | "source": [
268 | "让我们看看模型是如何思考的\n",
269 | "\n",
270 | "模型的分类是\"Account Management\"作为\"primary\",\"Close account\"作为\"secondary\"。\n",
271 | "\n",
272 | "请求结构化输出(如JSON)的好处是,您可以轻松地将其读入某个对象中,\n",
273 | "\n",
274 | "例如Python中的字典,或者如果您使用其他语言,则可以使用其他对象作为输入到后续步骤中。"
275 | ]
276 | },
277 | {
278 | "cell_type": "code",
279 | "execution_count": 10,
280 | "id": "77328388",
281 | "metadata": {},
282 | "outputs": [
283 | {
284 | "name": "stdout",
285 | "output_type": "stream",
286 | "text": [
287 | "{\n",
288 | " \"primary\": \"账户管理\",\n",
289 | " \"secondary\": \"关闭账户\"\n",
290 | "}\n"
291 | ]
292 | }
293 | ],
294 | "source": [
295 | "response = get_completion_from_messages(messages)\n",
296 | "print(response)"
297 | ]
298 | },
299 | {
300 | "attachments": {},
301 | "cell_type": "markdown",
302 | "id": "2f6b353b",
303 | "metadata": {},
304 | "source": [
305 | "这是另一个用户消息: \"告诉我更多关于你们的平板电视\"\n",
306 | "\n",
307 | "我们只是有相同的消息列表,模型的响应,然后我们打印它。\n",
308 | "\n",
309 | "结果这里是我们的第二个分类,看起来应该是正确的。"
310 | ]
311 | },
312 | {
313 | "cell_type": "code",
314 | "execution_count": 31,
315 | "id": "edf8fbe9",
316 | "metadata": {},
317 | "outputs": [
318 | {
319 | "name": "stdout",
320 | "output_type": "stream",
321 | "text": [
322 | "{\n",
323 | " \"primary\": \"General Inquiry\",\n",
324 | " \"secondary\": \"Product information\"\n",
325 | "}\n"
326 | ]
327 | }
328 | ],
329 | "source": [
330 | "user_message = f\"\"\"\\\n",
331 | "Tell me more about your flat screen tvs\"\"\"\n",
332 | "messages = [ \n",
333 | "{'role':'system', \n",
334 | " 'content': system_message}, \n",
335 | "{'role':'user', \n",
336 | " 'content': f\"{delimiter}{user_message}{delimiter}\"}, \n",
337 | "] \n",
338 | "response = get_completion_from_messages(messages)\n",
339 | "print(response)"
340 | ]
341 | },
342 | {
343 | "cell_type": "code",
344 | "execution_count": 12,
345 | "id": "f1d738e1",
346 | "metadata": {},
347 | "outputs": [
348 | {
349 | "name": "stdout",
350 | "output_type": "stream",
351 | "text": [
352 | "以下是针对平板电脑的一般咨询:\n",
353 | "\n",
354 | "{\n",
355 | " \"primary\": \"General Inquiry\",\n",
356 | " \"secondary\": \"Product information\"\n",
357 | "}\n",
358 | "\n",
359 | "如果您有任何特定的问题或需要更详细的信息,请告诉我,我会尽力回答。\n"
360 | ]
361 | }
362 | ],
363 | "source": [
364 | "user_message = f\"\"\"\\\n",
365 | "告诉我更多有关你们的平板电脑的信息\"\"\"\n",
366 | "messages = [ \n",
367 | "{'role':'system', \n",
368 | " 'content': system_message}, \n",
369 | "{'role':'user', \n",
370 | " 'content': f\"{delimiter}{user_message}{delimiter}\"}, \n",
371 | "] \n",
372 | "response = get_completion_from_messages(messages)\n",
373 | "print(response)"
374 | ]
375 | },
376 | {
377 | "attachments": {},
378 | "cell_type": "markdown",
379 | "id": "8f87f68d",
380 | "metadata": {},
381 | "source": [
382 | "所以总的来说,根据客户咨询的分类,我们现在可以提供一套更具体的指令来处理后续步骤。\n",
383 | "\n",
384 | "在这种情况下,我们可能会添加关于电视的额外信息,而不同情况下,我们可能希望提供关闭账户的链接或类似的内容。\n",
385 | "\n",
386 | "我们将在以后的视频中了解更多有关处理输入的不同方法。\n",
387 | "\n",
388 | "在下一个视频中,我们将探讨更多评估输入的方法,特别是确保用户以负责任的方式使用系统的方法。"
389 | ]
390 | }
391 | ],
392 | "metadata": {
393 | "kernelspec": {
394 | "display_name": "Python 3 (ipykernel)",
395 | "language": "python",
396 | "name": "python3"
397 | },
398 | "language_info": {
399 | "codemirror_mode": {
400 | "name": "ipython",
401 | "version": 3
402 | },
403 | "file_extension": ".py",
404 | "mimetype": "text/x-python",
405 | "name": "python",
406 | "nbconvert_exporter": "python",
407 | "pygments_lexer": "ipython3",
408 | "version": "3.10.11"
409 | }
410 | },
411 | "nbformat": 4,
412 | "nbformat_minor": 5
413 | }
414 |
--------------------------------------------------------------------------------
/99~参考资料/2023~吴恩达~《Building Systems with the ChatGPT API》/5.Chain of Thought Reasoning.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "attachments": {},
5 | "cell_type": "markdown",
6 | "metadata": {},
7 | "source": [
8 | "# L4: 处理输入: 思维链推理"
9 | ]
10 | },
11 | {
12 | "attachments": {},
13 | "cell_type": "markdown",
14 | "metadata": {},
15 | "source": [
16 | "在本节中,我们将专注于处理输入的任务,即通过一系列步骤生成有用输出的任务。\n",
17 | "\n",
18 | "有时,模型在回答特定问题之前需要详细推理问题,如果您参加了我们之前的课程,您将看到许多这样的例子。有时,模型可能会通过匆忙得出错误的结论而出现推理错误,因此我们可以重新构思查询,要求模型在提供最终答案之前提供一系列相关的推理步骤,以便它可以更长时间、更有方法地思考问题。\n",
19 | "\n",
20 | "通常,我们称这种要求模型逐步推理问题的策略为思维链推理。"
21 | ]
22 | },
23 | {
24 | "attachments": {},
25 | "cell_type": "markdown",
26 | "metadata": {},
27 | "source": [
28 | "## 设置\n",
29 | "#### 加载 API key 和相关的 Python 库.\n",
30 | "在这门课程中,我们提供了一些代码,帮助你加载OpenAI API key。"
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": 1,
36 | "metadata": {},
37 | "outputs": [],
38 | "source": [
39 | "import os\n",
40 | "import openai\n",
41 | "from dotenv import load_dotenv, find_dotenv\n",
42 | "_ = load_dotenv(find_dotenv()) # read local .env file\n",
43 | "\n",
44 | "openai.api_key = os.environ['OPENAI_API_KEY']\n"
45 | ]
46 | },
47 | {
48 | "cell_type": "code",
49 | "execution_count": 2,
50 | "metadata": {},
51 | "outputs": [],
52 | "source": [
53 | "def get_completion_from_messages(messages, \n",
54 | " model=\"gpt-3.5-turbo\", \n",
55 | " temperature=0, \n",
56 | " max_tokens=500):\n",
57 | " response = openai.ChatCompletion.create(\n",
58 | " model=model,\n",
59 | " messages=messages,\n",
60 | " temperature=temperature, \n",
61 | " max_tokens=max_tokens, \n",
62 | " )\n",
63 | " return response.choices[0].message[\"content\"]"
64 | ]
65 | },
66 | {
67 | "attachments": {},
68 | "cell_type": "markdown",
69 | "metadata": {},
70 | "source": [
71 | "## 思维链提示"
72 | ]
73 | },
74 | {
75 | "attachments": {},
76 | "cell_type": "markdown",
77 | "metadata": {},
78 | "source": [
79 | "因此,我们在这里要求模型在得出结论之前推理答案。\n"
80 | ]
81 | },
82 | {
83 | "cell_type": "code",
84 | "execution_count": 3,
85 | "metadata": {},
86 | "outputs": [],
87 | "source": [
88 | "delimiter = \"####\"\n",
89 | "system_message = f\"\"\"\n",
90 | "Follow these steps to answer the customer queries.\n",
91 | "The customer query will be delimited with four hashtags,\\\n",
92 | "i.e. {delimiter}. \n",
93 | "\n",
94 | "Step 1:{delimiter} First decide whether the user is \\\n",
95 | "asking a question about a specific product or products. \\\n",
96 | "Product cateogry doesn't count. \n",
97 | "\n",
98 | "Step 2:{delimiter} If the user is asking about \\\n",
99 | "specific products, identify whether \\\n",
100 | "the products are in the following list.\n",
101 | "All available products: \n",
102 | "1. Product: TechPro Ultrabook\n",
103 | " Category: Computers and Laptops\n",
104 | " Brand: TechPro\n",
105 | " Model Number: TP-UB100\n",
106 | " Warranty: 1 year\n",
107 | " Rating: 4.5\n",
108 | " Features: 13.3-inch display, 8GB RAM, 256GB SSD, Intel Core i5 processor\n",
109 | " Description: A sleek and lightweight ultrabook for everyday use.\n",
110 | " Price: $799.99\n",
111 | "\n",
112 | "2. Product: BlueWave Gaming Laptop\n",
113 | " Category: Computers and Laptops\n",
114 | " Brand: BlueWave\n",
115 | " Model Number: BW-GL200\n",
116 | " Warranty: 2 years\n",
117 | " Rating: 4.7\n",
118 | " Features: 15.6-inch display, 16GB RAM, 512GB SSD, NVIDIA GeForce RTX 3060\n",
119 | " Description: A high-performance gaming laptop for an immersive experience.\n",
120 | " Price: $1199.99\n",
121 | "\n",
122 | "3. Product: PowerLite Convertible\n",
123 | " Category: Computers and Laptops\n",
124 | " Brand: PowerLite\n",
125 | " Model Number: PL-CV300\n",
126 | " Warranty: 1 year\n",
127 | " Rating: 4.3\n",
128 | " Features: 14-inch touchscreen, 8GB RAM, 256GB SSD, 360-degree hinge\n",
129 | " Description: A versatile convertible laptop with a responsive touchscreen.\n",
130 | " Price: $699.99\n",
131 | "\n",
132 | "4. Product: TechPro Desktop\n",
133 | " Category: Computers and Laptops\n",
134 | " Brand: TechPro\n",
135 | " Model Number: TP-DT500\n",
136 | " Warranty: 1 year\n",
137 | " Rating: 4.4\n",
138 | " Features: Intel Core i7 processor, 16GB RAM, 1TB HDD, NVIDIA GeForce GTX 1660\n",
139 | " Description: A powerful desktop computer for work and play.\n",
140 | " Price: $999.99\n",
141 | "\n",
142 | "5. Product: BlueWave Chromebook\n",
143 | " Category: Computers and Laptops\n",
144 | " Brand: BlueWave\n",
145 | " Model Number: BW-CB100\n",
146 | " Warranty: 1 year\n",
147 | " Rating: 4.1\n",
148 | " Features: 11.6-inch display, 4GB RAM, 32GB eMMC, Chrome OS\n",
149 | " Description: A compact and affordable Chromebook for everyday tasks.\n",
150 | " Price: $249.99\n",
151 | "\n",
152 | "Step 3:{delimiter} If the message contains products \\\n",
153 | "in the list above, list any assumptions that the \\\n",
154 | "user is making in their \\\n",
155 | "message e.g. that Laptop X is bigger than \\\n",
156 | "Laptop Y, or that Laptop Z has a 2 year warranty.\n",
157 | "\n",
158 | "Step 4:{delimiter}: If the user made any assumptions, \\\n",
159 | "figure out whether the assumption is true based on your \\\n",
160 | "product information. \n",
161 | "\n",
162 | "Step 5:{delimiter}: First, politely correct the \\\n",
163 | "customer's incorrect assumptions if applicable. \\\n",
164 | "Only mention or reference products in the list of \\\n",
165 | "5 available products, as these are the only 5 \\\n",
166 | "products that the store sells. \\\n",
167 | "Answer the customer in a friendly tone.\n",
168 | "\n",
169 | "Use the following format:\n",
170 | "Step 1:{delimiter} \n",
171 | "Step 2:{delimiter} \n",
172 | "Step 3:{delimiter} \n",
173 | "Step 4:{delimiter} \n",
174 | "Response to user:{delimiter} \n",
175 | "\n",
176 | "Make sure to include {delimiter} to separate every step.\n",
177 | "\"\"\""
178 | ]
179 | },
180 | {
181 | "cell_type": "code",
182 | "execution_count": null,
183 | "metadata": {},
184 | "outputs": [
185 | {
186 | "name": "stdout",
187 | "output_type": "stream",
188 | "text": [
189 | "Step 1:#### The user is asking a question about two specific products, the BlueWave Chromebook and the TechPro Desktop.\n",
190 | "Step 2:#### The prices of the two products are as follows:\n",
191 | "- BlueWave Chromebook: $249.99\n",
192 | "- TechPro Desktop: $999.99\n",
193 | "Step 3:#### The user is assuming that the BlueWave Chromebook is more expensive than the TechPro Desktop.\n",
194 | "Step 4:#### The assumption is incorrect. The TechPro Desktop is actually more expensive than the BlueWave Chromebook.\n",
195 | "Response to user:#### The BlueWave Chromebook is actually less expensive than the TechPro Desktop. The BlueWave Chromebook costs $249.99 while the TechPro Desktop costs $999.99.\n"
196 | ]
197 | }
198 | ],
199 | "source": [
200 | "user_message = f\"\"\"\n",
201 | "by how much is the BlueWave Chromebook more expensive \\\n",
202 | "than the TechPro Desktop\"\"\"\n",
203 | "\n",
204 | "messages = [ \n",
205 | "{'role':'system', \n",
206 | " 'content': system_message}, \n",
207 | "{'role':'user', \n",
208 | " 'content': f\"{delimiter}{user_message}{delimiter}\"}, \n",
209 | "] \n",
210 | "\n",
211 | "response = get_completion_from_messages(messages)\n",
212 | "print(response)"
213 | ]
214 | },
215 | {
216 | "cell_type": "code",
217 | "execution_count": null,
218 | "metadata": {},
219 | "outputs": [
220 | {
221 | "name": "stdout",
222 | "output_type": "stream",
223 | "text": [
224 | "Step 1:#### The user is asking if the store sells TVs.\n",
225 | "Step 2:#### The list of available products does not include any TVs.\n",
226 | "Response to user:#### I'm sorry, but we do not sell TVs at this store. Our available products include computers and laptops.\n"
227 | ]
228 | }
229 | ],
230 | "source": [
231 | "user_message = f\"\"\"\n",
232 | "do you sell tvs\"\"\"\n",
233 | "messages = [ \n",
234 | "{'role':'system', \n",
235 | " 'content': system_message}, \n",
236 | "{'role':'user', \n",
237 | " 'content': f\"{delimiter}{user_message}{delimiter}\"}, \n",
238 | "] \n",
239 | "response = get_completion_from_messages(messages)\n",
240 | "print(response)"
241 | ]
242 | },
243 | {
244 | "cell_type": "code",
245 | "execution_count": 4,
246 | "metadata": {},
247 | "outputs": [],
248 | "source": [
249 | "delimiter = \"####\"\n",
250 | "system_message = f\"\"\"\n",
251 | "请按照以下步骤回答客户的查询。客户的查询将以四个井号(#)分隔,即 {delimiter}。\n",
252 | "\n",
253 | "步骤 1:{delimiter} 首先确定用户是否正在询问有关特定产品或产品的问题。产品类别不计入范围。\n",
254 | "\n",
255 | "步骤 2:{delimiter} 如果用户询问特定产品,请确认产品是否在以下列表中。所有可用产品:\n",
256 | "\n",
257 | "产品:TechPro超极本\n",
258 | "类别:计算机和笔记本电脑\n",
259 | "品牌:TechPro\n",
260 | "型号:TP-UB100\n",
261 | "保修期:1年\n",
262 | "评分:4.5\n",
263 | "特点:13.3英寸显示屏,8GB RAM,256GB SSD,Intel Core i5处理器\n",
264 | "描述:一款适用于日常使用的时尚轻便的超极本。\n",
265 | "价格:$799.99\n",
266 | "\n",
267 | "产品:BlueWave游戏笔记本电脑\n",
268 | "类别:计算机和笔记本电脑\n",
269 | "品牌:BlueWave\n",
270 | "型号:BW-GL200\n",
271 | "保修期:2年\n",
272 | "评分:4.7\n",
273 | "特点:15.6英寸显示屏,16GB RAM,512GB SSD,NVIDIA GeForce RTX 3060\n",
274 | "描述:一款高性能的游戏笔记本电脑,提供沉浸式体验。\n",
275 | "价格:$1199.99\n",
276 | "\n",
277 | "产品:PowerLite可转换笔记本电脑\n",
278 | "类别:计算机和笔记本电脑\n",
279 | "品牌:PowerLite\n",
280 | "型号:PL-CV300\n",
281 | "保修期:1年\n",
282 | "评分:4.3\n",
283 | "特点:14英寸触摸屏,8GB RAM,256GB SSD,360度铰链\n",
284 | "描述:一款多功能可转换笔记本电脑,具有响应触摸屏。\n",
285 | "价格:$699.99\n",
286 | "\n",
287 | "产品:TechPro台式电脑\n",
288 | "类别:计算机和笔记本电脑\n",
289 | "品牌:TechPro\n",
290 | "型号:TP-DT500\n",
291 | "保修期:1年\n",
292 | "评分:4.4\n",
293 | "特点:Intel Core i7处理器,16GB RAM,1TB HDD,NVIDIA GeForce GTX 1660\n",
294 | "描述:一款功能强大的台式电脑,适用于工作和娱乐。\n",
295 | "价格:$999.99\n",
296 | "\n",
297 | "产品:BlueWave Chromebook\n",
298 | "类别:计算机和笔记本电脑\n",
299 | "品牌:BlueWave\n",
300 | "型号:BW-CB100\n",
301 | "保修期:1年\n",
302 | "评分:4.1\n",
303 | "特点:11.6英寸显示屏,4GB RAM,32GB eMMC,Chrome OS\n",
304 | "描述:一款紧凑而价格实惠的Chromebook,适用于日常任务。\n",
305 | "价格:$249.99\n",
306 | "\n",
307 | "步骤 3:{delimiter} 如果消息中包含上述列表中的产品,请列出用户在消息中做出的任何假设,例如笔记本电脑 X 比笔记本电脑 Y 大,或者笔记本电脑 Z 有 2 年保修期。\n",
308 | "\n",
309 | "步骤 4:{delimiter} 如果用户做出了任何假设,请根据产品信息确定假设是否正确。\n",
310 | "\n",
311 | "步骤 5:{delimiter} 如果用户有任何错误的假设,请先礼貌地纠正客户的错误假设(如果适用)。只提及或引用可用产品列表中的产品,因为这是商店销售的唯一五款产品。以友好的口吻回答客户。\n",
312 | "\n",
313 | "使用以下格式回答问题:\n",
314 | "步骤 1:{delimiter} <步骤 1的推理>\n",
315 | "步骤 2:{delimiter} <步骤 2 的推理>\n",
316 | "步骤 3:{delimiter} <步骤 3 的推理>\n",
317 | "步骤 4:{delimiter} <步骤 4 的推理>\n",
318 | "回复客户:{delimiter} <回复客户的内容>\n",
319 | "\n",
320 | "请确保在每个步骤之间使用 {delimiter} 进行分隔。\n",
321 | "\"\"\""
322 | ]
323 | },
324 | {
325 | "cell_type": "code",
326 | "execution_count": 5,
327 | "metadata": {},
328 | "outputs": [
329 | {
330 | "name": "stdout",
331 | "output_type": "stream",
332 | "text": [
333 | "步骤 1:#### 确认用户正在询问有关特定产品的问题。\n",
334 | "\n",
335 | "步骤 2:#### 用户询问 BlueWave Chromebook 和 TechPro 台式电脑之间的价格差异。\n",
336 | "\n",
337 | "步骤 3:#### 用户假设 BlueWave Chromebook 的价格高于 TechPro 台式电脑。\n",
338 | "\n",
339 | "步骤 4:#### 用户的假设是正确的。BlueWave Chromebook 的价格为 $249.99,而 TechPro 台式电脑的价格为 $999.99,因此 BlueWave Chromebook 的价格比 TechPro 台式电脑低 $750。\n",
340 | "\n",
341 | "回复客户:#### BlueWave Chromebook 比 TechPro 台式电脑便宜 $750。\n"
342 | ]
343 | }
344 | ],
345 | "source": [
346 | "user_message = f\"\"\"BlueWave Chromebook 比 TechPro 台式电脑贵多少?\"\"\"\n",
347 | "\n",
348 | "messages = [ \n",
349 | "{'role':'system', \n",
350 | " 'content': system_message}, \n",
351 | "{'role':'user', \n",
352 | " 'content': f\"{delimiter}{user_message}{delimiter}\"}, \n",
353 | "] \n",
354 | "\n",
355 | "response = get_completion_from_messages(messages)\n",
356 | "print(response)"
357 | ]
358 | },
359 | {
360 | "cell_type": "code",
361 | "execution_count": 9,
362 | "metadata": {},
363 | "outputs": [
364 | {
365 | "name": "stdout",
366 | "output_type": "stream",
367 | "text": [
368 | "步骤 1:#### 首先确定用户是否正在询问有关特定产品或产品的问题。产品类别不计入范围。\n",
369 | "\n",
370 | "步骤 2:#### 如果用户询问特定产品,请确认产品是否在以下列表中。所有可用产品:\n",
371 | "\n",
372 | "我们很抱歉,我们商店不出售电视机。\n",
373 | "\n",
374 | "步骤 3:#### 如果消息中包含上述列表中的产品,请列出用户在消息中做出的任何假设,例如笔记本电脑 X 比笔记本电脑 Y 大,或者笔记本电脑 Z 有 2 年保修期。\n",
375 | "\n",
376 | "N/A\n",
377 | "\n",
378 | "步骤 4:#### 如果用户做出了任何假设,请根据产品信息确定假设是否正确。\n",
379 | "\n",
380 | "N/A\n",
381 | "\n",
382 | "回复客户:#### 我们很抱歉,我们商店不出售电视机。\n"
383 | ]
384 | }
385 | ],
386 | "source": [
387 | "user_message = f\"\"\"你有电视机么\"\"\"\n",
388 | "messages = [ \n",
389 | "{'role':'system', \n",
390 | " 'content': system_message}, \n",
391 | "{'role':'user', \n",
392 | " 'content': f\"{delimiter}{user_message}{delimiter}\"}, \n",
393 | "] \n",
394 | "response = get_completion_from_messages(messages)\n",
395 | "print(response)"
396 | ]
397 | },
398 | {
399 | "attachments": {},
400 | "cell_type": "markdown",
401 | "metadata": {},
402 | "source": [
403 | "## 内心独白"
404 | ]
405 | },
406 | {
407 | "attachments": {},
408 | "cell_type": "markdown",
409 | "metadata": {},
410 | "source": [
411 | "对于某些应用程序,模型用于得出最终答案的推理过程可能不适合与用户共享。例如,在辅导应用程序中,我们可能希望鼓励学生自己解决问题,但模型对学生解决方案的推理过程可能会揭示答案。\n",
412 | "\n",
413 | "内心独白是一种可以用来缓解这种情况的策略,这只是一种隐藏模型推理过程的高级方法。\n",
414 | "\n",
415 | "内心独白的想法是指示模型将输出的部分放在不会透露答案的方式中,以便用户无法看到完整的推理过程。旨在将它们隐藏在一个结构化的格式中,使得传递它们变得容易。然后,在向用户呈现输出之前,输出被传递,只有部分输出是可见的。\n"
416 | ]
417 | },
418 | {
419 | "cell_type": "code",
420 | "execution_count": 10,
421 | "metadata": {},
422 | "outputs": [
423 | {
424 | "name": "stdout",
425 | "output_type": "stream",
426 | "text": [
427 | "我们很抱歉,我们商店不出售电视机。\n"
428 | ]
429 | }
430 | ],
431 | "source": [
432 | "try:\n",
433 | " final_response = response.split(delimiter)[-1].strip()\n",
434 | "except Exception as e:\n",
435 | " final_response = \"Sorry, I'm having trouble right now, please try asking another question.\"\n",
436 | " \n",
437 | "print(final_response)"
438 | ]
439 | }
440 | ],
441 | "metadata": {
442 | "kernelspec": {
443 | "display_name": "Python 3",
444 | "language": "python",
445 | "name": "python3"
446 | },
447 | "language_info": {
448 | "codemirror_mode": {
449 | "name": "ipython",
450 | "version": 3
451 | },
452 | "file_extension": ".py",
453 | "mimetype": "text/x-python",
454 | "name": "python",
455 | "nbconvert_exporter": "python",
456 | "pygments_lexer": "ipython3",
457 | "version": "3.10.11"
458 | },
459 | "orig_nbformat": 4
460 | },
461 | "nbformat": 4,
462 | "nbformat_minor": 2
463 | }
464 |
--------------------------------------------------------------------------------
/99~参考资料/2023~吴恩达~《Building Systems with the ChatGPT API》/7.Check Outputs.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "f99b8a44",
6 | "metadata": {},
7 | "source": [
8 | "# L6: 检查结果\n",
9 | "比较简单轻松的一节"
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": 1,
15 | "id": "5daec1c7",
16 | "metadata": {},
17 | "outputs": [],
18 | "source": [
19 | "import os\n",
20 | "import openai\n",
21 | "\n",
22 | "# from dotenv import load_dotenv, find_dotenv\n",
23 | "# _ = load_dotenv(find_dotenv()) # 读取本地的.env环境文件\n",
24 | "\n",
25 | "openai.api_key = 'sk-xxxxxxxxxxxx' #更换成你自己的key"
26 | ]
27 | },
28 | {
29 | "cell_type": "code",
30 | "execution_count": 2,
31 | "id": "9c40b32d",
32 | "metadata": {},
33 | "outputs": [],
34 | "source": [
35 | "def get_completion_from_messages(messages, model=\"gpt-3.5-turbo\", temperature=0, max_tokens=500):\n",
36 | " response = openai.ChatCompletion.create(\n",
37 | " model=model,\n",
38 | " messages=messages,\n",
39 | " temperature=temperature, \n",
40 | " max_tokens=max_tokens, \n",
41 | " )\n",
42 | " return response.choices[0].message[\"content\"]"
43 | ]
44 | },
45 | {
46 | "cell_type": "markdown",
47 | "id": "59f69c2e",
48 | "metadata": {},
49 | "source": [
50 | "### 检查输出是否有潜在的有害内容\n",
51 | "重要的就是一个moderation"
52 | ]
53 | },
54 | {
55 | "cell_type": "code",
56 | "execution_count": 4,
57 | "id": "943f5396",
58 | "metadata": {},
59 | "outputs": [
60 | {
61 | "name": "stdout",
62 | "output_type": "stream",
63 | "text": [
64 | "{\n",
65 | " \"categories\": {\n",
66 | " \"hate\": false,\n",
67 | " \"hate/threatening\": false,\n",
68 | " \"self-harm\": false,\n",
69 | " \"sexual\": false,\n",
70 | " \"sexual/minors\": false,\n",
71 | " \"violence\": false,\n",
72 | " \"violence/graphic\": false\n",
73 | " },\n",
74 | " \"category_scores\": {\n",
75 | " \"hate\": 2.6680607e-06,\n",
76 | " \"hate/threatening\": 1.2194433e-08,\n",
77 | " \"self-harm\": 8.294434e-07,\n",
78 | " \"sexual\": 3.41087e-05,\n",
79 | " \"sexual/minors\": 1.5462567e-07,\n",
80 | " \"violence\": 6.3285606e-06,\n",
81 | " \"violence/graphic\": 2.9102332e-06\n",
82 | " },\n",
83 | " \"flagged\": false\n",
84 | "}\n"
85 | ]
86 | }
87 | ],
88 | "source": [
89 | "final_response_to_customer = f\"\"\"\n",
90 | "SmartX ProPhone有一个6.1英寸的显示屏,128GB存储、1200万像素的双摄像头,以及5G。FotoSnap单反相机有一个2420万像素的传感器,1080p视频,3英寸LCD和 \n",
91 | "可更换的镜头。我们有各种电视,包括CineView 4K电视,55英寸显示屏,4K分辨率、HDR,以及智能电视功能。我们也有SoundMax家庭影院系统,具有5.1声道,1000W输出,无线 \n",
92 | "重低音扬声器和蓝牙。关于这些产品或我们提供的任何其他产品您是否有任何具体问题?\n",
93 | "\"\"\"\n",
94 | "# Moderation是OpenAI的内容审核函数,用于检测这段内容的危害含量\n",
95 | "\n",
96 | "response = openai.Moderation.create(\n",
97 | " input=final_response_to_customer\n",
98 | ")\n",
99 | "moderation_output = response[\"results\"][0]\n",
100 | "print(moderation_output)"
101 | ]
102 | },
103 | {
104 | "cell_type": "markdown",
105 | "id": "f57f8dad",
106 | "metadata": {},
107 | "source": [
108 | "### 检查输出结果是否与提供的产品信息相符合"
109 | ]
110 | },
111 | {
112 | "cell_type": "code",
113 | "execution_count": 7,
114 | "id": "552e3d8c",
115 | "metadata": {},
116 | "outputs": [
117 | {
118 | "name": "stdout",
119 | "output_type": "stream",
120 | "text": [
121 | "Y\n"
122 | ]
123 | }
124 | ],
125 | "source": [
126 | "# 这是一段电子产品相关的信息\n",
127 | "system_message = f\"\"\"\n",
128 | "You are an assistant that evaluates whether \\\n",
129 | "customer service agent responses sufficiently \\\n",
130 | "answer customer questions, and also validates that \\\n",
131 | "all the facts the assistant cites from the product \\\n",
132 | "information are correct.\n",
133 | "The product information and user and customer \\\n",
134 | "service agent messages will be delimited by \\\n",
135 | "3 backticks, i.e. ```.\n",
136 | "Respond with a Y or N character, with no punctuation:\n",
137 | "Y - if the output sufficiently answers the question \\\n",
138 | "AND the response correctly uses product information\n",
139 | "N - otherwise\n",
140 | "\n",
141 | "Output a single letter only.\n",
142 | "\"\"\"\n",
143 | "\n",
144 | "#这是顾客的提问\n",
145 | "customer_message = f\"\"\"\n",
146 | "tell me about the smartx pro phone and \\\n",
147 | "the fotosnap camera, the dslr one. \\\n",
148 | "Also tell me about your tvs\"\"\"\n",
149 | "product_information = \"\"\"{ \"name\": \"SmartX ProPhone\", \"category\": \"Smartphones and Accessories\", \"brand\": \"SmartX\", \"model_number\": \"SX-PP10\", \"warranty\": \"1 year\", \"rating\": 4.6, \"features\": [ \"6.1-inch display\", \"128GB storage\", \"12MP dual camera\", \"5G\" ], \"description\": \"A powerful smartphone with advanced camera features.\", \"price\": 899.99 } { \"name\": \"FotoSnap DSLR Camera\", \"category\": \"Cameras and Camcorders\", \"brand\": \"FotoSnap\", \"model_number\": \"FS-DSLR200\", \"warranty\": \"1 year\", \"rating\": 4.7, \"features\": [ \"24.2MP sensor\", \"1080p video\", \"3-inch LCD\", \"Interchangeable lenses\" ], \"description\": \"Capture stunning photos and videos with this versatile DSLR camera.\", \"price\": 599.99 } { \"name\": \"CineView 4K TV\", \"category\": \"Televisions and Home Theater Systems\", \"brand\": \"CineView\", \"model_number\": \"CV-4K55\", \"warranty\": \"2 years\", \"rating\": 4.8, \"features\": [ \"55-inch display\", \"4K resolution\", \"HDR\", \"Smart TV\" ], \"description\": \"A stunning 4K TV with vibrant colors and smart features.\", \"price\": 599.99 } { \"name\": \"SoundMax Home Theater\", \"category\": \"Televisions and Home Theater Systems\", \"brand\": \"SoundMax\", \"model_number\": \"SM-HT100\", \"warranty\": \"1 year\", \"rating\": 4.4, \"features\": [ \"5.1 channel\", \"1000W output\", \"Wireless subwoofer\", \"Bluetooth\" ], \"description\": \"A powerful home theater system for an immersive audio experience.\", \"price\": 399.99 } { \"name\": \"CineView 8K TV\", \"category\": \"Televisions and Home Theater Systems\", \"brand\": \"CineView\", \"model_number\": \"CV-8K65\", \"warranty\": \"2 years\", \"rating\": 4.9, \"features\": [ \"65-inch display\", \"8K resolution\", \"HDR\", \"Smart TV\" ], \"description\": \"Experience the future of television with this stunning 8K TV.\", \"price\": 2999.99 } { \"name\": \"SoundMax Soundbar\", \"category\": \"Televisions and Home Theater Systems\", \"brand\": \"SoundMax\", \"model_number\": \"SM-SB50\", \"warranty\": \"1 year\", \"rating\": 4.3, \"features\": [ \"2.1 channel\", \"300W output\", \"Wireless subwoofer\", \"Bluetooth\" ], \"description\": \"Upgrade your TV's audio with this sleek and powerful soundbar.\", \"price\": 199.99 } { \"name\": \"CineView OLED TV\", \"category\": \"Televisions and Home Theater Systems\", \"brand\": \"CineView\", \"model_number\": \"CV-OLED55\", \"warranty\": \"2 years\", \"rating\": 4.7, \"features\": [ \"55-inch display\", \"4K resolution\", \"HDR\", \"Smart TV\" ], \"description\": \"Experience true blacks and vibrant colors with this OLED TV.\", \"price\": 1499.99 }\"\"\"\n",
150 | "\n",
151 | "q_a_pair = f\"\"\"\n",
152 | "Customer message: ```{customer_message}```\n",
153 | "Product information: ```{product_information}```\n",
154 | "Agent response: ```{final_response_to_customer}```\n",
155 | "\n",
156 | "Does the response use the retrieved information correctly?\n",
157 | "Does the response sufficiently answer the question?\n",
158 | "\n",
159 | "Output Y or N\n",
160 | "\"\"\"\n",
161 | "#判断相关性\n",
162 | "messages = [\n",
163 | " {'role': 'system', 'content': system_message},\n",
164 | " {'role': 'user', 'content': q_a_pair}\n",
165 | "]\n",
166 | "\n",
167 | "response = get_completion_from_messages(messages, max_tokens=1)\n",
168 | "print(response)"
169 | ]
170 | },
171 | {
172 | "cell_type": "code",
173 | "execution_count": 6,
174 | "id": "afb1b82f",
175 | "metadata": {},
176 | "outputs": [
177 | {
178 | "name": "stdout",
179 | "output_type": "stream",
180 | "text": [
181 | "N\n"
182 | ]
183 | }
184 | ],
185 | "source": [
186 | "another_response = \"life is like a box of chocolates\"\n",
187 | "q_a_pair = f\"\"\"\n",
188 | "Customer message: ```{customer_message}```\n",
189 | "Product information: ```{product_information}```\n",
190 | "Agent response: ```{another_response}```\n",
191 | "\n",
192 | "Does the response use the retrieved information correctly?\n",
193 | "Does the response sufficiently answer the question?\n",
194 | "\n",
195 | "Output Y or N\n",
196 | "\"\"\"\n",
197 | "messages = [\n",
198 | " {'role': 'system', 'content': system_message},\n",
199 | " {'role': 'user', 'content': q_a_pair}\n",
200 | "]\n",
201 | "\n",
202 | "response = get_completion_from_messages(messages)\n",
203 | "print(response)"
204 | ]
205 | }
206 | ],
207 | "metadata": {
208 | "kernelspec": {
209 | "display_name": "Python 3 (ipykernel)",
210 | "language": "python",
211 | "name": "python3"
212 | },
213 | "language_info": {
214 | "codemirror_mode": {
215 | "name": "ipython",
216 | "version": 3
217 | },
218 | "file_extension": ".py",
219 | "mimetype": "text/x-python",
220 | "name": "python",
221 | "nbconvert_exporter": "python",
222 | "pygments_lexer": "ipython3",
223 | "version": "3.10.9"
224 | }
225 | },
226 | "nbformat": 4,
227 | "nbformat_minor": 5
228 | }
229 |
--------------------------------------------------------------------------------
/99~参考资料/2023~吴恩达~《Building Systems with the ChatGPT API》/products.json:
--------------------------------------------------------------------------------
1 | {"TechPro Ultrabook": {"name": "TechPro Ultrabook", "category": "Computers and Laptops", "brand": "TechPro", "model_number": "TP-UB100", "warranty": "1 year", "rating": 4.5, "features": ["13.3-inch display", "8GB RAM", "256GB SSD", "Intel Core i5 processor"], "description": "A sleek and lightweight ultrabook for everyday use.", "price": 799.99}, "BlueWave Gaming Laptop": {"name": "BlueWave Gaming Laptop", "category": "Computers and Laptops", "brand": "BlueWave", "model_number": "BW-GL200", "warranty": "2 years", "rating": 4.7, "features": ["15.6-inch display", "16GB RAM", "512GB SSD", "NVIDIA GeForce RTX 3060"], "description": "A high-performance gaming laptop for an immersive experience.", "price": 1199.99}, "PowerLite Convertible": {"name": "PowerLite Convertible", "category": "Computers and Laptops", "brand": "PowerLite", "model_number": "PL-CV300", "warranty": "1 year", "rating": 4.3, "features": ["14-inch touchscreen", "8GB RAM", "256GB SSD", "360-degree hinge"], "description": "A versatile convertible laptop with a responsive touchscreen.", "price": 699.99}, "TechPro Desktop": {"name": "TechPro Desktop", "category": "Computers and Laptops", "brand": "TechPro", "model_number": "TP-DT500", "warranty": "1 year", "rating": 4.4, "features": ["Intel Core i7 processor", "16GB RAM", "1TB HDD", "NVIDIA GeForce GTX 1660"], "description": "A powerful desktop computer for work and play.", "price": 999.99}, "BlueWave Chromebook": {"name": "BlueWave Chromebook", "category": "Computers and Laptops", "brand": "BlueWave", "model_number": "BW-CB100", "warranty": "1 year", "rating": 4.1, "features": ["11.6-inch display", "4GB RAM", "32GB eMMC", "Chrome OS"], "description": "A compact and affordable Chromebook for everyday tasks.", "price": 249.99}, "SmartX ProPhone": {"name": "SmartX ProPhone", "category": "Smartphones and Accessories", "brand": "SmartX", "model_number": "SX-PP10", "warranty": "1 year", "rating": 4.6, "features": ["6.1-inch display", "128GB storage", "12MP dual camera", "5G"], "description": "A powerful smartphone with advanced camera features.", "price": 899.99}, "MobiTech PowerCase": {"name": "MobiTech PowerCase", "category": "Smartphones and Accessories", "brand": "MobiTech", "model_number": "MT-PC20", "warranty": "1 year", "rating": 4.3, "features": ["5000mAh battery", "Wireless charging", "Compatible with SmartX ProPhone"], "description": "A protective case with built-in battery for extended usage.", "price": 59.99}, "SmartX MiniPhone": {"name": "SmartX MiniPhone", "category": "Smartphones and Accessories", "brand": "SmartX", "model_number": "SX-MP5", "warranty": "1 year", "rating": 4.2, "features": ["4.7-inch display", "64GB storage", "8MP camera", "4G"], "description": "A compact and affordable smartphone for basic tasks.", "price": 399.99}, "MobiTech Wireless Charger": {"name": "MobiTech Wireless Charger", "category": "Smartphones and Accessories", "brand": "MobiTech", "model_number": "MT-WC10", "warranty": "1 year", "rating": 4.5, "features": ["10W fast charging", "Qi-compatible", "LED indicator", "Compact design"], "description": "A convenient wireless charger for a clutter-free workspace.", "price": 29.99}, "SmartX EarBuds": {"name": "SmartX EarBuds", "category": "Smartphones and Accessories", "brand": "SmartX", "model_number": "SX-EB20", "warranty": "1 year", "rating": 4.4, "features": ["True wireless", "Bluetooth 5.0", "Touch controls", "24-hour battery life"], "description": "Experience true wireless freedom with these comfortable earbuds.", "price": 99.99}, "CineView 4K TV": {"name": "CineView 4K TV", "category": "Televisions and Home Theater Systems", "brand": "CineView", "model_number": "CV-4K55", "warranty": "2 years", "rating": 4.8, "features": ["55-inch display", "4K resolution", "HDR", "Smart TV"], "description": "A stunning 4K TV with vibrant colors and smart features.", "price": 599.99}, "SoundMax Home Theater": {"name": "SoundMax Home Theater", "category": "Televisions and Home Theater Systems", "brand": "SoundMax", "model_number": "SM-HT100", "warranty": "1 year", "rating": 4.4, "features": ["5.1 channel", "1000W output", "Wireless subwoofer", "Bluetooth"], "description": "A powerful home theater system for an immersive audio experience.", "price": 399.99}, "CineView 8K TV": {"name": "CineView 8K TV", "category": "Televisions and Home Theater Systems", "brand": "CineView", "model_number": "CV-8K65", "warranty": "2 years", "rating": 4.9, "features": ["65-inch display", "8K resolution", "HDR", "Smart TV"], "description": "Experience the future of television with this stunning 8K TV.", "price": 2999.99}, "SoundMax Soundbar": {"name": "SoundMax Soundbar", "category": "Televisions and Home Theater Systems", "brand": "SoundMax", "model_number": "SM-SB50", "warranty": "1 year", "rating": 4.3, "features": ["2.1 channel", "300W output", "Wireless subwoofer", "Bluetooth"], "description": "Upgrade your TV's audio with this sleek and powerful soundbar.", "price": 199.99}, "CineView OLED TV": {"name": "CineView OLED TV", "category": "Televisions and Home Theater Systems", "brand": "CineView", "model_number": "CV-OLED55", "warranty": "2 years", "rating": 4.7, "features": ["55-inch display", "4K resolution", "HDR", "Smart TV"], "description": "Experience true blacks and vibrant colors with this OLED TV.", "price": 1499.99}, "GameSphere X": {"name": "GameSphere X", "category": "Gaming Consoles and Accessories", "brand": "GameSphere", "model_number": "GS-X", "warranty": "1 year", "rating": 4.9, "features": ["4K gaming", "1TB storage", "Backward compatibility", "Online multiplayer"], "description": "A next-generation gaming console for the ultimate gaming experience.", "price": 499.99}, "ProGamer Controller": {"name": "ProGamer Controller", "category": "Gaming Consoles and Accessories", "brand": "ProGamer", "model_number": "PG-C100", "warranty": "1 year", "rating": 4.2, "features": ["Ergonomic design", "Customizable buttons", "Wireless", "Rechargeable battery"], "description": "A high-quality gaming controller for precision and comfort.", "price": 59.99}, "GameSphere Y": {"name": "GameSphere Y", "category": "Gaming Consoles and Accessories", "brand": "GameSphere", "model_number": "GS-Y", "warranty": "1 year", "rating": 4.8, "features": ["4K gaming", "500GB storage", "Backward compatibility", "Online multiplayer"], "description": "A compact gaming console with powerful performance.", "price": 399.99}, "ProGamer Racing Wheel": {"name": "ProGamer Racing Wheel", "category": "Gaming Consoles and Accessories", "brand": "ProGamer", "model_number": "PG-RW200", "warranty": "1 year", "rating": 4.5, "features": ["Force feedback", "Adjustable pedals", "Paddle shifters", "Compatible with GameSphere X"], "description": "Enhance your racing games with this realistic racing wheel.", "price": 249.99}, "GameSphere VR Headset": {"name": "GameSphere VR Headset", "category": "Gaming Consoles and Accessories", "brand": "GameSphere", "model_number": "GS-VR", "warranty": "1 year", "rating": 4.6, "features": ["Immersive VR experience", "Built-in headphones", "Adjustable headband", "Compatible with GameSphere X"], "description": "Step into the world of virtual reality with this comfortable VR headset.", "price": 299.99}, "AudioPhonic Noise-Canceling Headphones": {"name": "AudioPhonic Noise-Canceling Headphones", "category": "Audio Equipment", "brand": "AudioPhonic", "model_number": "AP-NC100", "warranty": "1 year", "rating": 4.6, "features": ["Active noise-canceling", "Bluetooth", "20-hour battery life", "Comfortable fit"], "description": "Experience immersive sound with these noise-canceling headphones.", "price": 199.99}, "WaveSound Bluetooth Speaker": {"name": "WaveSound Bluetooth Speaker", "category": "Audio Equipment", "brand": "WaveSound", "model_number": "WS-BS50", "warranty": "1 year", "rating": 4.5, "features": ["Portable", "10-hour battery life", "Water-resistant", "Built-in microphone"], "description": "A compact and versatile Bluetooth speaker for music on the go.", "price": 49.99}, "AudioPhonic True Wireless Earbuds": {"name": "AudioPhonic True Wireless Earbuds", "category": "Audio Equipment", "brand": "AudioPhonic", "model_number": "AP-TW20", "warranty": "1 year", "rating": 4.4, "features": ["True wireless", "Bluetooth 5.0", "Touch controls", "18-hour battery life"], "description": "Enjoy music without wires with these comfortable true wireless earbuds.", "price": 79.99}, "WaveSound Soundbar": {"name": "WaveSound Soundbar", "category": "Audio Equipment", "brand": "WaveSound", "model_number": "WS-SB40", "warranty": "1 year", "rating": 4.3, "features": ["2.0 channel", "80W output", "Bluetooth", "Wall-mountable"], "description": "Upgrade your TV's audio with this slim and powerful soundbar.", "price": 99.99}, "AudioPhonic Turntable": {"name": "AudioPhonic Turntable", "category": "Audio Equipment", "brand": "AudioPhonic", "model_number": "AP-TT10", "warranty": "1 year", "rating": 4.2, "features": ["3-speed", "Built-in speakers", "Bluetooth", "USB recording"], "description": "Rediscover your vinyl collection with this modern turntable.", "price": 149.99}, "FotoSnap DSLR Camera": {"name": "FotoSnap DSLR Camera", "category": "Cameras and Camcorders", "brand": "FotoSnap", "model_number": "FS-DSLR200", "warranty": "1 year", "rating": 4.7, "features": ["24.2MP sensor", "1080p video", "3-inch LCD", "Interchangeable lenses"], "description": "Capture stunning photos and videos with this versatile DSLR camera.", "price": 599.99}, "ActionCam 4K": {"name": "ActionCam 4K", "category": "Cameras and Camcorders", "brand": "ActionCam", "model_number": "AC-4K", "warranty": "1 year", "rating": 4.4, "features": ["4K video", "Waterproof", "Image stabilization", "Wi-Fi"], "description": "Record your adventures with this rugged and compact 4K action camera.", "price": 299.99}, "FotoSnap Mirrorless Camera": {"name": "FotoSnap Mirrorless Camera", "category": "Cameras and Camcorders", "brand": "FotoSnap", "model_number": "FS-ML100", "warranty": "1 year", "rating": 4.6, "features": ["20.1MP sensor", "4K video", "3-inch touchscreen", "Interchangeable lenses"], "description": "A compact and lightweight mirrorless camera with advanced features.", "price": 799.99}, "ZoomMaster Camcorder": {"name": "ZoomMaster Camcorder", "category": "Cameras and Camcorders", "brand": "ZoomMaster", "model_number": "ZM-CM50", "warranty": "1 year", "rating": 4.3, "features": ["1080p video", "30x optical zoom", "3-inch LCD", "Image stabilization"], "description": "Capture life's moments with this easy-to-use camcorder.", "price": 249.99}, "FotoSnap Instant Camera": {"name": "FotoSnap Instant Camera", "category": "Cameras and Camcorders", "brand": "FotoSnap", "model_number": "FS-IC10", "warranty": "1 year", "rating": 4.1, "features": ["Instant prints", "Built-in flash", "Selfie mirror", "Battery-powered"], "description": "Create instant memories with this fun and portable instant camera.", "price": 69.99}}
--------------------------------------------------------------------------------
/99~参考资料/2023~吴恩达~《Building Systems with the ChatGPT API》/readme.md:
--------------------------------------------------------------------------------
1 | # 使用 ChatGPT API 搭建系统
2 |
3 | 吴恩达老师发布的大模型开发新课程,在《Prompt Engineering for Developers》课程的基础上,指导开发者如何基于 ChatGPT 提供的 API 开发一个完整的、全面的智能问答系统,包括使用大语言模型的基本规范,通过分类与监督评估输入,通过思维链推理及链式提示处理输入,检查并评估系统输出等,介绍了基于大模型开发的新范式,值得每一个有志于使用大模型开发应用程序的开发者学习。
4 |
5 | ### 目录
6 |
7 | 1. 简介 Introduction @Sarai
8 | 2. 模型,范式和 token Language Models, the Chat Format and Tokens @仲泰
9 | 3. 检查输入-分类 Classification @诸世纪
10 | 4. 检查输入-监督 Moderation @诸世纪
11 | 5. 思维链推理 Chain of Thought Reasoning @万礼行
12 | 6. 提示链 Chaining Prompts @万礼行
13 | 7. 检查输入 Check Outputs @仲泰
14 | 8. 评估(端到端系统)Evaluation @邹雨衡
15 | 9. 评估(简单问答)Evaluation-part1 @陈志宏
16 | 10. 评估(复杂问答)Evaluation-part2 @邹雨衡
17 | 11. 总结 Conclusion @Sarai
18 |
--------------------------------------------------------------------------------
/99~参考资料/2023~吴恩达~《ChatGPT Prompt Engineering for Developers》/00.README.md:
--------------------------------------------------------------------------------
1 | # Prompt Engineering for Developers
2 |
3 | LLM 正在逐步改变人们的生活,而对于开发者,如何基于 LLM 提供的 API 快速、便捷地开发一些具备更强能力、集成LLM 的应用,来便捷地实现一些更新颖、更实用的能力,是一个急需学习的重要能力。由吴恩达老师与 OpenAI 合作推出的 《ChatGPT Prompt Engineering for Developers》教程面向入门 LLM 的开发者,深入浅出地介绍了对于开发者,如何构造 Prompt 并基于 OpenAI 提供的 API 实现包括总结、推断、转换等多种常用功能,是入门 LLM 开发的经典教程。在可预见的未来,该教程会成为 LLM 的重要入门教程,但是目前还只支持英文版且国内访问受限,打造中文版且国内流畅访问的教程具有重要意义。因此,我们将该课程翻译为中文,并复现其范例代码,支持国内中文学习者直接使用,以帮助中文学习者更好地学习 LLM 开发。
4 |
5 | 本教程为吴恩达《ChatGPT Prompt Engineering for Developers》课程中文版,主要内容为指导开发者如何构建 Prompt 并基于 OpenAI API 构建新的、基于 LLM 的应用,包括:
6 | > 书写 Prompt 的原则
7 | > 文本总结(如总结用户评论);
8 | > 文本推断(如情感分类、主题提取);
9 | > 文本转换(如翻译、自动纠错);
10 | > 扩展(如书写邮件)
11 |
12 | **目录:**
13 | 1. 简介 Introduction @邹雨衡
14 | 2. Prompt 的构建原则 Guidelines @邹雨衡
15 | 3. 如何迭代优化 Prompt Itrative @邹雨衡
16 | 4. 文本总结 Summarizing @玉琳
17 | 5. 文本推断 @长琴
18 | 6. 文本转换 Transforming @玉琳
19 | 7. 文本扩展 Expand @邹雨衡
20 | 8. 聊天机器人 @长琴
21 | 9. 总结 @长琴
22 |
--------------------------------------------------------------------------------
/99~参考资料/2023~吴恩达~《ChatGPT Prompt Engineering for Developers》/01. 简介.md:
--------------------------------------------------------------------------------
1 | # 简介
2 |
3 | **作者 吴恩达教授**
4 |
5 | 欢迎来到本课程,我们将为开发人员介绍 ChatGPT 提示工程。本课程由 Isa Fulford 教授和我一起授课。Isa Fulford 是 OpenAI 的技术团队成员,曾开发过受欢迎的 ChatGPT 检索插件,并且在教授人们如何在产品中使用 LLM 或 LLM 技术方面做出了很大贡献。她还参与编写了教授人们使用 Prompt 的 OpenAI cookbook。
6 |
7 | 互联网上有很多有关提示的材料,例如《30 prompts everyone has to know》之类的文章。这些文章主要集中在 ChatGPT Web 用户界面上,许多人在使用它执行特定的、通常是一次性的任务。但是,我认为 LLM 或大型语言模型作为开发人员的更强大功能是使用 API 调用到 LLM,以快速构建软件应用程序。我认为这方面还没有得到充分的重视。实际上,我们在 DeepLearning.AI 的姊妹公司 AI Fund 的团队一直在与许多初创公司合作,将这些技术应用于许多不同的应用程序上。看到 LLM API 能够让开发人员非常快速地构建应用程序,这真是令人兴奋。
8 |
9 | 在本课程中,我们将与您分享一些可能性以及如何实现它们的最佳实践。
10 |
11 | 随着大型语言模型(LLM)的发展,LLM 大致可以分为两种类型,即基础LLM和指令微调LLM。基础LLM是基于文本训练数据,训练出预测下一个单词能力的模型,其通常是在互联网和其他来源的大量数据上训练的。例如,如果你以“从前有一只独角兽”作为提示,基础LLM可能会继续预测“生活在一个与所有独角兽朋友的神奇森林中”。但是,如果你以“法国的首都是什么”为提示,则基础LLM可能会根据互联网上的文章,将答案预测为“法国最大的城市是什么?法国的人口是多少?”,因为互联网上的文章很可能是有关法国国家的问答题目列表。
12 |
13 | 许多 LLMs 的研究和实践的动力正在指令调整的 LLMs 上。指令调整的 LLMs 已经被训练来遵循指令。因此,如果你问它,“法国的首都是什么?”,它更有可能输出“法国的首都是巴黎”。指令调整的 LLMs 的训练通常是从已经训练好的基本 LLMs 开始,该模型已经在大量文本数据上进行了训练。然后,使用输入是指令、输出是其应该返回的结果的数据集来对其进行微调,要求它遵循这些指令。然后通常使用一种称为 RLHF(reinforcement learning from human feedback,人类反馈强化学习)的技术进行进一步改进,使系统更能够有帮助地遵循指令。
14 |
15 | 因为指令调整的 LLMs 已经被训练成有益、诚实和无害的,所以与基础LLMs相比,它们更不可能输出有问题的文本,如有害输出。许多实际使用场景已经转向指令调整的LLMs。您在互联网上找到的一些最佳实践可能更适用于基础LLMs,但对于今天的大多数实际应用,我们建议将注意力集中在指令调整的LLMs上,这些LLMs更容易使用,而且由于OpenAI和其他LLM公司的工作,它们变得更加安全和更加协调。
16 |
17 | 因此,本课程将重点介绍针对指令调整 LLM 的最佳实践,这是我们建议您用于大多数应用程序的。在继续之前,我想感谢 OpenAI 和 DeepLearning.ai 团队为 Izzy 和我所提供的材料作出的贡献。我非常感激 OpenAI 的 Andrew Main、Joe Palermo、Boris Power、Ted Sanders 和 Lillian Weng,他们参与了我们的头脑风暴材料的制定和审核,为这个短期课程编制了课程大纲。我也感激 Deep Learning 方面的 Geoff Ladwig、Eddy Shyu 和 Tommy Nelson 的工作。
18 |
19 | 当您使用指令调整 LLM 时,请类似于考虑向另一个人提供指令,假设它是一个聪明但不知道您任务的具体细节的人。当 LLM 无法正常工作时,有时是因为指令不够清晰。例如,如果您说“请为我写一些关于阿兰·图灵的东西”,清楚表明您希望文本专注于他的科学工作、个人生活、历史角色或其他方面可能会更有帮助。更多的,您还可以指定文本采取像专业记者写作的语调,或者更像是您向朋友写的随笔。
20 |
21 | 当然,如果你想象一下让一位新毕业的大学生为你完成这个任务,你甚至可以提前指定他们应该阅读哪些文本片段来写关于 Alan Turing的文本,那么这能够帮助这位新毕业的大学生更好地成功完成这项任务。下一章你会看到如何让提示清晰明确,创建提示的一个重要原则,你还会从提示的第二个原则中学到给LLM时间去思考。
--------------------------------------------------------------------------------
/99~参考资料/2023~吴恩达~《ChatGPT Prompt Engineering for Developers》/07. 文本扩展 Expanding.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# 第七章 扩展\n",
8 | "\n",
9 | "扩展是将短文本,例如一组说明或主题列表,输入到大型语言模型中,让模型生成更长的文本,例如基于某个主题的电子邮件或论文。这样做有一些很好的用途,例如将大型语言模型用作头脑风暴的伙伴。但这种做法也存在一些问题,例如某人可能会使用它来生成大量垃圾邮件。因此,当你使用大型语言模型的这些功能时,请仅以负责任的方式和有益于人们的方式使用它们。\n",
10 | "\n",
11 | "在本章中,你将学会如何基于 OpenAI API 生成适用于每个客户评价的客户服务电子邮件。我们还将使用模型的另一个输入参数称为温度,这种参数允许您在模型响应中变化探索的程度和多样性。\n"
12 | ]
13 | },
14 | {
15 | "cell_type": "markdown",
16 | "metadata": {},
17 | "source": [
18 | "## 一、环境配置\n",
19 | "\n",
20 | "同以上几章,你需要类似的代码来配置一个可以使用 OpenAI API 的环境"
21 | ]
22 | },
23 | {
24 | "cell_type": "code",
25 | "execution_count": null,
26 | "metadata": {},
27 | "outputs": [],
28 | "source": [
29 | "# 将自己的 API-KEY 导入系统环境变量\n",
30 | "!export OPENAI_API_KEY='api-key'"
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": 1,
36 | "metadata": {},
37 | "outputs": [],
38 | "source": [
39 | "import openai\n",
40 | "import os\n",
41 | "from dotenv import load_dotenv, find_dotenv\n",
42 | "# 导入第三方库\n",
43 | "\n",
44 | "_ = load_dotenv(find_dotenv())\n",
45 | "# 读取系统中的环境变量\n",
46 | "\n",
47 | "openai.api_key = os.getenv('OPENAI_API_KEY')\n",
48 | "# 设置 API_KEY"
49 | ]
50 | },
51 | {
52 | "cell_type": "code",
53 | "execution_count": 9,
54 | "metadata": {},
55 | "outputs": [],
56 | "source": [
57 | "# 一个封装 OpenAI 接口的函数,参数为 Prompt,返回对应结果\n",
58 | "def get_completion(prompt, model=\"gpt-3.5-turbo\", temperature=0):\n",
59 | " '''\n",
60 | " prompt: 对应的提示\n",
61 | " model: 调用的模型,默认为 gpt-3.5-turbo(ChatGPT),有内测资格的用户可以选择 gpt-4\n",
62 | " temperature: 温度系数\n",
63 | " '''\n",
64 | " messages = [{\"role\": \"user\", \"content\": prompt}]\n",
65 | " response = openai.ChatCompletion.create(\n",
66 | " model=model,\n",
67 | " messages=messages,\n",
68 | " temperature=temperature, # 模型输出的温度系数,控制输出的随机程度\n",
69 | " )\n",
70 | " # 调用 OpenAI 的 ChatCompletion 接口\n",
71 | " return response.choices[0].message[\"content\"]\n"
72 | ]
73 | },
74 | {
75 | "cell_type": "markdown",
76 | "metadata": {},
77 | "source": [
78 | "## 二、定制客户邮件"
79 | ]
80 | },
81 | {
82 | "cell_type": "markdown",
83 | "metadata": {},
84 | "source": [
85 | "我们将根据客户评价和情感撰写自定义电子邮件响应。因此,我们将给定客户评价和情感,并生成自定义响应即使用 LLM 根据客户评价和评论情感生成定制电子邮件。"
86 | ]
87 | },
88 | {
89 | "cell_type": "markdown",
90 | "metadata": {},
91 | "source": [
92 | "我们首先给出一个示例,包括一个评论及对应的情感"
93 | ]
94 | },
95 | {
96 | "cell_type": "code",
97 | "execution_count": 4,
98 | "metadata": {},
99 | "outputs": [],
100 | "source": [
101 | "# given the sentiment from the lesson on \"inferring\",\n",
102 | "# and the original customer message, customize the email\n",
103 | "sentiment = \"negative\"\n",
104 | "\n",
105 | "# review for a blender\n",
106 | "review = f\"\"\"\n",
107 | "So, they still had the 17 piece system on seasonal \\\n",
108 | "sale for around $49 in the month of November, about \\\n",
109 | "half off, but for some reason (call it price gouging) \\\n",
110 | "around the second week of December the prices all went \\\n",
111 | "up to about anywhere from between $70-$89 for the same \\\n",
112 | "system. And the 11 piece system went up around $10 or \\\n",
113 | "so in price also from the earlier sale price of $29. \\\n",
114 | "So it looks okay, but if you look at the base, the part \\\n",
115 | "where the blade locks into place doesn’t look as good \\\n",
116 | "as in previous editions from a few years ago, but I \\\n",
117 | "plan to be very gentle with it (example, I crush \\\n",
118 | "very hard items like beans, ice, rice, etc. in the \\ \n",
119 | "blender first then pulverize them in the serving size \\\n",
120 | "I want in the blender then switch to the whipping \\\n",
121 | "blade for a finer flour, and use the cross cutting blade \\\n",
122 | "first when making smoothies, then use the flat blade \\\n",
123 | "if I need them finer/less pulpy). Special tip when making \\\n",
124 | "smoothies, finely cut and freeze the fruits and \\\n",
125 | "vegetables (if using spinach-lightly stew soften the \\ \n",
126 | "spinach then freeze until ready for use-and if making \\\n",
127 | "sorbet, use a small to medium sized food processor) \\ \n",
128 | "that you plan to use that way you can avoid adding so \\\n",
129 | "much ice if at all-when making your smoothie. \\\n",
130 | "After about a year, the motor was making a funny noise. \\\n",
131 | "I called customer service but the warranty expired \\\n",
132 | "already, so I had to buy another one. FYI: The overall \\\n",
133 | "quality has gone done in these types of products, so \\\n",
134 | "they are kind of counting on brand recognition and \\\n",
135 | "consumer loyalty to maintain sales. Got it in about \\\n",
136 | "two days.\n",
137 | "\"\"\""
138 | ]
139 | },
140 | {
141 | "cell_type": "code",
142 | "execution_count": 11,
143 | "metadata": {},
144 | "outputs": [],
145 | "source": [
146 | "# 我们可以在推理那章学习到如何对一个评论判断其情感倾向\n",
147 | "sentiment = \"negative\"\n",
148 | "\n",
149 | "# 一个产品的评价\n",
150 | "review = f\"\"\"\n",
151 | "他们在11月份的季节性销售期间以约49美元的价格出售17件套装,折扣约为一半。\\\n",
152 | "但由于某些原因(可能是价格欺诈),到了12月第二周,同样的套装价格全都涨到了70美元到89美元不等。\\\n",
153 | "11件套装的价格也上涨了大约10美元左右。\\\n",
154 | "虽然外观看起来还可以,但基座上锁定刀片的部分看起来不如几年前的早期版本那么好。\\\n",
155 | "不过我打算非常温柔地使用它,例如,\\\n",
156 | "我会先在搅拌机中将像豆子、冰、米饭等硬物研磨,然后再制成所需的份量,\\\n",
157 | "切换到打蛋器制作更细的面粉,或者在制作冰沙时先使用交叉切割刀片,然后使用平面刀片制作更细/不粘的效果。\\\n",
158 | "制作冰沙时,特别提示:\\\n",
159 | "将水果和蔬菜切碎并冷冻(如果使用菠菜,则轻轻煮软菠菜,然后冷冻直到使用;\\\n",
160 | "如果制作果酱,则使用小到中号的食品处理器),这样可以避免在制作冰沙时添加太多冰块。\\\n",
161 | "大约一年后,电机发出奇怪的噪音,我打电话给客服,但保修已经过期了,所以我不得不再买一个。\\\n",
162 | "总的来说,这些产品的总体质量已经下降,因此它们依靠品牌认可和消费者忠诚度来维持销售。\\\n",
163 | "货物在两天内到达。\n",
164 | "\"\"\""
165 | ]
166 | },
167 | {
168 | "cell_type": "markdown",
169 | "metadata": {},
170 | "source": [
171 | "我们已经使用推断课程中学到的提取了情感,这是一个关于搅拌机的客户评价,现在我们将根据情感定制回复。\n",
172 | "\n",
173 | "这里的指令是:假设你是一个客户服务AI助手,你的任务是为客户发送电子邮件回复,根据通过三个反引号分隔的客户电子邮件,生成一封回复以感谢客户的评价。"
174 | ]
175 | },
176 | {
177 | "cell_type": "code",
178 | "execution_count": 5,
179 | "metadata": {},
180 | "outputs": [
181 | {
182 | "name": "stdout",
183 | "output_type": "stream",
184 | "text": [
185 | "Dear Valued Customer,\n",
186 | "\n",
187 | "Thank you for taking the time to leave a review about our product. We are sorry to hear that you experienced an increase in price and that the quality of the product did not meet your expectations. We apologize for any inconvenience this may have caused you.\n",
188 | "\n",
189 | "We would like to assure you that we take all feedback seriously and we will be sure to pass your comments along to our team. If you have any further concerns, please do not hesitate to reach out to our customer service team for assistance.\n",
190 | "\n",
191 | "Thank you again for your review and for choosing our product. We hope to have the opportunity to serve you better in the future.\n",
192 | "\n",
193 | "Best regards,\n",
194 | "\n",
195 | "AI customer agent\n"
196 | ]
197 | }
198 | ],
199 | "source": [
200 | "prompt = f\"\"\"\n",
201 | "You are a customer service AI assistant.\n",
202 | "Your task is to send an email reply to a valued customer.\n",
203 | "Given the customer email delimited by ```, \\\n",
204 | "Generate a reply to thank the customer for their review.\n",
205 | "If the sentiment is positive or neutral, thank them for \\\n",
206 | "their review.\n",
207 | "If the sentiment is negative, apologize and suggest that \\\n",
208 | "they can reach out to customer service. \n",
209 | "Make sure to use specific details from the review.\n",
210 | "Write in a concise and professional tone.\n",
211 | "Sign the email as `AI customer agent`.\n",
212 | "Customer review: ```{review}```\n",
213 | "Review sentiment: {sentiment}\n",
214 | "\"\"\"\n",
215 | "response = get_completion(prompt)\n",
216 | "print(response)"
217 | ]
218 | },
219 | {
220 | "cell_type": "code",
221 | "execution_count": 6,
222 | "metadata": {},
223 | "outputs": [
224 | {
225 | "name": "stdout",
226 | "output_type": "stream",
227 | "text": [
228 | "尊敬的客户,\n",
229 | "\n",
230 | "非常感谢您对我们产品的评价。我们非常抱歉您在购买过程中遇到了价格上涨的问题。我们一直致力于为客户提供最优惠的价格,但由于市场波动,价格可能会有所变化。我们深表歉意,如果您需要任何帮助,请随时联系我们的客户服务团队。\n",
231 | "\n",
232 | "我们非常感谢您对我们产品的详细评价和使用技巧。我们将会把您的反馈传达给我们的产品团队,以便改进我们的产品质量和性能。\n",
233 | "\n",
234 | "再次感谢您对我们的支持和反馈。如果您需要任何帮助或有任何疑问,请随时联系我们的客户服务团队。\n",
235 | "\n",
236 | "祝您一切顺利!\n",
237 | "\n",
238 | "AI客户代理\n"
239 | ]
240 | }
241 | ],
242 | "source": [
243 | "prompt = f\"\"\"\n",
244 | "你是一位客户服务的AI助手。\n",
245 | "你的任务是给一位重要客户发送邮件回复。\n",
246 | "根据客户通过“```”分隔的评价,生成回复以感谢客户的评价。提醒模型使用评价中的具体细节\n",
247 | "用简明而专业的语气写信。\n",
248 | "作为“AI客户代理”签署电子邮件。\n",
249 | "客户评论:\n",
250 | "```{review}```\n",
251 | "评论情感:{sentiment}\n",
252 | "\"\"\"\n",
253 | "response = get_completion(prompt)\n",
254 | "print(response)"
255 | ]
256 | },
257 | {
258 | "cell_type": "markdown",
259 | "metadata": {},
260 | "source": [
261 | "## 三、使用温度系数\n",
262 | "\n",
263 | "接下来,我们将使用语言模型的一个称为“温度”的参数,它将允许我们改变模型响应的多样性。您可以将温度视为模型探索或随机性的程度。\n",
264 | "\n",
265 | "例如,在一个特定的短语中,“我的最爱食品”最有可能的下一个词是“比萨”,其次最有可能的是“寿司”和“塔可”。因此,在温度为零时,模型将总是选择最有可能的下一个词,而在较高的温度下,它还将选择其中一个不太可能的词,在更高的温度下,它甚至可能选择塔可,而这种可能性仅为五分之一。您可以想象,随着模型继续生成更多单词的最终响应,“我的最爱食品是比萨”将会与第一个响应“我的最爱食品是塔可”产生差异。因此,随着模型的继续,这两个响应将变得越来越不同。\n",
266 | "\n",
267 | "一般来说,在构建需要可预测响应的应用程序时,我建议使用温度为零。在所有课程中,我们一直设置温度为零,如果您正在尝试构建一个可靠和可预测的系统,我认为您应该选择这个温度。如果您尝试以更具创意的方式使用模型,可能需要更广泛地输出不同的结果,那么您可能需要使用更高的温度。"
268 | ]
269 | },
270 | {
271 | "cell_type": "code",
272 | "execution_count": 7,
273 | "metadata": {},
274 | "outputs": [],
275 | "source": [
276 | "# given the sentiment from the lesson on \"inferring\",\n",
277 | "# and the original customer message, customize the email\n",
278 | "sentiment = \"negative\"\n",
279 | "\n",
280 | "# review for a blender\n",
281 | "review = f\"\"\"\n",
282 | "So, they still had the 17 piece system on seasonal \\\n",
283 | "sale for around $49 in the month of November, about \\\n",
284 | "half off, but for some reason (call it price gouging) \\\n",
285 | "around the second week of December the prices all went \\\n",
286 | "up to about anywhere from between $70-$89 for the same \\\n",
287 | "system. And the 11 piece system went up around $10 or \\\n",
288 | "so in price also from the earlier sale price of $29. \\\n",
289 | "So it looks okay, but if you look at the base, the part \\\n",
290 | "where the blade locks into place doesn’t look as good \\\n",
291 | "as in previous editions from a few years ago, but I \\\n",
292 | "plan to be very gentle with it (example, I crush \\\n",
293 | "very hard items like beans, ice, rice, etc. in the \\ \n",
294 | "blender first then pulverize them in the serving size \\\n",
295 | "I want in the blender then switch to the whipping \\\n",
296 | "blade for a finer flour, and use the cross cutting blade \\\n",
297 | "first when making smoothies, then use the flat blade \\\n",
298 | "if I need them finer/less pulpy). Special tip when making \\\n",
299 | "smoothies, finely cut and freeze the fruits and \\\n",
300 | "vegetables (if using spinach-lightly stew soften the \\ \n",
301 | "spinach then freeze until ready for use-and if making \\\n",
302 | "sorbet, use a small to medium sized food processor) \\ \n",
303 | "that you plan to use that way you can avoid adding so \\\n",
304 | "much ice if at all-when making your smoothie. \\\n",
305 | "After about a year, the motor was making a funny noise. \\\n",
306 | "I called customer service but the warranty expired \\\n",
307 | "already, so I had to buy another one. FYI: The overall \\\n",
308 | "quality has gone done in these types of products, so \\\n",
309 | "they are kind of counting on brand recognition and \\\n",
310 | "consumer loyalty to maintain sales. Got it in about \\\n",
311 | "two days.\n",
312 | "\"\"\""
313 | ]
314 | },
315 | {
316 | "cell_type": "code",
317 | "execution_count": 10,
318 | "metadata": {},
319 | "outputs": [
320 | {
321 | "name": "stdout",
322 | "output_type": "stream",
323 | "text": [
324 | "Dear valued customer,\n",
325 | "\n",
326 | "Thank you for taking the time to share your review with us. We are sorry to hear that you were disappointed with the prices of our products and the quality of our blender. We apologize for any inconvenience this may have caused you.\n",
327 | "\n",
328 | "We value your feedback and would like to make things right for you. Please feel free to contact our customer service team so we can assist you with any concerns or issues you may have. We are committed to providing you with the best possible service and products.\n",
329 | "\n",
330 | "Thank you again for your review and for being a loyal customer. We hope to have the opportunity to serve you better in the future.\n",
331 | "\n",
332 | "Sincerely,\n",
333 | "AI customer agent\n"
334 | ]
335 | }
336 | ],
337 | "source": [
338 | "prompt = f\"\"\"\n",
339 | "You are a customer service AI assistant.\n",
340 | "Your task is to send an email reply to a valued customer.\n",
341 | "Given the customer email delimited by ```, \\\n",
342 | "Generate a reply to thank the customer for their review.\n",
343 | "If the sentiment is positive or neutral, thank them for \\\n",
344 | "their review.\n",
345 | "If the sentiment is negative, apologize and suggest that \\\n",
346 | "they can reach out to customer service. \n",
347 | "Make sure to use specific details from the review.\n",
348 | "Write in a concise and professional tone.\n",
349 | "Sign the email as `AI customer agent`.\n",
350 | "Customer review: ```{review}```\n",
351 | "Review sentiment: {sentiment}\n",
352 | "\"\"\"\n",
353 | "response = get_completion(prompt, temperature=0.7)\n",
354 | "print(response)"
355 | ]
356 | },
357 | {
358 | "cell_type": "code",
359 | "execution_count": 12,
360 | "metadata": {},
361 | "outputs": [
362 | {
363 | "name": "stdout",
364 | "output_type": "stream",
365 | "text": [
366 | "尊敬的客户,\n",
367 | "\n",
368 | "非常感谢您对我们产品的评价。我们由衷地为您在购买过程中遇到的问题表示抱歉。我们确实在12月份的第二周调整了价格,但这是由于市场因素所致,并非价格欺诈。我们深刻意识到您对产品质量的担忧,我们将尽一切努力改进产品,以提供更好的体验。\n",
369 | "\n",
370 | "我们非常感激您对我们产品的使用经验和制作技巧的分享。您的建议和反馈对我们非常重要,我们将以此为基础,进一步改进我们的产品。\n",
371 | "\n",
372 | "如果您有任何疑问或需要进一步帮助,请随时联系我们的客户服务部门。我们将尽快回复您并提供帮助。\n",
373 | "\n",
374 | "最后,请再次感谢您对我们产品的评价和选择。我们期待着未来与您的合作。\n",
375 | "\n",
376 | "此致\n",
377 | "\n",
378 | "敬礼\n",
379 | "\n",
380 | "AI客户代理\n"
381 | ]
382 | }
383 | ],
384 | "source": [
385 | "prompt = f\"\"\"\n",
386 | "你是一名客户服务的AI助手。\n",
387 | "你的任务是给一位重要的客户发送邮件回复。\n",
388 | "根据通过“```”分隔的客户电子邮件生成回复,以感谢客户的评价。\n",
389 | "如果情感是积极的或中性的,感谢他们的评价。\n",
390 | "如果情感是消极的,道歉并建议他们联系客户服务。\n",
391 | "请确保使用评论中的具体细节。\n",
392 | "以简明和专业的语气写信。\n",
393 | "以“AI客户代理”的名义签署电子邮件。\n",
394 | "客户评价:```{review}```\n",
395 | "评论情感:{sentiment}\n",
396 | "\"\"\"\n",
397 | "response = get_completion(prompt, temperature=0.7)\n",
398 | "print(response)"
399 | ]
400 | },
401 | {
402 | "cell_type": "markdown",
403 | "metadata": {},
404 | "source": [
405 | " "
406 | ]
407 | },
408 | {
409 | "cell_type": "markdown",
410 | "metadata": {},
411 | "source": [
412 | "在温度为零时,每次执行相同的提示时,您应该期望获得相同的完成。而使用温度为0.7,则每次都会获得不同的输出。\n",
413 | "\n",
414 | "所以,您可以看到它与我们之前收到的电子邮件不同。让我们再次执行它,以显示我们将再次获得不同的电子邮件。\n",
415 | "\n",
416 | "因此,我建议您自己尝试温度,以查看输出如何变化。总之,在更高的温度下,模型的输出更加随机。您几乎可以将其视为在更高的温度下,助手更易分心,但也许更有创造力。"
417 | ]
418 | }
419 | ],
420 | "metadata": {
421 | "kernelspec": {
422 | "display_name": "Python 3",
423 | "language": "python",
424 | "name": "python3"
425 | },
426 | "language_info": {
427 | "codemirror_mode": {
428 | "name": "ipython",
429 | "version": 3
430 | },
431 | "file_extension": ".py",
432 | "mimetype": "text/x-python",
433 | "name": "python",
434 | "nbconvert_exporter": "python",
435 | "pygments_lexer": "ipython3",
436 | "version": "3.8.13"
437 | },
438 | "latex_envs": {
439 | "LaTeX_envs_menu_present": true,
440 | "autoclose": false,
441 | "autocomplete": true,
442 | "bibliofile": "biblio.bib",
443 | "cite_by": "apalike",
444 | "current_citInitial": 1,
445 | "eqLabelWithNumbers": true,
446 | "eqNumInitial": 1,
447 | "hotkeys": {
448 | "equation": "Ctrl-E",
449 | "itemize": "Ctrl-I"
450 | },
451 | "labels_anchors": false,
452 | "latex_user_defs": false,
453 | "report_style_numbering": false,
454 | "user_envs_cfg": false
455 | },
456 | "toc": {
457 | "base_numbering": 1,
458 | "nav_menu": {},
459 | "number_sections": true,
460 | "sideBar": true,
461 | "skip_h1_title": false,
462 | "title_cell": "Table of Contents",
463 | "title_sidebar": "Contents",
464 | "toc_cell": false,
465 | "toc_position": {},
466 | "toc_section_display": true,
467 | "toc_window_display": false
468 | }
469 | },
470 | "nbformat": 4,
471 | "nbformat_minor": 4
472 | }
473 |
--------------------------------------------------------------------------------
/99~参考资料/2023~吴恩达~《ChatGPT Prompt Engineering for Developers》/09. 总结.md:
--------------------------------------------------------------------------------
1 | 恭喜你完成了这门短期课程。
2 |
3 | 总的来说,在这门课程中,我们学习了关于prompt的两个关键原则:
4 |
5 | - 编写清晰具体的指令;
6 | - 如果适当的话,给模型一些思考时间。
7 |
8 | 你还学习了迭代式prompt开发的方法,并了解了如何找到适合你应用程序的prompt的过程是非常关键的。
9 |
10 | 我们还介绍了许多大型语言模型的功能,包括摘要、推断、转换和扩展。你还学会了如何构建自定义聊天机器人。在这门短期课程中,你学到了很多,希望你喜欢这些学习材料。
11 |
12 | 我们希望你能想出一些应用程序的想法,并尝试自己构建它们。请尝试一下并让我们知道你的想法。你可以从一个非常小的项目开始,也许它具有一定的实用价值,也可能完全没有实用价值,只是一些有趣好玩儿的东西。请利用你第一个项目的学习经验来构建更好的第二个项目,甚至更好的第三个项目等。或者,如果你已经有一个更大的项目想法,那就去做吧。
13 |
14 | 大型语言模型非常强大,作为提醒,我们希望大家负责任地使用它们,请仅构建对他人有积极影响的东西。在这个时代,构建人工智能系统的人可以对他人产生巨大的影响。因此必须负责任地使用这些工具。
15 |
16 | 现在,基于大型语言模型构建应用程序是一个非常令人兴奋和不断发展的领域。现在你已经完成了这门课程,我们认为你现在拥有了丰富的知识,可以帮助你构建其他人今天不知道如何构建的东西。因此,我希望你也能帮助我们传播并鼓励其他人也参加这门课程。
17 |
18 | 最后,希望你在完成这门课程时感到愉快,感谢你完成了这门课程。我们期待听到你构建的惊人之作。
--------------------------------------------------------------------------------
/99~参考资料/2023~吴恩达~《LangChain for LLM Application Development》/1.开篇介绍.md:
--------------------------------------------------------------------------------
1 | ## 吴恩达 LangChain大模型应用开发 开端篇
2 |
3 | ## LangChain for LLM Application Development
4 |
5 | 欢迎来到LangChain大模型应用开发短期课程👏🏻👏🏻
6 |
7 | 本课程由哈里森·蔡斯 (Harrison Chase,LangChain作者)与Deeplearning.ai合作开发,旨在教大家使用这个神奇工具。
8 |
9 | ### 🚀 LangChain的诞生和发展
10 |
11 | 通过提示LLM或大型语言模型,现在可以比以往更快地开发AI应用程序,但是一个应用程序可能需要提示和多次并暂停作为输出。
12 |
13 | 在此过程有很多胶水代码需要编写,因此哈里森·蔡斯 (Harrison Chase) 创建了LangChain,整合了常见的抽象功能,使开发过程变得更加丝滑。
14 |
15 | LangChain开源社区快速发展,贡献者已达数百人,正以惊人的速度更新代码和功能。
16 |
17 |
18 |
19 | ### 📚 课程基本内容
20 |
21 | LangChain是用于构建大模型应用程序的开源框架,有Python和JavaScript两个不同版本的包。LangChain基于模块化组合,有许多单独的组件,可以一起使用或单独使用。此外LangChain还拥有很多应用案例,帮助我们了解如何将这些模块化组件组合成链式方式,以形成更多端到端的应用程序 。
22 |
23 | 在本课程中,我们将介绍LandChain的常见组件,并讨论模型、提示(使模型执行操作的方式)、索引(处理数据的方式),然后将讨论链式(端到端用例)以及令人激动的代理(使用模型作为推理引擎的端到端应用)。
24 |
25 |
26 |
27 | ### 🌹致谢课程重要贡献者
28 |
29 | 最后特别感谢Ankush Gholar(LandChain的联合作者)、Geoff Ladwig,、Eddy Shyu 以及 Diala Ezzedine,他们也为课程内容投入了很多思考~
--------------------------------------------------------------------------------
/99~参考资料/2023~吴恩达~《LangChain for LLM Application Development》/8.课程总结.md:
--------------------------------------------------------------------------------
1 | ## 吴恩达 LangChain大模型应用开发 总结篇
2 |
3 | ## LangChain for LLM Application Development
4 |
5 | 本次简短课程涵盖了一系列LangChain的应用实践,包括处理顾客评论和基于文档回答问题,以及通过LLM判断何时求助外部工具 (如网站) 来回答复杂问题。
6 |
7 | ### 👍🏻 LangChain如此强大
8 |
9 | 构建这类应用曾经需要耗费数周时间,而现在只需要非常少的代码,就可以通过LangChain高效构建所需的应用程序。LangChain已成为开发大模型应用的有力范式,希望大家拥抱这个强大工具,积极探索更多更广泛的应用场景。
10 |
11 | ### 🌈 不同组合->更多可能性
12 |
13 | LangChain还可以协助我们做什么呢:基于CSV文件回答问题、查询sql数据库、与api交互,有很多例子通过Chain以及不同的提示(Prompts)和输出解析器(output parsers)组合得以实现。
14 |
15 | ### 💪🏻 出发~去探索新世界吧~
16 |
17 | 因此非常感谢社区中做出贡献的每一个人,无论是协助文档的改进,还是让其他人更容易上手,还是构建新的Chain打开一个全新的世界。
18 |
19 | 如果你还没有这样做,快去打开电脑,运行 pip install LangChain,然后去使用LangChain、搭建惊艳的应用吧~
20 |
21 |
--------------------------------------------------------------------------------
/99~参考资料/2023~吴恩达~《LangChain for LLM Application Development》/Data.csv:
--------------------------------------------------------------------------------
1 | Product,Review
2 | Queen Size Sheet Set,"I ordered a king size set. My only criticism would be that I wish seller would offer the king size set with 4 pillowcases. I separately ordered a two pack of pillowcases so I could have a total of four. When I saw the two packages, it looked like the color did not exactly match. Customer service was excellent about sending me two more pillowcases so I would have four that matched. Excellent! For the cost of these sheets, I am satisfied with the characteristics and coolness of the sheets."
3 | Waterproof Phone Pouch,"I loved the waterproof sac, although the opening was made of a hard plastic. I don’t know if that would break easily. But I couldn’t turn my phone on, once it was in the pouch."
4 | Luxury Air Mattress,"This mattress had a small hole in the top of it (took forever to find where it was), and the patches that they provide did not work, maybe because it's the top of the mattress where it's kind of like fabric and a patch won't stick. Maybe I got unlucky with a defective mattress, but where's quality assurance for this company? That flat out should not happen. Emphasis on flat. Cause that's what the mattress was. Seriously horrible experience, ruined my friend's stay with me. Then they make you ship it back instead of just providing a refund, which is also super annoying to pack up an air mattress and take it to the UPS store. This company is the worst, and this mattress is the worst."
5 | Pillows Insert,"This is the best throw pillow fillers on Amazon. I’ve tried several others, and they’re all cheap and flat no matter how much fluffing you do. Once you toss these in the dryer after you remove them from the vacuum sealed shipping material, they fluff up great"
6 | "Milk Frother Handheld
7 | "," I loved this product. But they only seem to last a few months. The company was great replacing the first one (the frother falls out of the handle and can't be fixed). The after 4 months my second one did the same. I only use the frother for coffee once a day. It's not overuse or abuse. I'm very disappointed and will look for another. As I understand they will only replace once. Anyway, if you have one good luck."
8 | "L'Or Espresso Café
9 | ","Je trouve le goût médiocre. La mousse ne tient pas, c'est bizarre. J'achète les mêmes dans le commerce et le goût est bien meilleur...
10 | Vieux lot ou contrefaçon !?"
11 | Hervidor de Agua Eléctrico,"Está lu bonita calienta muy rápido, es muy funcional, solo falta ver cuánto dura, solo llevo 3 días en funcionamiento."
--------------------------------------------------------------------------------
/99~参考资料/2023~吴恩达~《LangChain for LLM Application Development》/readme.md:
--------------------------------------------------------------------------------
1 | # 使用 LangChain 开发基于 LLM 的应用程序
2 |
3 | 吴恩达老师发布的大模型开发新课程,指导开发者如何结合框架LangChain 使用 ChatGPT API 来搭建基于 LLM 的应用程序,帮助开发者学习使用 LangChain 的一些技巧,包括:模型、提示和解析器,应用程序所需要用到的存储,搭建模型链,基于文档的问答系统,评估与代理等。
4 |
5 | ### 目录
6 | 1. 简介 Introduction @Sarai
7 | 2. 模型,提示和解析器 Models, Prompts and Output Parsers @Joye
8 | 3. 存储 Memory @徐虎
9 | 4. 模型链 Chains @徐虎
10 | 5. 基于文档的问答 Question and Answer @苟晓攀
11 | 6. 评估 Evaluation @苟晓攀
12 | 7. 代理 Agent @Joye
13 | 8. 总结 Conclusion @Sarai
14 |
--------------------------------------------------------------------------------
/99~参考资料/2023~陆奇~我的大模型世界观.md:
--------------------------------------------------------------------------------
1 | # 陆奇
2 |
3 | 
4 |
5 | 
6 |
7 | 
8 |
9 | 
10 |
11 | 这张图是“三位一体结构演化模式”,本质是讲任何复杂体系,包括一个人、一家公司、一个社会,甚至数字化本身的数字化体系,都是复杂体系。“三位一体”包括:
12 |
13 | - “信息”系统(subsystem of information),从环境当中获得信息;
14 | - “模型”系统(subsystem of model),对信息做一种表达,进行推理和规划;
15 | - “行动”系统(subsystem of action),我们最终和环境做交互,达到人类想达到的目的。
16 |
17 | 我们可以得出一个简单结论。今天大部分数字化产品和公司,包括 Google、微软、阿里、字节,本质是信息搬运公司。一定要记住,我们所做的一切,一切的一切,包括在座的大部分企业都在搬运信息。Nothing more than that,You just move bytes(仅此而已,你只是移动字节)。但它已经足够好,改变了世界。
18 |
19 | 早在 1995-1996 年,通过 PC 互联网迎来一个拐点。那时我刚从 CMU(卡内基梅隆大学)毕业。大量公司层出不穷,其中诞生了一家伟大公司叫 Google。为什么会有这个拐点?为什么会有爆炸式增长?把这个观点讲清楚,就能把今天的拐点讲清楚。
20 |
21 | 原因是,获取信息的边际成本开始变成固定成本。一定要记住,任何改变社会、改变产业的,永远是结构性改变。这个结构性改变往往是一类大型成本,从边际成本变成固定成本。举个例子,我在 CMU 念书开车离开匹茨堡出去,一张地图 3 美元,获取信息很贵。今天我要地图,还是有价钱,但都变成固定价格。Google 平均一年付 10 亿美元做一张地图,但每个用户要获得地图的信息,基本上代价是 0。也就是说,获取信息成本变 0 的时候,它一定改变了所有产业。这就是过去 20 年发生的,今天基本是 free information everywhere(免费的信息无处不在)。
22 |
23 | 模型的成本开始从边际走向固定,大模型是技术核心、产业化基础。OpenAI 搭好了,发展速度爬升会很快。为什么模型这么重要、这个拐点这么重要,因为模型和人有内在关系。我们每个人都是模型的组合。人有三种模型:
24 |
25 | - 认知模型,我们能看、能听、能思考、能规划;
26 | - 任务模型,我们能爬楼梯、搬椅子剥鸡蛋;
27 | - 领域模型,我们有些人是医生,有些人是律师,有些人是码农。
28 |
29 | 通用智能四大要素是:涌现(emergence)+代理(agency)+功能可见性(affordence)+具象(embodiment)。
30 |
31 | The only way to make natural language work is you have knowledge(让自然语言处理有效的唯一路径是你有知识)。正好 Transformer 把这么多知识压缩在一起了,这是它的最大突破。
32 |
33 | 
34 |
35 | 这张图是整个人类技术驱动的创业创新,所有事情的机会都在这张图上。
36 |
37 | - 首先,底层是数字化的技术,因为数字化是人的延伸。数字化的基础里有平台,有发展基础,包括开源的代码、开源的设计、开源的数据;平台有前端、后端等。这里有大量机会。
38 | - 第二,波是用数字化的能力去解决人的需求。我们把数字化应用完整放在这张表上。
39 |
40 | 
41 |
42 | 
43 |
44 | 
45 |
46 | 
47 |
48 | 
49 |
50 | 
51 |
52 | 
53 |
54 | 
55 |
56 | 
57 |
58 | 
59 |
60 | 
61 |
62 | 
63 |
64 | 
65 |
66 | 
67 |
68 | 
69 |
70 | 
71 |
72 | 
73 |
74 | 
75 |
76 | 
77 |
78 | 
79 |
80 | 
81 |
82 | 
83 |
84 | 
85 |
86 | 
87 |
88 | 
89 |
90 | 
91 |
92 | 
93 |
94 | 
95 |
96 | 
97 |
98 | 
99 |
100 | 
101 |
102 | 
103 |
104 | 
105 |
106 | 
107 |
108 | 
109 |
110 | 
111 |
112 | 
113 |
114 | 
115 |
116 | 
117 |
118 | 
119 |
120 | 
121 |
122 | 
123 |
124 | 
125 |
126 | 
127 |
128 | 
129 |
130 | 
131 |
132 | 
133 |
134 | 
135 |
136 | 
137 |
138 | 
139 |
140 | 
141 |
142 | 
143 |
144 | 
145 |
146 | 
147 |
148 | 
149 |
150 | 
151 |
152 | 
153 |
154 | 
155 |
156 | 
157 |
158 | 
159 |
160 | 
161 |
--------------------------------------------------------------------------------
/INTRODUCTION.md:
--------------------------------------------------------------------------------
1 | # 本篇导读
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
2 | Public License
3 |
4 | By exercising the Licensed Rights (defined below), You accept and agree
5 | to be bound by the terms and conditions of this Creative Commons
6 | Attribution-NonCommercial-ShareAlike 4.0 International Public License
7 | ("Public License"). To the extent this Public License may be
8 | interpreted as a contract, You are granted the Licensed Rights in
9 | consideration of Your acceptance of these terms and conditions, and the
10 | Licensor grants You such rights in consideration of benefits the
11 | Licensor receives from making the Licensed Material available under
12 | these terms and conditions.
13 |
14 |
15 | Section 1 -- Definitions.
16 |
17 | a. Adapted Material means material subject to Copyright and Similar
18 | Rights that is derived from or based upon the Licensed Material
19 | and in which the Licensed Material is translated, altered,
20 | arranged, transformed, or otherwise modified in a manner requiring
21 | permission under the Copyright and Similar Rights held by the
22 | Licensor. For purposes of this Public License, where the Licensed
23 | Material is a musical work, performance, or sound recording,
24 | Adapted Material is always produced where the Licensed Material is
25 | synched in timed relation with a moving image.
26 |
27 | b. Adapter's License means the license You apply to Your Copyright
28 | and Similar Rights in Your contributions to Adapted Material in
29 | accordance with the terms and conditions of this Public License.
30 |
31 | c. BY-NC-SA Compatible License means a license listed at
32 | creativecommons.org/compatiblelicenses, approved by Creative
33 | Commons as essentially the equivalent of this Public License.
34 |
35 | d. Copyright and Similar Rights means copyright and/or similar rights
36 | closely related to copyright including, without limitation,
37 | performance, broadcast, sound recording, and Sui Generis Database
38 | Rights, without regard to how the rights are labeled or
39 | categorized. For purposes of this Public License, the rights
40 | specified in Section 2(b)(1)-(2) are not Copyright and Similar
41 | Rights.
42 |
43 | e. Effective Technological Measures means those measures that, in the
44 | absence of proper authority, may not be circumvented under laws
45 | fulfilling obligations under Article 11 of the WIPO Copyright
46 | Treaty adopted on December 20, 1996, and/or similar international
47 | agreements.
48 |
49 | f. Exceptions and Limitations means fair use, fair dealing, and/or
50 | any other exception or limitation to Copyright and Similar Rights
51 | that applies to Your use of the Licensed Material.
52 |
53 | g. License Elements means the license attributes listed in the name
54 | of a Creative Commons Public License. The License Elements of this
55 | Public License are Attribution, NonCommercial, and ShareAlike.
56 |
57 | h. Licensed Material means the artistic or literary work, database,
58 | or other material to which the Licensor applied this Public
59 | License.
60 |
61 | i. Licensed Rights means the rights granted to You subject to the
62 | terms and conditions of this Public License, which are limited to
63 | all Copyright and Similar Rights that apply to Your use of the
64 | Licensed Material and that the Licensor has authority to license.
65 |
66 | j. Licensor means the individual(s) or entity(ies) granting rights
67 | under this Public License.
68 |
69 | k. NonCommercial means not primarily intended for or directed towards
70 | commercial advantage or monetary compensation. For purposes of
71 | this Public License, the exchange of the Licensed Material for
72 | other material subject to Copyright and Similar Rights by digital
73 | file-sharing or similar means is NonCommercial provided there is
74 | no payment of monetary compensation in connection with the
75 | exchange.
76 |
77 | l. Share means to provide material to the public by any means or
78 | process that requires permission under the Licensed Rights, such
79 | as reproduction, public display, public performance, distribution,
80 | dissemination, communication, or importation, and to make material
81 | available to the public including in ways that members of the
82 | public may access the material from a place and at a time
83 | individually chosen by them.
84 |
85 | m. Sui Generis Database Rights means rights other than copyright
86 | resulting from Directive 96/9/EC of the European Parliament and of
87 | the Council of 11 March 1996 on the legal protection of databases,
88 | as amended and/or succeeded, as well as other essentially
89 | equivalent rights anywhere in the world.
90 |
91 | n. You means the individual or entity exercising the Licensed Rights
92 | under this Public License. Your has a corresponding meaning.
93 |
94 |
95 | Section 2 -- Scope.
96 |
97 | a. License grant.
98 |
99 | 1. Subject to the terms and conditions of this Public License,
100 | the Licensor hereby grants You a worldwide, royalty-free,
101 | non-sublicensable, non-exclusive, irrevocable license to
102 | exercise the Licensed Rights in the Licensed Material to:
103 |
104 | a. reproduce and Share the Licensed Material, in whole or
105 | in part, for NonCommercial purposes only; and
106 |
107 | b. produce, reproduce, and Share Adapted Material for
108 | NonCommercial purposes only.
109 |
110 | 2. Exceptions and Limitations. For the avoidance of doubt, where
111 | Exceptions and Limitations apply to Your use, this Public
112 | License does not apply, and You do not need to comply with
113 | its terms and conditions.
114 |
115 | 3. Term. The term of this Public License is specified in Section
116 | 6(a).
117 |
118 | 4. Media and formats; technical modifications allowed. The
119 | Licensor authorizes You to exercise the Licensed Rights in
120 | all media and formats whether now known or hereafter created,
121 | and to make technical modifications necessary to do so. The
122 | Licensor waives and/or agrees not to assert any right or
123 | authority to forbid You from making technical modifications
124 | necessary to exercise the Licensed Rights, including
125 | technical modifications necessary to circumvent Effective
126 | Technological Measures. For purposes of this Public License,
127 | simply making modifications authorized by this Section 2(a)
128 | (4) never produces Adapted Material.
129 |
130 | 5. Downstream recipients.
131 |
132 | a. Offer from the Licensor -- Licensed Material. Every
133 | recipient of the Licensed Material automatically
134 | receives an offer from the Licensor to exercise the
135 | Licensed Rights under the terms and conditions of this
136 | Public License.
137 |
138 | b. Additional offer from the Licensor -- Adapted Material.
139 | Every recipient of Adapted Material from You
140 | automatically receives an offer from the Licensor to
141 | exercise the Licensed Rights in the Adapted Material
142 | under the conditions of the Adapter's License You apply.
143 |
144 | c. No downstream restrictions. You may not offer or impose
145 | any additional or different terms or conditions on, or
146 | apply any Effective Technological Measures to, the
147 | Licensed Material if doing so restricts exercise of the
148 | Licensed Rights by any recipient of the Licensed
149 | Material.
150 |
151 | 6. No endorsement. Nothing in this Public License constitutes or
152 | may be construed as permission to assert or imply that You
153 | are, or that Your use of the Licensed Material is, connected
154 | with, or sponsored, endorsed, or granted official status by,
155 | the Licensor or others designated to receive attribution as
156 | provided in Section 3(a)(1)(A)(i).
157 |
158 | b. Other rights.
159 |
160 | 1. Moral rights, such as the right of integrity, are not
161 | licensed under this Public License, nor are publicity,
162 | privacy, and/or other similar personality rights; however, to
163 | the extent possible, the Licensor waives and/or agrees not to
164 | assert any such rights held by the Licensor to the limited
165 | extent necessary to allow You to exercise the Licensed
166 | Rights, but not otherwise.
167 |
168 | 2. Patent and trademark rights are not licensed under this
169 | Public License.
170 |
171 | 3. To the extent possible, the Licensor waives any right to
172 | collect royalties from You for the exercise of the Licensed
173 | Rights, whether directly or through a collecting society
174 | under any voluntary or waivable statutory or compulsory
175 | licensing scheme. In all other cases the Licensor expressly
176 | reserves any right to collect such royalties, including when
177 | the Licensed Material is used other than for NonCommercial
178 | purposes.
179 |
180 |
181 | Section 3 -- License Conditions.
182 |
183 | Your exercise of the Licensed Rights is expressly made subject to the
184 | following conditions.
185 |
186 | a. Attribution.
187 |
188 | 1. If You Share the Licensed Material (including in modified
189 | form), You must:
190 |
191 | a. retain the following if it is supplied by the Licensor
192 | with the Licensed Material:
193 |
194 | i. identification of the creator(s) of the Licensed
195 | Material and any others designated to receive
196 | attribution, in any reasonable manner requested by
197 | the Licensor (including by pseudonym if
198 | designated);
199 |
200 | ii. a copyright notice;
201 |
202 | iii. a notice that refers to this Public License;
203 |
204 | iv. a notice that refers to the disclaimer of
205 | warranties;
206 |
207 | v. a URI or hyperlink to the Licensed Material to the
208 | extent reasonably practicable;
209 |
210 | b. indicate if You modified the Licensed Material and
211 | retain an indication of any previous modifications; and
212 |
213 | c. indicate the Licensed Material is licensed under this
214 | Public License, and include the text of, or the URI or
215 | hyperlink to, this Public License.
216 |
217 | 2. You may satisfy the conditions in Section 3(a)(1) in any
218 | reasonable manner based on the medium, means, and context in
219 | which You Share the Licensed Material. For example, it may be
220 | reasonable to satisfy the conditions by providing a URI or
221 | hyperlink to a resource that includes the required
222 | information.
223 | 3. If requested by the Licensor, You must remove any of the
224 | information required by Section 3(a)(1)(A) to the extent
225 | reasonably practicable.
226 |
227 | b. ShareAlike.
228 |
229 | In addition to the conditions in Section 3(a), if You Share
230 | Adapted Material You produce, the following conditions also apply.
231 |
232 | 1. The Adapter's License You apply must be a Creative Commons
233 | license with the same License Elements, this version or
234 | later, or a BY-NC-SA Compatible License.
235 |
236 | 2. You must include the text of, or the URI or hyperlink to, the
237 | Adapter's License You apply. You may satisfy this condition
238 | in any reasonable manner based on the medium, means, and
239 | context in which You Share Adapted Material.
240 |
241 | 3. You may not offer or impose any additional or different terms
242 | or conditions on, or apply any Effective Technological
243 | Measures to, Adapted Material that restrict exercise of the
244 | rights granted under the Adapter's License You apply.
245 |
246 |
247 | Section 4 -- Sui Generis Database Rights.
248 |
249 | Where the Licensed Rights include Sui Generis Database Rights that
250 | apply to Your use of the Licensed Material:
251 |
252 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right
253 | to extract, reuse, reproduce, and Share all or a substantial
254 | portion of the contents of the database for NonCommercial purposes
255 | only;
256 |
257 | b. if You include all or a substantial portion of the database
258 | contents in a database in which You have Sui Generis Database
259 | Rights, then the database in which You have Sui Generis Database
260 | Rights (but not its individual contents) is Adapted Material,
261 | including for purposes of Section 3(b); and
262 |
263 | c. You must comply with the conditions in Section 3(a) if You Share
264 | all or a substantial portion of the contents of the database.
265 |
266 | For the avoidance of doubt, this Section 4 supplements and does not
267 | replace Your obligations under this Public License where the Licensed
268 | Rights include other Copyright and Similar Rights.
269 |
270 |
271 | Section 5 -- Disclaimer of Warranties and Limitation of Liability.
272 |
273 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
274 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
275 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
276 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
277 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
278 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
279 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
280 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
281 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
282 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
283 |
284 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
285 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
286 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
287 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
288 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
289 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
290 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
291 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
292 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
293 |
294 | c. The disclaimer of warranties and limitation of liability provided
295 | above shall be interpreted in a manner that, to the extent
296 | possible, most closely approximates an absolute disclaimer and
297 | waiver of all liability.
298 |
299 |
300 | Section 6 -- Term and Termination.
301 |
302 | a. This Public License applies for the term of the Copyright and
303 | Similar Rights licensed here. However, if You fail to comply with
304 | this Public License, then Your rights under this Public License
305 | terminate automatically.
306 |
307 | b. Where Your right to use the Licensed Material has terminated under
308 | Section 6(a), it reinstates:
309 |
310 | 1. automatically as of the date the violation is cured, provided
311 | it is cured within 30 days of Your discovery of the
312 | violation; or
313 |
314 | 2. upon express reinstatement by the Licensor.
315 |
316 | For the avoidance of doubt, this Section 6(b) does not affect any
317 | right the Licensor may have to seek remedies for Your violations
318 | of this Public License.
319 |
320 | c. For the avoidance of doubt, the Licensor may also offer the
321 | Licensed Material under separate terms or conditions or stop
322 | distributing the Licensed Material at any time; however, doing so
323 | will not terminate this Public License.
324 |
325 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
326 | License.
327 |
328 |
329 | Section 7 -- Other Terms and Conditions.
330 |
331 | a. The Licensor shall not be bound by any additional or different
332 | terms or conditions communicated by You unless expressly agreed.
333 |
334 | b. Any arrangements, understandings, or agreements regarding the
335 | Licensed Material not stated herein are separate from and
336 | independent of the terms and conditions of this Public License.
337 |
338 |
339 | Section 8 -- Interpretation.
340 |
341 | a. For the avoidance of doubt, this Public License does not, and
342 | shall not be interpreted to, reduce, limit, restrict, or impose
343 | conditions on any use of the Licensed Material that could lawfully
344 | be made without permission under this Public License.
345 |
346 | b. To the extent possible, if any provision of this Public License is
347 | deemed unenforceable, it shall be automatically reformed to the
348 | minimum extent necessary to make it enforceable. If the provision
349 | cannot be reformed, it shall be severed from this Public License
350 | without affecting the enforceability of the remaining terms and
351 | conditions.
352 |
353 | c. No term or condition of this Public License will be waived and no
354 | failure to comply consented to unless expressly agreed to by the
355 | Licensor.
356 |
357 | d. Nothing in this Public License constitutes or may be interpreted
358 | as a limitation upon, or waiver of, any privileges and immunities
359 | that apply to the Licensor or You, including from the legal
360 | processes of any jurisdiction or authority.
361 |
--------------------------------------------------------------------------------
/LLM/README.link:
--------------------------------------------------------------------------------
1 | https://github.com/wx-chevalier/LLM-Notes
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [![Contributors][contributors-shield]][contributors-url]
2 | [![Forks][forks-shield]][forks-url]
3 | [![Stargazers][stars-shield]][stars-url]
4 | [![Issues][issues-shield]][issues-url]
5 | [][license-url]
6 |
7 |
8 |
9 |