2023-03-28 18:56:57 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Replicate\n",
"\n",
2023-04-18 03:25:32 +00:00
">[Replicate](https://replicate.com/blog/machine-learning-needs-better-tools) runs machine learning models in the cloud. We have a library of open-source models that you can run with a few lines of code. If you're building your own machine learning models, Replicate makes it easy to deploy them at scale.\n",
"\n",
"This example goes over how to use LangChain to interact with `Replicate` [models](https://replicate.com/explore)"
2023-03-28 18:56:57 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2023-04-04 19:15:03 +00:00
"## Setup"
2023-03-28 18:56:57 +00:00
]
},
{
2023-07-21 01:59:54 +00:00
"cell_type": "code",
"execution_count": 1,
2023-03-28 18:56:57 +00:00
"metadata": {},
2023-07-21 01:59:54 +00:00
"outputs": [],
2023-03-28 18:56:57 +00:00
"source": [
2023-07-21 01:59:54 +00:00
"# magics to auto-reload external modules in case you are making changes to langchain while working on this notebook\n",
"%load_ext autoreload\n",
"%autoreload 2"
2023-03-28 18:56:57 +00:00
]
},
2023-04-18 03:25:32 +00:00
{
2023-07-21 01:59:54 +00:00
"cell_type": "markdown",
"metadata": {},
2023-04-18 03:25:32 +00:00
"source": [
2023-07-21 01:59:54 +00:00
"To run this notebook, you'll need to create a [replicate](https://replicate.com) account and install the [replicate python client](https://github.com/replicate/replicate-python)."
2023-04-18 03:25:32 +00:00
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"tags": []
},
"outputs": [
{
Fix Replicate llm response to handle iterator / multiple outputs (#3614)
One of our users noticed a bug when calling streaming models. This is
because those models return an iterator. So, I've updated the Replicate
`_call` code to join together the output. The other advantage of this
fix is that if you requested multiple outputs you would get them all –
previously I was just returning output[0].
I also adjusted the demo docs to use dolly, because we're featuring that
model right now and it's always hot, so people won't have to wait for
the model to boot up.
The error that this fixes:
```
> llm = Replicate(model=“replicate/flan-t5-xl:eec2f71c986dfa3b7a5d842d22e1130550f015720966bec48beaae059b19ef4c”)
> llm(“hello”)
> Traceback (most recent call last):
File "/Users/charlieholtz/workspace/dev/python/main.py", line 15, in <module>
print(llm(prompt))
File "/opt/homebrew/lib/python3.10/site-packages/langchain/llms/base.py", line 246, in __call__
return self.generate([prompt], stop=stop).generations[0][0].text
File "/opt/homebrew/lib/python3.10/site-packages/langchain/llms/base.py", line 140, in generate
raise e
File "/opt/homebrew/lib/python3.10/site-packages/langchain/llms/base.py", line 137, in generate
output = self._generate(prompts, stop=stop)
File "/opt/homebrew/lib/python3.10/site-packages/langchain/llms/base.py", line 324, in _generate
text = self._call(prompt, stop=stop)
File "/opt/homebrew/lib/python3.10/site-packages/langchain/llms/replicate.py", line 108, in _call
return outputs[0]
TypeError: 'generator' object is not subscriptable
```
2023-04-26 21:26:33 +00:00
"name": "stdout",
2023-04-18 03:25:32 +00:00
"output_type": "stream",
"text": [
2023-07-21 01:59:54 +00:00
"Requirement already satisfied: replicate in /root/Source/github/docugami.langchain/.venv/lib/python3.9/site-packages (0.9.0)\n",
"Requirement already satisfied: packaging in /root/Source/github/docugami.langchain/.venv/lib/python3.9/site-packages (from replicate) (23.1)\n",
"Requirement already satisfied: pydantic>1 in /root/Source/github/docugami.langchain/.venv/lib/python3.9/site-packages (from replicate) (1.10.9)\n",
"Requirement already satisfied: requests>2 in /root/Source/github/docugami.langchain/.venv/lib/python3.9/site-packages (from replicate) (2.28.2)\n",
"Requirement already satisfied: typing-extensions>=4.2.0 in /root/Source/github/docugami.langchain/.venv/lib/python3.9/site-packages (from pydantic>1->replicate) (4.5.0)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /root/Source/github/docugami.langchain/.venv/lib/python3.9/site-packages (from requests>2->replicate) (3.1.0)\n",
"Requirement already satisfied: idna<4,>=2.5 in /root/Source/github/docugami.langchain/.venv/lib/python3.9/site-packages (from requests>2->replicate) (3.4)\n",
"Requirement already satisfied: urllib3<1.27,>=1.21.1 in /root/Source/github/docugami.langchain/.venv/lib/python3.9/site-packages (from requests>2->replicate) (1.26.16)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /root/Source/github/docugami.langchain/.venv/lib/python3.9/site-packages (from requests>2->replicate) (2023.5.7)\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.2\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
2023-04-18 03:25:32 +00:00
]
}
],
2023-07-21 01:59:54 +00:00
"source": [
"!pip install replicate"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"tags": []
},
"outputs": [],
2023-04-18 03:25:32 +00:00
"source": [
"# get a token: https://replicate.com/account\n",
"\n",
"from getpass import getpass\n",
"\n",
"REPLICATE_API_TOKEN = getpass()"
]
},
{
"cell_type": "code",
2023-07-21 01:59:54 +00:00
"execution_count": 4,
2023-04-18 03:25:32 +00:00
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import os\n",
"\n",
"os.environ[\"REPLICATE_API_TOKEN\"] = REPLICATE_API_TOKEN"
]
},
{
"cell_type": "code",
2023-07-21 01:59:54 +00:00
"execution_count": 5,
2023-04-18 03:25:32 +00:00
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from langchain.llms import Replicate\n",
"from langchain import PromptTemplate, LLMChain"
]
},
2023-03-28 18:56:57 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
2023-04-04 19:15:03 +00:00
"## Calling a model\n",
2023-03-28 18:56:57 +00:00
"\n",
2023-07-18 19:09:09 +00:00
"Find a model on the [replicate explore page](https://replicate.com/explore), and then paste in the model name and version in this format: model_name/version.\n",
2023-03-28 18:56:57 +00:00
"\n",
2023-07-18 19:09:09 +00:00
"For example, here is [`LLama-V2`](https://replicate.com/a16z-infra/llama13b-v2-chat)."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2023-07-21 01:59:54 +00:00
"'1. Can a dog operate a vehicle? No.\\n2. Do dogs have hands to manipulate the pedals and steering wheel? No.\\n3. Can dogs see well enough to drive? No.\\n4. Does a dog have the cognitive ability to understand traffic laws and make safe driving decisions? No.\\n\\nTherefore, the answer is no, a dog cannot drive a car.'"
2023-07-18 19:09:09 +00:00
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"llm = Replicate(\n",
" model=\"a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5\",\n",
" input={\"temperature\": 0.75, \"max_length\": 500, \"top_p\": 1},\n",
")\n",
"prompt = \"\"\"\n",
"User: Answer the following yes/no question by reasoning step by step. Can a dog drive a car?\n",
"Assistant:\n",
"\"\"\"\n",
"llm(prompt)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As another example, for this [dolly model](https://replicate.com/replicate/dolly-v2-12b), click on the API tab. The model name/version would be: `replicate/dolly-v2-12b:ef0e1aefc61f8e096ebe4db6b2bacc297daf2ef6899f0f7e001ec445893500e5`\n",
2023-03-28 18:56:57 +00:00
"\n",
"Only the `model` param is required, but we can add other model params when initializing.\n",
"\n",
"For example, if we were running stable diffusion and wanted to change the image dimensions:\n",
"\n",
"```\n",
"Replicate(model=\"stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf\", input={'image_dimensions': '512x512'})\n",
"```\n",
" \n",
"*Note that only the first output of a model will be returned.*"
]
},
{
"cell_type": "code",
2023-07-21 01:59:54 +00:00
"execution_count": 26,
2023-04-18 03:25:32 +00:00
"metadata": {
"tags": []
},
2023-03-28 18:56:57 +00:00
"outputs": [],
"source": [
2023-06-16 18:52:56 +00:00
"llm = Replicate(\n",
" model=\"replicate/dolly-v2-12b:ef0e1aefc61f8e096ebe4db6b2bacc297daf2ef6899f0f7e001ec445893500e5\"\n",
")"
2023-03-28 18:56:57 +00:00
]
},
{
"cell_type": "code",
2023-07-21 01:59:54 +00:00
"execution_count": 27,
2023-03-28 18:56:57 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2023-07-21 01:59:54 +00:00
"'It depends on how you define \"can\". Because dogs do have four legs, they are clearly able to move around in a car; it might even be possible for them to drive given proper training and enough motivation (e.g., food or comfort). From a legal perspective however, there are many reasons why this would not make sense at all: Dogs lack some of the vital capabilities required to safely operate a vehicle; their behaviour may differ significantly compared to humans due to their weaker cognitive abilities versus ours; and there could also exist valid concerns about safety since we don\\'t really know what happens when two species with different psychological characteristics are put together under stressful conditions. Therefore, no, a dog cannot legally drive a car.\\n\\n'"
2023-03-28 18:56:57 +00:00
]
},
2023-07-21 01:59:54 +00:00
"execution_count": 27,
2023-03-28 18:56:57 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"prompt = \"\"\"\n",
"Answer the following yes/no question by reasoning step by step. \n",
"Can a dog drive a car?\n",
"\"\"\"\n",
"llm(prompt)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can call any replicate model using this syntax. For example, we can call stable diffusion."
]
},
{
"cell_type": "code",
2023-07-21 01:59:54 +00:00
"execution_count": 28,
2023-03-28 18:56:57 +00:00
"metadata": {},
"outputs": [],
"source": [
2023-06-16 18:52:56 +00:00
"text2image = Replicate(\n",
" model=\"stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf\",\n",
" input={\"image_dimensions\": \"512x512\"},\n",
")"
2023-03-28 18:56:57 +00:00
]
},
{
"cell_type": "code",
2023-07-21 01:59:54 +00:00
"execution_count": 29,
2023-03-28 18:56:57 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2023-07-21 01:59:54 +00:00
"'https://replicate.delivery/pbxt/j0nlxW0aoh7LExWGfdvyfgkmKA2GQWcF6e1wkYNWfoSakkHFB/out-0.png'"
2023-03-28 18:56:57 +00:00
]
},
2023-07-21 01:59:54 +00:00
"execution_count": 29,
2023-03-28 18:56:57 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"image_output = text2image(\"A cat riding a motorcycle by Picasso\")\n",
"image_output"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The model spits out a URL. Let's render it."
]
},
{
"cell_type": "code",
2023-07-21 01:59:54 +00:00
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: Pillow in /root/Source/github/docugami.langchain/.venv/lib/python3.9/site-packages (10.0.0)\n"
]
}
],
"source": [
"!pip install Pillow"
]
},
{
"cell_type": "code",
"execution_count": 30,
2023-03-28 18:56:57 +00:00
"metadata": {},
"outputs": [
{
"data": {
2023-07-21 01:59:54 +00:00
"image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAIAAgADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAEC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023-07-21 01:59:54 +00:00
"<PIL.PngImagePlugin.PngImageFile image mode=RGB size=512x512>"
2023-03-28 18:56:57 +00:00
]
},
2023-07-21 01:59:54 +00:00
"execution_count": 30,
2023-03-28 18:56:57 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from PIL import Image\n",
"import requests\n",
"from io import BytesIO\n",
"\n",
"response = requests.get(image_output)\n",
"img = Image.open(BytesIO(response.content))\n",
"\n",
"img"
]
},
2023-07-21 01:59:54 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Streaming Response\n",
"You can optionally stream the response as it is produced, which is helpful to show interactivity to users for time-consuming generations. See detailed docs on [Streaming](https://python.langchain.com/docs/modules/model_io/models/llms/how_to/streaming_llm) for more information."
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1. Dogs do not have the ability to operate complex machinery, such as cars.\n",
"2. Dogs do not have the cognitive ability to understand the concept of driving.\n",
"3. Dogs do not have the physical ability to reach the pedals or steering wheel of a car.\n",
"4. Dogs do not have the ability to communicate their intentions to other drivers or pedestrians.\n",
"\n",
"Therefore, the answer is no, a dog cannot drive a car."
]
}
],
"source": [
"from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n",
"\n",
"llm = Replicate(\n",
" streaming=True,\n",
" callbacks=[StreamingStdOutCallbackHandler()],\n",
" model=\"a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5\",\n",
" input={\"temperature\": 0.75, \"max_length\": 500, \"top_p\": 1},\n",
")\n",
"prompt = \"\"\"\n",
"User: Answer the following yes/no question by reasoning step by step. Can a dog drive a car?\n",
"Assistant:\n",
"\"\"\"\n",
"_ = llm(prompt)"
]
},
2023-03-28 18:56:57 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
2023-04-04 19:15:03 +00:00
"## Chaining Calls\n",
2023-03-28 18:56:57 +00:00
"The whole point of langchain is to... chain! Here's an example of how do that."
]
},
{
"cell_type": "code",
2023-07-21 01:59:54 +00:00
"execution_count": 14,
2023-03-28 18:56:57 +00:00
"metadata": {},
"outputs": [],
"source": [
"from langchain.chains import SimpleSequentialChain"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First, let's define the LLM for this model as a flan-5, and text2image as a stable diffusion model."
]
},
{
"cell_type": "code",
2023-07-21 01:59:54 +00:00
"execution_count": 15,
2023-03-28 18:56:57 +00:00
"metadata": {},
"outputs": [],
"source": [
2023-06-16 18:52:56 +00:00
"dolly_llm = Replicate(\n",
" model=\"replicate/dolly-v2-12b:ef0e1aefc61f8e096ebe4db6b2bacc297daf2ef6899f0f7e001ec445893500e5\"\n",
")\n",
"text2image = Replicate(\n",
" model=\"stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf\"\n",
")"
2023-03-28 18:56:57 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First prompt in the chain"
]
},
{
"cell_type": "code",
2023-07-21 01:59:54 +00:00
"execution_count": 16,
2023-03-28 18:56:57 +00:00
"metadata": {},
"outputs": [],
"source": [
"prompt = PromptTemplate(\n",
" input_variables=[\"product\"],\n",
" template=\"What is a good name for a company that makes {product}?\",\n",
")\n",
"\n",
Fix Replicate llm response to handle iterator / multiple outputs (#3614)
One of our users noticed a bug when calling streaming models. This is
because those models return an iterator. So, I've updated the Replicate
`_call` code to join together the output. The other advantage of this
fix is that if you requested multiple outputs you would get them all –
previously I was just returning output[0].
I also adjusted the demo docs to use dolly, because we're featuring that
model right now and it's always hot, so people won't have to wait for
the model to boot up.
The error that this fixes:
```
> llm = Replicate(model=“replicate/flan-t5-xl:eec2f71c986dfa3b7a5d842d22e1130550f015720966bec48beaae059b19ef4c”)
> llm(“hello”)
> Traceback (most recent call last):
File "/Users/charlieholtz/workspace/dev/python/main.py", line 15, in <module>
print(llm(prompt))
File "/opt/homebrew/lib/python3.10/site-packages/langchain/llms/base.py", line 246, in __call__
return self.generate([prompt], stop=stop).generations[0][0].text
File "/opt/homebrew/lib/python3.10/site-packages/langchain/llms/base.py", line 140, in generate
raise e
File "/opt/homebrew/lib/python3.10/site-packages/langchain/llms/base.py", line 137, in generate
output = self._generate(prompts, stop=stop)
File "/opt/homebrew/lib/python3.10/site-packages/langchain/llms/base.py", line 324, in _generate
text = self._call(prompt, stop=stop)
File "/opt/homebrew/lib/python3.10/site-packages/langchain/llms/replicate.py", line 108, in _call
return outputs[0]
TypeError: 'generator' object is not subscriptable
```
2023-04-26 21:26:33 +00:00
"chain = LLMChain(llm=dolly_llm, prompt=prompt)"
2023-03-28 18:56:57 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Second prompt to get the logo for company description"
]
},
{
"cell_type": "code",
2023-07-21 01:59:54 +00:00
"execution_count": 17,
2023-03-28 18:56:57 +00:00
"metadata": {},
"outputs": [],
"source": [
"second_prompt = PromptTemplate(\n",
" input_variables=[\"company_name\"],\n",
" template=\"Write a description of a logo for this company: {company_name}\",\n",
")\n",
Fix Replicate llm response to handle iterator / multiple outputs (#3614)
One of our users noticed a bug when calling streaming models. This is
because those models return an iterator. So, I've updated the Replicate
`_call` code to join together the output. The other advantage of this
fix is that if you requested multiple outputs you would get them all –
previously I was just returning output[0].
I also adjusted the demo docs to use dolly, because we're featuring that
model right now and it's always hot, so people won't have to wait for
the model to boot up.
The error that this fixes:
```
> llm = Replicate(model=“replicate/flan-t5-xl:eec2f71c986dfa3b7a5d842d22e1130550f015720966bec48beaae059b19ef4c”)
> llm(“hello”)
> Traceback (most recent call last):
File "/Users/charlieholtz/workspace/dev/python/main.py", line 15, in <module>
print(llm(prompt))
File "/opt/homebrew/lib/python3.10/site-packages/langchain/llms/base.py", line 246, in __call__
return self.generate([prompt], stop=stop).generations[0][0].text
File "/opt/homebrew/lib/python3.10/site-packages/langchain/llms/base.py", line 140, in generate
raise e
File "/opt/homebrew/lib/python3.10/site-packages/langchain/llms/base.py", line 137, in generate
output = self._generate(prompts, stop=stop)
File "/opt/homebrew/lib/python3.10/site-packages/langchain/llms/base.py", line 324, in _generate
text = self._call(prompt, stop=stop)
File "/opt/homebrew/lib/python3.10/site-packages/langchain/llms/replicate.py", line 108, in _call
return outputs[0]
TypeError: 'generator' object is not subscriptable
```
2023-04-26 21:26:33 +00:00
"chain_two = LLMChain(llm=dolly_llm, prompt=second_prompt)"
2023-03-28 18:56:57 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Third prompt, let's create the image based on the description output from prompt 2"
]
},
{
"cell_type": "code",
2023-07-21 01:59:54 +00:00
"execution_count": 18,
2023-03-28 18:56:57 +00:00
"metadata": {},
"outputs": [],
"source": [
"third_prompt = PromptTemplate(\n",
" input_variables=[\"company_logo_description\"],\n",
" template=\"{company_logo_description}\",\n",
")\n",
"chain_three = LLMChain(llm=text2image, prompt=third_prompt)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now let's run it!"
]
},
{
"cell_type": "code",
2023-07-21 01:59:54 +00:00
"execution_count": 19,
2023-03-28 18:56:57 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\u001b[1m> Entering new SimpleSequentialChain chain...\u001b[0m\n",
2023-07-21 01:59:54 +00:00
"\u001b[36;1m\u001b[1;3m colorsocks.com\n",
"\n",
"\u001b[0m\n",
"\u001b[33;1m\u001b[1;3mA stylized letter \"s\" in red, white and blue colors with a bright light shining through it, reminiscent of the sunlight streaming through a clear summer sky.\n",
"\n",
"\n",
"\u001b[0m\n",
"\u001b[38;5;200m\u001b[1;3mhttps://replicate.delivery/pbxt/Qau0h94c8e1xX6DnW4tHubR5vmdrdXJZh39cycjrjb3Wf3RRA/out-0.png\u001b[0m\n",
2023-03-28 18:56:57 +00:00
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n",
2023-07-21 01:59:54 +00:00
"https://replicate.delivery/pbxt/Qau0h94c8e1xX6DnW4tHubR5vmdrdXJZh39cycjrjb3Wf3RRA/out-0.png\n"
2023-03-28 18:56:57 +00:00
]
}
],
"source": [
"# Run the chain specifying only the input variable for the first chain.\n",
2023-06-16 18:52:56 +00:00
"overall_chain = SimpleSequentialChain(\n",
" chains=[chain, chain_two, chain_three], verbose=True\n",
")\n",
2023-03-28 18:56:57 +00:00
"catchphrase = overall_chain.run(\"colorful socks\")\n",
"print(catchphrase)"
]
},
{
"cell_type": "code",
2023-07-21 01:59:54 +00:00
"execution_count": 24,
2023-03-28 18:56:57 +00:00
"metadata": {},
"outputs": [
{
"data": {
2023-07-21 01:59:54 +00:00
"image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAMAAwADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dX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bgPVEXbYO+220ZZFNp20Yk3zcbhmL0Nc7scEbUeIBHSutRmmH+A2szW1gFR6Pm+2SPbhbsZI3/dN6v/642uzIjv16QZsRCK1je9gd3Pz6H/fGnWavf2BVbz6e9to+YR7g2y9mx6oyW8Zsdzipfnq3qTeqxXL9uGi3sVJ9M5vjJtqmms3YsLW1GR0byHR76ow6x/16z9R+9dCaDJfLx9PV4tkXX5j67A+/r775od+47H5Y1z4cWstVq8ek3e4R22pBjjQW3Vrj0KoqIiLzZaS365vtGoR24+XhbrrtdbcPT00IPzZW/ffHYYdsxvq9Tz85jLrHbmfw6vmO+KnX25eXrKUTTw+gSPfBCE21G+0IC5QBsq0mAw7i29yw/ZYGiSypdjHeL4YYfbtarVDL9tDuRsRhBwqWdYIr0Qzc99rt/WFbmSl7xSR2RwbSiVODxGssMYr25DrZSJ3AmR4RC2LDjr4eN7tqXS0KkfSH42iLxmk47FMU60XlFW5PDOzdnmrarbd0M0RTWTF0NEbbNxq7NSZBrayEMEWtW2cAbNYbM261uoSQkRR6ruFcD68qNi7J2eh1+U3hEGMJhaM59hYzT3OGGo5skcy8FMI+Jj+B3Ix9E+9Gm5491KmiwoM1XMtgiC+D0shzll2ENPanV5uDLu96i8jJeN4GsU0T8TqQbf41671Ot9hesYYimKtdhHsY9mrfeCBIuj0jBTsogiui4tjuttEyPYMB3akBKgcJYrZRAt12t9ZpRWxoJgYaR2CHgPerTb3bxQqdDiMsRvJuud0tN0wjZhkZcMI1rB4e86rihHMiSacmnogJhkLir5PVcbXjm1GMp06nxTFDVzCAazF
2023-03-28 18:56:57 +00:00
"text/plain": [
2023-07-21 01:59:54 +00:00
"<PIL.PngImagePlugin.PngImageFile image mode=RGB size=768x768>"
2023-03-28 18:56:57 +00:00
]
},
2023-07-21 01:59:54 +00:00
"execution_count": 24,
2023-03-28 18:56:57 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2023-06-16 18:52:56 +00:00
"response = requests.get(\n",
2023-07-21 01:59:54 +00:00
" \"https://replicate.delivery/pbxt/Qau0h94c8e1xX6DnW4tHubR5vmdrdXJZh39cycjrjb3Wf3RRA/out-0.png\"\n",
2023-06-16 18:52:56 +00:00
")\n",
2023-03-28 18:56:57 +00:00
"img = Image.open(BytesIO(response.content))\n",
"img"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2023-07-18 19:09:09 +00:00
"version": "3.9.16"
2023-03-28 18:56:57 +00:00
},
"vscode": {
"interpreter": {
"hash": "a0a0263b650d907a3bfe41c0f8d6a63a071b884df3cfdc1579f00cdc1aed6b03"
}
}
},
"nbformat": 4,
2023-04-18 03:25:32 +00:00
"nbformat_minor": 4
2023-03-28 18:56:57 +00:00
}