"{'text': 'Why did the tomato turn red? Because it saw the salad dressing!'}"
]
},
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"llm_chain(\"lame\", return_only_outputs=True)"
"llm_chain(\"corny\", return_only_outputs=True)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"If the `Chain` only takes one input key (i.e. only has one element in its `input_variables`), you can use `run` method. Note that `run` outputs a string instead of a dictionary."
"If the `Chain` only outputs one output key (i.e. only has one element in its `output_keys`), you can use `run` method. Note that `run` outputs a string instead of a dictionary."
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['text']"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# llm_chain only has one output key, so we can use run\n",
"llm_chain.output_keys"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
@ -201,47 +224,47 @@
"'Why did the tomato turn red? Because it saw the salad dressing!'"
]
},
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"llm_chain.run({\"adjective\":\"lame\"})"
"llm_chain.run({\"adjective\":\"corny\"})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Besides, in the case of one input key, you can input the string directly without specifying the input mapping."
"In the case of one input key, you can input the string directly without specifying the input mapping."
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'adjective': 'lame',\n",
"{'adjective': 'corny',\n",
" 'text': 'Why did the tomato turn red? Because it saw the salad dressing!'}"
]
},
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# These two are equivalent\n",
"llm_chain.run({\"adjective\":\"lame\"})\n",
"llm_chain.run(\"lame\")\n",
"llm_chain.run({\"adjective\":\"corny\"})\n",
"llm_chain.run(\"corny\")\n",
"\n",
"# These two are also equivalent\n",
"llm_chain(\"lame\")\n",
"llm_chain({\"adjective\":\"lame\"})"
"llm_chain(\"corny\")\n",
"llm_chain({\"adjective\":\"corny\"})"
]
},
{
@ -262,7 +285,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 9,
"metadata": {},
"outputs": [
{
@ -271,7 +294,7 @@
"'The next four colors of a rainbow are green, blue, indigo, and violet.'"
]
},
"execution_count": 11,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
@ -309,7 +332,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 10,
"metadata": {},
"outputs": [
{
@ -336,7 +359,7 @@
"'ChatGPT is an AI language model developed by OpenAI. It is based on the GPT-3 architecture and is capable of generating human-like responses to text prompts. ChatGPT has been trained on a massive amount of text data and can understand and respond to a wide range of topics. It is often used for chatbots, virtual assistants, and other conversational AI applications.'"