|
24 | 24 | },
|
25 | 25 | {
|
26 | 26 | "cell_type": "code",
|
27 |
| - "execution_count": 4, |
| 27 | + "execution_count": null, |
28 | 28 | "metadata": {
|
29 | 29 | "id": "q-k8wmp0zquh"
|
30 | 30 | },
|
|
34 | 34 | "\n",
|
35 | 35 | "from langchain_openai import OpenAI\n",
|
36 | 36 | "\n",
|
37 |
| - "os.environ[\"OPENAI_API_KEY\"] = \"<your-key-here>\"" |
| 37 | + "os.environ[\"OPENAI_API_KEY\"] = \"insertapikey\"" |
38 | 38 | ]
|
39 | 39 | },
|
40 | 40 | {
|
|
47 | 47 | },
|
48 | 48 | {
|
49 | 49 | "cell_type": "code",
|
50 |
| - "execution_count": 2, |
| 50 | + "execution_count": null, |
51 | 51 | "metadata": {},
|
52 | 52 | "outputs": [],
|
53 | 53 | "source": [
|
|
75 | 75 | },
|
76 | 76 | {
|
77 | 77 | "cell_type": "code",
|
78 |
| - "execution_count": 4, |
| 78 | + "execution_count": null, |
79 | 79 | "metadata": {},
|
80 |
| - "outputs": [ |
81 |
| - { |
82 |
| - "data": { |
83 |
| - "text/plain": [ |
84 |
| - "'https://oaidalleapiprodscus.blob.core.windows.net/private/org-i0zjYONU3PemzJ222esBaAzZ/user-f6uEIOFxoiUZivy567cDSWni/img-i7Z2ZxvJ4IbbdAiO6OXJgS3v.png?st=2023-08-11T14%3A03%3A14Z&se=2023-08-11T16%3A03%3A14Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-08-10T20%3A58%3A32Z&ske=2023-08-11T20%3A58%3A32Z&sks=b&skv=2021-08-06&sig=/sECe7C0EAq37ssgBm7g7JkVIM/Q1W3xOstd0Go6slA%3D'" |
85 |
| - ] |
86 |
| - }, |
87 |
| - "execution_count": 4, |
88 |
| - "metadata": {}, |
89 |
| - "output_type": "execute_result" |
90 |
| - } |
91 |
| - ], |
| 80 | + "outputs": [], |
92 | 81 | "source": [
|
93 | 82 | "image_url"
|
94 | 83 | ]
|
|
135 | 124 | },
|
136 | 125 | {
|
137 | 126 | "cell_type": "code",
|
138 |
| - "execution_count": 9, |
| 127 | + "execution_count": null, |
139 | 128 | "metadata": {},
|
140 |
| - "outputs": [ |
141 |
| - { |
142 |
| - "name": "stdout", |
143 |
| - "output_type": "stream", |
144 |
| - "text": [ |
145 |
| - "\n", |
146 |
| - "\n", |
147 |
| - "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", |
148 |
| - "\u001b[32;1m\u001b[1;3m What is the best way to turn this description into an image?\n", |
149 |
| - "Action: Dall-E Image Generator\n", |
150 |
| - "Action Input: A spooky Halloween night at a haunted museum\u001b[0mhttps://oaidalleapiprodscus.blob.core.windows.net/private/org-rocrupyvzgcl4yf25rqq6d1v/user-WsxrbKyP2c8rfhCKWDyMfe8N/img-ogKfqxxOS5KWVSj4gYySR6FY.png?st=2023-01-31T07%3A38%3A25Z&se=2023-01-31T09%3A38%3A25Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-01-30T22%3A19%3A36Z&ske=2023-01-31T22%3A19%3A36Z&sks=b&skv=2021-08-06&sig=XsomxxBfu2CP78SzR9lrWUlbask4wBNnaMsHamy4VvU%3D\n", |
151 |
| - "\n", |
152 |
| - "Observation: \u001b[36;1m\u001b[1;3mhttps://oaidalleapiprodscus.blob.core.windows.net/private/org-rocrupyvzgcl4yf25rqq6d1v/user-WsxrbKyP2c8rfhCKWDyMfe8N/img-ogKfqxxOS5KWVSj4gYySR6FY.png?st=2023-01-31T07%3A38%3A25Z&se=2023-01-31T09%3A38%3A25Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-01-30T22%3A19%3A36Z&ske=2023-01-31T22%3A19%3A36Z&sks=b&skv=2021-08-06&sig=XsomxxBfu2CP78SzR9lrWUlbask4wBNnaMsHamy4VvU%3D\u001b[0m\n", |
153 |
| - "Thought:\u001b[32;1m\u001b[1;3m With the image generated, I can now make my final answer.\n", |
154 |
| - "Final Answer: An image of a Halloween night at a haunted museum can be seen here: https://oaidalleapiprodscus.blob.core.windows.net/private/org-rocrupyvzgcl4yf25rqq6d1v/user-WsxrbKyP2c8rfhCKWDyMfe8N/img-ogKfqxxOS5KWVSj4gYySR6FY.png?st=2023-01-31T07%3A38%3A25Z&se=2023-01-31T09%3A38%3A25Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-01-30T22\u001b[0m\n", |
155 |
| - "\n", |
156 |
| - "\u001b[1m> Finished chain.\u001b[0m\n" |
157 |
| - ] |
158 |
| - } |
159 |
| - ], |
| 129 | + "outputs": [], |
160 | 130 | "source": [
|
161 |
| - "from langchain.agents import initialize_agent, load_tools\n", |
| 131 | + "from langchain_community.tools.openai_dalle_image_generation import (\n", |
| 132 | + " OpenAIDALLEImageGenerationTool,\n", |
| 133 | + ")\n", |
| 134 | + "from langchain_community.utilities.dalle_image_generator import DallEAPIWrapper\n", |
| 135 | + "from langchain_openai import ChatOpenAI\n", |
| 136 | + "from langgraph.prebuilt import create_react_agent\n", |
162 | 137 | "\n",
|
163 |
| - "tools = load_tools([\"dalle-image-generator\"])\n", |
164 |
| - "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)\n", |
165 |
| - "output = agent.run(\"Create an image of a halloween night at a haunted museum\")" |
| 138 | + "llm = ChatOpenAI(model=\"gpt-3.5-turbo\", temperature=0)\n", |
| 139 | + "api_wrapper = DallEAPIWrapper()\n", |
| 140 | + "dalle_tool = OpenAIDALLEImageGenerationTool(api_wrapper=api_wrapper)\n", |
| 141 | + "\n", |
| 142 | + "tools = [dalle_tool]\n", |
| 143 | + "\n", |
| 144 | + "agent = create_react_agent(llm, tools, debug=True)\n", |
| 145 | + "\n", |
| 146 | + "# User prompt\n", |
| 147 | + "prompt = \"Create an image of a halloween night at a haunted museum\"\n", |
| 148 | + "\n", |
| 149 | + "messages = [\n", |
| 150 | + " # \"role\": \"user\" Indicates message is coming from user\n", |
| 151 | + " # \"content\": prompt is where the user's input is placed\n", |
| 152 | + " {\"role\": \"user\", \"content\": prompt}\n", |
| 153 | + "]\n", |
| 154 | + "\n", |
| 155 | + "# Sending the message to be processed and adjusted by ChatGPT, after which is sent through DALL-E\n", |
| 156 | + "response = agent.invoke({\"messages\": messages})\n", |
| 157 | + "\n", |
| 158 | + "print(response)" |
166 | 159 | ]
|
167 | 160 | }
|
168 | 161 | ],
|
|
171 | 164 | "provenance": []
|
172 | 165 | },
|
173 | 166 | "kernelspec": {
|
174 |
| - "display_name": "Python 3 (ipykernel)", |
| 167 | + "display_name": "Python (langchain-env)", |
175 | 168 | "language": "python",
|
176 |
| - "name": "python3" |
| 169 | + "name": "langchain-env" |
177 | 170 | },
|
178 | 171 | "language_info": {
|
179 | 172 | "codemirror_mode": {
|
|
185 | 178 | "name": "python",
|
186 | 179 | "nbconvert_exporter": "python",
|
187 | 180 | "pygments_lexer": "ipython3",
|
188 |
| - "version": "3.10.12" |
189 |
| - }, |
190 |
| - "vscode": { |
191 |
| - "interpreter": { |
192 |
| - "hash": "3570c8892273ffbeee7ead61dc7c022b73551d9f55fb2584ac0e8e8920b18a89" |
193 |
| - } |
| 181 | + "version": "3.12.9" |
194 | 182 | }
|
195 | 183 | },
|
196 | 184 | "nbformat": 4,
|
|
0 commit comments