From b37562180bac7c0a2221d1ba72318862781f533e Mon Sep 17 00:00:00 2001 From: nowadays0421 Date: Sat, 3 Jun 2023 11:24:45 +0800 Subject: [PATCH] modified: content/LangChain for LLM Application Development/2.Models_Prompts_and_Parsers.ipynb --- .../2.Models_Prompts_and_Parsers.ipynb | 66 +++++++++++++++---- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/content/LangChain for LLM Application Development/2.Models_Prompts_and_Parsers.ipynb b/content/LangChain for LLM Application Development/2.Models_Prompts_and_Parsers.ipynb index c82868a..0eb5a56 100644 --- a/content/LangChain for LLM Application Development/2.Models_Prompts_and_Parsers.ipynb +++ b/content/LangChain for LLM Application Development/2.Models_Prompts_and_Parsers.ipynb @@ -1,6 +1,7 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -18,6 +19,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "tags": [] @@ -32,10 +34,7 @@ "cell_type": "code", "execution_count": 1, "metadata": { - "tags": [], - "vscode": { - "languageId": "plaintext" - } + "tags": [] }, "outputs": [], "source": [ @@ -49,10 +48,7 @@ "cell_type": "code", "execution_count": 2, "metadata": { - "tags": [], - "vscode": { - "languageId": "plaintext" - } + "tags": [] }, "outputs": [], "source": [ @@ -61,10 +57,12 @@ "\n", "from dotenv import load_dotenv, find_dotenv\n", "_ = load_dotenv(find_dotenv()) # read local .env file\n", + "# 导入 OpenAI API_KEY\n", "openai.api_key = os.environ['OPENAI_API_KEY']" ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "tags": [] @@ -77,9 +75,9 @@ "`get_completion`函数是基于`openai`的封装函数,对于给定提示(prompt)输出相应的回答。其包含两个参数\n", " \n", " - `prompt` 必需输入参数。 你给模型的提示,可以是一个问题,可以是你需要模型帮助你做的事(改变文本写作风格,翻译,回复消息等等)。\n", - " - `model` 非必需输入参数。默认为gpt-3.5-turbo,也就是说默认模型是gpt-3.5-turbo。 你也可以选择其他模型。\n", + " - `model` 非必需输入参数。默认使用gpt-3.5-turbo。你也可以选择其他模型。\n", " \n", - "这里的提示对应我们在chatgpt中对问题,函数给出的输出则对应chatpgt给我们的答案。" + "这里的提示对应我们给chatgpt的问题,函数给出的输出则对应chatpgt给我们的答案。" ] }, { @@ -103,6 +101,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "tags": [] @@ -159,6 +158,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -168,7 +168,7 @@ "\n", "现在我们来看一个复杂一点的例子: \n", "\n", - "假设我们是电商公司某逊,我们的顾客是一名海盗A,他在我们的网站上买了一榨汁机用来做奶昔,在制作奶昔的过程中,奶昔的盖子飞了出去,弄得厨房墙上到处都是。于是海盗A给我们的客服中心写来以下邮件:`customer_email`" + "假设我们是电商公司员工,我们的顾客是一名海盗A,他在我们的网站上买了一个榨汁机用来做奶昔,在制作奶昔的过程中,奶昔的盖子飞了出去,弄得厨房墙上到处都是。于是海盗A给我们的客服中心写来以下邮件:`customer_email`" ] }, { @@ -190,6 +190,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -209,12 +210,14 @@ }, "outputs": [], "source": [ + "# 美式英语 + 平静、尊敬的语调\n", "style = \"\"\"American English \\\n", "in a calm and respectful tone\n", "\"\"\"" ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -243,6 +246,7 @@ } ], "source": [ + "# 要求模型根据给出的语调进行转化\n", "prompt = f\"\"\"Translate the text \\\n", "that is delimited by triple backticks \n", "into a style that is {style}.\n", @@ -253,6 +257,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -293,6 +298,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -306,6 +312,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "tags": [] @@ -332,6 +339,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "tags": [] @@ -339,7 +347,7 @@ "source": [ "### 模型\n", "\n", - "从`langchain.chat_models`倒入`OpenAI`的对话模型`ChatOpenAI`。 除去OpenAI以外,`langchain.chat_models`还集成了其他对话模型,更多细节可以查看[Langchain官方文档](https://python.langchain.com/en/latest/modules/models/chat/integrations.html)。" + "从`langchain.chat_models`导入`OpenAI`的对话模型`ChatOpenAI`。 除去OpenAI以外,`langchain.chat_models`还集成了其他对话模型,更多细节可以查看[Langchain官方文档](https://python.langchain.com/en/latest/modules/models/chat/integrations.html)。" ] }, { @@ -379,6 +387,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -386,6 +395,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -404,6 +414,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -428,6 +439,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -470,6 +482,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -499,6 +512,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -541,6 +555,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -582,6 +597,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -610,6 +626,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -649,6 +666,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -718,6 +736,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -747,6 +766,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "tags": [] @@ -758,11 +778,12 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "\n", - "在应用于比较复杂的长江时,提示可能会非常长并且包含涉及许多细节。使用提示模版,可以让我们更为方便地重复使用设计好的提示。\n", + "在应用于比较复杂的场景时,提示可能会非常长并且包含涉及许多细节。使用提示模版,可以让我们更为方便地重复使用设计好的提示。\n", "\n", "下面给出了一个比较长的提示模版案例。学生们线上学习并提交作业,通过以下的提示来实现对学生的提交的作业的评分。\n", "\n", @@ -841,6 +862,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -848,6 +870,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -884,6 +907,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -918,6 +942,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -944,6 +969,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -960,6 +986,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -990,6 +1017,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -1039,6 +1067,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -1046,6 +1075,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -1077,6 +1107,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -1093,6 +1124,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -1152,6 +1184,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -1205,6 +1238,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -1236,6 +1270,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -1266,6 +1301,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -1314,6 +1350,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -1321,6 +1358,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -1398,7 +1436,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.12" + "version": "3.10.11" } }, "nbformat": 4,