modified: "content/LangChain for LLM Application Development/2.\346\250\241\345\236\213\343\200\201\346\217\220\347\244\272\345\222\214\350\247\243\346\236\220\345\231\250.ipynb"

This commit is contained in:
nowadays0421
2023-06-04 11:13:09 +08:00
parent 0130ecb936
commit 8917bbb174

View File

@ -32,10 +32,8 @@
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"tags": []
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 下载需要的包python-dotenv和openai\n",
@ -46,7 +44,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {
"tags": []
},
@ -82,7 +80,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"metadata": {
"tags": []
},
@ -117,7 +115,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
@ -126,7 +124,7 @@
"'1+1等于2。'"
]
},
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
@ -352,7 +350,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 6,
"metadata": {
"tags": []
},
@ -363,7 +361,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 7,
"metadata": {
"tags": []
},
@ -374,7 +372,7 @@
"ChatOpenAI(verbose=False, callbacks=None, callback_manager=None, client=<class 'openai.api_resources.chat_completion.ChatCompletion'>, model_name='gpt-3.5-turbo', temperature=0.0, model_kwargs={}, openai_api_key=None, openai_api_base=None, openai_organization=None, openai_proxy=None, request_timeout=None, max_retries=6, streaming=False, n=1, max_tokens=None)"
]
},
"execution_count": 13,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@ -425,7 +423,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 8,
"metadata": {
"tags": []
},
@ -449,19 +447,20 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 9,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# 需要安装最新版的 LangChain\n",
"from langchain.prompts import ChatPromptTemplate\n",
"prompt_template = ChatPromptTemplate.from_template(template_string)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 10,
"metadata": {
"tags": []
},
@ -472,7 +471,7 @@
"PromptTemplate(input_variables=['style', 'text'], output_parser=None, partial_variables={}, template='Translate the text that is delimited by triple backticks into a style that is {style}. text: ```{text}```\\n', template_format='f-string', validate_template=True)"
]
},
"execution_count": 16,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
@ -491,7 +490,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 7,
"metadata": {
"tags": []
},
@ -502,7 +501,7 @@
"['style', 'text']"
]
},
"execution_count": 17,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@ -525,7 +524,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 11,
"metadata": {
"tags": []
},
@ -538,7 +537,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 12,
"metadata": {
"tags": []
},
@ -564,7 +563,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 13,
"metadata": {
"tags": []
},
@ -577,7 +576,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 11,
"metadata": {
"tags": []
},
@ -608,7 +607,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 12,
"metadata": {
"tags": []
},
@ -637,7 +636,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 14,
"metadata": {
"tags": []
},
@ -648,7 +647,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 15,
"metadata": {
"tags": []
},
@ -657,7 +656,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"I'm really frustrated that my blender lid flew off and made a mess of my kitchen walls with smoothie. To add to my frustration, the warranty doesn't cover the cost of cleaning up my kitchen. Can you please help me out, friend?\n"
"I'm really frustrated that my blender lid flew off and made a mess of my kitchen walls with smoothie. To add insult to injury, the warranty doesn't cover the cost of cleaning up my kitchen. Can you please help me out, friend?\n"
]
}
],
@ -679,7 +678,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 16,
"metadata": {
"tags": []
},
@ -698,7 +697,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 17,
"metadata": {
"tags": []
},
@ -712,7 +711,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 18,
"metadata": {
"tags": []
},
@ -747,7 +746,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 19,
"metadata": {
"tags": []
},
@ -756,7 +755,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Ahoy there, matey! I must kindly inform ye that the warranty be not coverin' the expenses o' cleaning yer galley, as 'tis yer own fault fer misusin' yer blender by forgettin' to put the lid on afore startin' it. Aye, tough luck! Farewell and may the winds be in yer favor!\n"
"Ahoy there, me hearty customer! I be sorry to inform ye that the warranty be not coverin' the expenses o' cleaning yer galley, as 'tis yer own fault fer misusin' yer blender by forgettin' to put the lid on afore startin' it. Aye, tough luck! Farewell and may the winds be in yer favor!\n"
]
}
],
@ -889,7 +888,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
@ -916,7 +915,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
@ -951,7 +950,7 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 22,
"metadata": {},
"outputs": [
{
@ -978,7 +977,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
@ -995,7 +994,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 24,
"metadata": {},
"outputs": [
{