thrag commited on
Commit
22c858d
1 Parent(s): d92b31b

added openapi key input

Browse files
Files changed (2) hide show
  1. app.py +91 -24
  2. demo-tools-1.ipynb +136 -51
app.py CHANGED
@@ -80,29 +80,89 @@ print(type(x))
80
 
81
  # %%
82
  dessertList = [
83
- "https://www.allrecipes.com/chocolate-snack-cake-recipe-8350343",
84
- "https://www.allrecipes.com/charred-spiced-pears-with-smoky-vanilla-cherry-sauce-recipe-8347080",
85
- "https://www.allrecipes.com/meringue-topped-banana-pudding-recipe-8347040",
86
- "https://www.allrecipes.com/white-chocolate-cinnamon-toast-crunch-bars-recipe-7556790",
87
- "https://www.allrecipes.com/plum-cobbler-for-two-recipe-8304143",
88
- "https://www.allrecipes.com/pumpkin-cheesecake-cookies-recipe-7972485",
89
- "https://www.allrecipes.com/chocolate-whipped-cottage-cheese-recipe-8303272",
90
- "https://www.allrecipes.com/nutella-ice-cream-recipe-7508716",
91
- "https://www.allrecipes.com/3-ingredient-banana-oatmeal-cookies-recipe-7972686",
92
- "https://www.allrecipes.com/caramel-apple-pie-cookies-recipe-7642173"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  ]
94
 
95
  chickenDishList = [
96
- "https://www.allrecipes.com/recipe/228363/crispy-roasted-chicken/",
97
- "https://www.allrecipes.com/recipe/254877/roasted-spatchcocked-chicken-with-potatoes/",
98
- "https://www.allrecipes.com/recipe/235153/easy-baked-chicken-thighs/",
99
- "https://www.allrecipes.com/recipe/258878/crispy-baked-chicken-thighs/",
100
- "https://www.allrecipes.com/recipe/235151/crispy-and-tender-baked-chicken-thighs/",
101
- "https://www.allrecipes.com/recipe/233953/million-dollar-chicken/",
102
- "https://www.allrecipes.com/recipe/70679/simple-whole-roasted-chicken/",
103
- "https://www.allrecipes.com/recipe/214618/beer-can-chicken/",
104
- "https://www.allrecipes.com/recipe/272858/air-fryer-chicken-thighs/",
105
- "https://www.allrecipes.com/recipe/214478/happy-roast-chicken/"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  ]
107
 
108
  # %% [markdown]
@@ -193,10 +253,15 @@ from langchain.llms import OpenAI
193
  from langchain.chat_models import ChatOpenAI
194
  from langchain.load.dump import dumps
195
 
196
- def ask_query(query):
 
 
 
 
 
197
 
198
  # LLM
199
- llm = ChatOpenAI(temperature=0.2, model_name='gpt-4') # 'gpt-3.5-turbo'
200
  agent = initialize_agent(agent="zero-shot-react-description", tools=tools, llm=llm, verbose=True, max_iterations=7, return_intermediate_steps=True)
201
  system = """
202
  If the answer is not in the tools or context passed to you then don't answer. \n
@@ -231,7 +296,9 @@ with gr.Blocks() as demo:
231
  gr.Markdown("Start typing below and then click **Run** to see the output.")
232
  with gr.Row():
233
  with gr.Column():
234
- inp = gr.Textbox(placeholder="Type your question here?", label="Question")
 
 
235
  btn = gr.Button("Run")
236
  examples = ["Can you show tell me what ingredients I need for the first baked chicken recipe?",
237
  "I have 15 guests coming to visit, if I make the 'Chocolate Snack Cake' recipe will there be enough? ",
@@ -248,7 +315,7 @@ with gr.Blocks() as demo:
248
  with gr.Column():
249
  out = gr.TextArea(label="ReAct Answer", placeholder="The answer will go here...")
250
 
251
- btn.click(fn=ask_query, inputs=inp, outputs=out)
252
 
253
  demo.launch(show_error=True)
254
 
 
80
 
81
  # %%
82
  dessertList = [
83
+ {
84
+ "title": "Chocolate Snack Cake",
85
+ "url": "https://www.allrecipes.com/chocolate-snack-cake-recipe-8350343"
86
+ },
87
+ {
88
+ "title": "Charred Spiced Pears with Smoky Vanilla Cherry Sauce",
89
+ "url": "https://www.allrecipes.com/charred-spiced-pears-with-smoky-vanilla-cherry-sauce-recipe-8347080"
90
+ },
91
+ {
92
+ "title": "Meringue Topped Banana Pudding",
93
+ "url": "https://www.allrecipes.com/meringue-topped-banana-pudding-recipe-8347040"
94
+ },
95
+ {
96
+ "title": "White Chocolate Cinnamon Toast Crunch Bars",
97
+ "url": "https://www.allrecipes.com/white-chocolate-cinnamon-toast-crunch-bars-recipe-7556790"
98
+ },
99
+ {
100
+ "title": "Plum Cobbler for Two",
101
+ "url": "https://www.allrecipes.com/plum-cobbler-for-two-recipe-8304143"
102
+ },
103
+ {
104
+ "title": "Pumpkin Cheesecake Cookies",
105
+ "url": "https://www.allrecipes.com/pumpkin-cheesecake-cookies-recipe-7972485"
106
+ },
107
+ {
108
+ "title": "Chocolate Whipped Cottage Cheese",
109
+ "url": "https://www.allrecipes.com/chocolate-whipped-cottage-cheese-recipe-8303272"
110
+ },
111
+ {
112
+ "title": "Nutella Ice Cream",
113
+ "url": "https://www.allrecipes.com/nutella-ice-cream-recipe-7508716"
114
+ },
115
+ {
116
+ "title": "3-Ingredient Banana Oatmeal Cookies",
117
+ "url": "https://www.allrecipes.com/3-ingredient-banana-oatmeal-cookies-recipe-7972686"
118
+ },
119
+ {
120
+ "title": "Caramel Apple Pie Cookies",
121
+ "url": "https://www.allrecipes.com/caramel-apple-pie-cookies-recipe-7642173"
122
+ }
123
  ]
124
 
125
  chickenDishList = [
126
+ {
127
+ "title": "Crispy Roasted Chicken",
128
+ "url": "https://www.allrecipes.com/recipe/228363/crispy-roasted-chicken/"
129
+ },
130
+ {
131
+ "title": "Roasted Spatchcocked Chicken With Potatoes",
132
+ "url": "https://www.allrecipes.com/recipe/254877/roasted-spatchcocked-chicken-with-potatoes/"
133
+ },
134
+ {
135
+ "title": "Easy Baked Chicken Thighs",
136
+ "url": "https://www.allrecipes.com/recipe/235153/easy-baked-chicken-thighs/"
137
+ },
138
+ {
139
+ "title": "Crispy Baked Chicken Thighs",
140
+ "url": "https://www.allrecipes.com/recipe/258878/crispy-baked-chicken-thighs/"
141
+ },
142
+ {
143
+ "title": "Crispy and Tender Baked Chicken Thighs",
144
+ "url": "https://www.allrecipes.com/recipe/235151/crispy-and-tender-baked-chicken-thighs/"
145
+ },
146
+ {
147
+ "title": "Million Dollar Chicken",
148
+ "url": "https://www.allrecipes.com/recipe/233953/million-dollar-chicken/"
149
+ },
150
+ {
151
+ "title": "Simple Whole Roasted Chicken",
152
+ "url": "https://www.allrecipes.com/recipe/70679/simple-whole-roasted-chicken/"
153
+ },
154
+ {
155
+ "title": "Beer Can Chicken",
156
+ "url": "https://www.allrecipes.com/recipe/214618/beer-can-chicken/"
157
+ },
158
+ {
159
+ "title": "Air Fryer Chicken Thighs",
160
+ "url": "https://www.allrecipes.com/recipe/272858/air-fryer-chicken-thighs/"
161
+ },
162
+ {
163
+ "title": "Happy Roast Chicken",
164
+ "url": "https://www.allrecipes.com/recipe/214478/happy-roast-chicken/"
165
+ }
166
  ]
167
 
168
  # %% [markdown]
 
253
  from langchain.chat_models import ChatOpenAI
254
  from langchain.load.dump import dumps
255
 
256
+ def ask_query(model, apiKey, query):
257
+
258
+ if len(apiKey) > 0:
259
+ os.environ['OPENAI_API_KEY'] = apiKey
260
+
261
+ print(model)
262
 
263
  # LLM
264
+ llm = ChatOpenAI(temperature=0.2, model_name=model) # 'gpt-3.5-turbo' # gpt-4
265
  agent = initialize_agent(agent="zero-shot-react-description", tools=tools, llm=llm, verbose=True, max_iterations=7, return_intermediate_steps=True)
266
  system = """
267
  If the answer is not in the tools or context passed to you then don't answer. \n
 
296
  gr.Markdown("Start typing below and then click **Run** to see the output.")
297
  with gr.Row():
298
  with gr.Column():
299
+ modelDD = gr.Dropdown(['gpt-3.5-turbo', 'gpt-4'], value='gpt-3.5-turbo')
300
+ openAIKey = gr.Textbox(placeholder="Paste your OpenAI API Key Here", label="OpenAI API Key")
301
+ inp = gr.Textbox(placeholder="Type your question here...", label="Question")
302
  btn = gr.Button("Run")
303
  examples = ["Can you show tell me what ingredients I need for the first baked chicken recipe?",
304
  "I have 15 guests coming to visit, if I make the 'Chocolate Snack Cake' recipe will there be enough? ",
 
315
  with gr.Column():
316
  out = gr.TextArea(label="ReAct Answer", placeholder="The answer will go here...")
317
 
318
+ btn.click(fn=ask_query, inputs=[modelDD, openAIKey, inp], outputs=out)
319
 
320
  demo.launch(show_error=True)
321
 
demo-tools-1.ipynb CHANGED
@@ -40,17 +40,9 @@
40
  },
41
  {
42
  "cell_type": "code",
43
- "execution_count": 37,
44
  "metadata": {},
45
- "outputs": [
46
- {
47
- "name": "stdout",
48
- "output_type": "stream",
49
- "text": [
50
- "{'@context': 'http://schema.org', '@type': ['Recipe', 'NewsArticle'], 'headline': 'Easy Baked Chicken Thighs', 'datePublished': '2016-03-02T13:02:00.000-05:00', 'dateModified': '2023-03-07T10:00:00.000-05:00', 'author': [{'@type': 'Person', 'name': 'KALENG', 'url': 'https://www.allrecipes.com/cook/1118863'}], 'description': 'These easy baked chicken thighs, seasoned with onion and garlic, take just 30 minutes to bake in the oven for a quick and delicious weeknight meal.', 'video': {'@type': 'VideoObject', 'contentUrl': 'https://content.jwplatform.com/videos/a9jndB0U-K3AjnAEN.mp4', 'description': \"In this video, we show you how to make the easiest, 30-minute, baked chicken recipe. If you've got a baking dish, an oven, some chicken thighs, garlic powder, and onion flakes, then you've got yourself a quick and tasty little dinner. Whether you're a beginner cook or just need to get food on the table, this recipe is for you. Try adding new spices or maybe whip up a savory sauce to go with this. \", 'duration': 'PT47S', 'name': 'Easy Baked Chicken Thighs', 'thumbnailUrl': 'https://cdn.jwplayer.com/v2/media/a9jndB0U/poster.jpg?width=720', 'uploadDate': '2021-03-08T18:54:35.211-05:00'}, 'name': 'Easy Baked Chicken Thighs', 'aggregateRating': {'@type': 'AggregateRating', 'ratingValue': '4.2', 'ratingCount': '201'}, 'cookTime': 'PT30M', 'nutrition': {'@type': 'NutritionInformation', 'calories': '162 kcal', 'carbohydrateContent': '3 g', 'cholesterolContent': '69 mg', 'fiberContent': '0 g', 'proteinContent': '20 g', 'saturatedFatContent': '2 g', 'sodiumContent': '58 mg', 'sugarContent': '1 g', 'fatContent': '8 g', 'unsaturatedFatContent': '0 g'}, 'prepTime': 'PT5M', 'recipeCategory': ['Dinner'], 'recipeIngredient': ['4 chicken thighs', '4 teaspoons garlic powder', '4 teaspoons onion flakes'], 'recipeInstructions': [{'@type': 'HowToStep', 'text': 'Preheat the oven to 375 degrees F (190 degrees C).'}, {'@type': 'HowToStep', 'text': 'Place chicken thighs in a baking dish; season both sides with garlic powder and onion flakes.'}, {'@type': 'HowToStep', 'image': [{'@type': 'ImageObject', 'url': 'https://www.allrecipes.com/thmb/BOL-8G2Bl2He3S9qVHwSl0oBP5A=/1500x0/filters:no_upscale():max_bytes(150000):strip_icc()/4348465-easy-baked-chicken-thighs-Meoshia_P-1x1-1-88ab86050c154776a8d3c44260ae385d.jpg'}], 'text': 'Bake in the preheated oven until no longer pink at the bone and juices run clear, about 30 minutes. An instant-read thermometer inserted into thickest part of thigh, near the bone, should read 165 degrees F (74 degrees C).'}], 'recipeYield': ['4'], 'totalTime': 'PT35M', 'about': []}\n"
51
- ]
52
- }
53
- ],
54
  "source": [
55
  "import requests\n",
56
  "from bs4 import BeautifulSoup\n",
@@ -106,7 +98,7 @@
106
  },
107
  {
108
  "cell_type": "code",
109
- "execution_count": 32,
110
  "metadata": {},
111
  "outputs": [
112
  {
@@ -132,34 +124,94 @@
132
  },
133
  {
134
  "cell_type": "code",
135
- "execution_count": 3,
136
  "metadata": {},
137
  "outputs": [],
138
  "source": [
139
  "dessertList = [\n",
140
- "\"https://www.allrecipes.com/chocolate-snack-cake-recipe-8350343\",\n",
141
- "\"https://www.allrecipes.com/charred-spiced-pears-with-smoky-vanilla-cherry-sauce-recipe-8347080\",\n",
142
- "\"https://www.allrecipes.com/meringue-topped-banana-pudding-recipe-8347040\",\n",
143
- "\"https://www.allrecipes.com/white-chocolate-cinnamon-toast-crunch-bars-recipe-7556790\",\n",
144
- "\"https://www.allrecipes.com/plum-cobbler-for-two-recipe-8304143\",\n",
145
- "\"https://www.allrecipes.com/pumpkin-cheesecake-cookies-recipe-7972485\",\n",
146
- "\"https://www.allrecipes.com/chocolate-whipped-cottage-cheese-recipe-8303272\",\n",
147
- "\"https://www.allrecipes.com/nutella-ice-cream-recipe-7508716\",\n",
148
- "\"https://www.allrecipes.com/3-ingredient-banana-oatmeal-cookies-recipe-7972686\",\n",
149
- "\"https://www.allrecipes.com/caramel-apple-pie-cookies-recipe-7642173\"\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  "]\n",
151
  "\n",
152
  "chickenDishList = [\n",
153
- "\"https://www.allrecipes.com/recipe/228363/crispy-roasted-chicken/\",\n",
154
- "\"https://www.allrecipes.com/recipe/254877/roasted-spatchcocked-chicken-with-potatoes/\",\n",
155
- "\"https://www.allrecipes.com/recipe/235153/easy-baked-chicken-thighs/\",\n",
156
- "\"https://www.allrecipes.com/recipe/258878/crispy-baked-chicken-thighs/\",\n",
157
- "\"https://www.allrecipes.com/recipe/235151/crispy-and-tender-baked-chicken-thighs/\",\n",
158
- "\"https://www.allrecipes.com/recipe/233953/million-dollar-chicken/\",\n",
159
- "\"https://www.allrecipes.com/recipe/70679/simple-whole-roasted-chicken/\",\n",
160
- "\"https://www.allrecipes.com/recipe/214618/beer-can-chicken/\",\n",
161
- "\"https://www.allrecipes.com/recipe/272858/air-fryer-chicken-thighs/\",\n",
162
- "\"https://www.allrecipes.com/recipe/214478/happy-roast-chicken/\"\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  "]"
164
  ]
165
  },
@@ -172,7 +224,7 @@
172
  },
173
  {
174
  "cell_type": "code",
175
- "execution_count": 13,
176
  "metadata": {},
177
  "outputs": [],
178
  "source": [
@@ -208,7 +260,7 @@
208
  },
209
  {
210
  "cell_type": "code",
211
- "execution_count": 5,
212
  "metadata": {},
213
  "outputs": [],
214
  "source": [
@@ -235,7 +287,7 @@
235
  },
236
  {
237
  "cell_type": "code",
238
- "execution_count": 6,
239
  "metadata": {},
240
  "outputs": [],
241
  "source": [
@@ -271,7 +323,7 @@
271
  },
272
  {
273
  "cell_type": "code",
274
- "execution_count": 19,
275
  "metadata": {},
276
  "outputs": [],
277
  "source": [
@@ -281,10 +333,15 @@
281
  "from langchain.chat_models import ChatOpenAI\n",
282
  "from langchain.load.dump import dumps\n",
283
  "\n",
284
- "def ask_query(query):\n",
 
 
 
 
 
285
  " \n",
286
  " # LLM \n",
287
- " llm = ChatOpenAI(temperature=0.2, model_name='gpt-4') # 'gpt-3.5-turbo'\n",
288
  " agent = initialize_agent(agent=\"zero-shot-react-description\", tools=tools, llm=llm, verbose=True, max_iterations=7, return_intermediate_steps=True)\n",
289
  " system = \"\"\"\n",
290
  " If the answer is not in the tools or context passed to you then don't answer. \\n\n",
@@ -319,14 +376,14 @@
319
  },
320
  {
321
  "cell_type": "code",
322
- "execution_count": 20,
323
  "metadata": {},
324
  "outputs": [
325
  {
326
  "name": "stdout",
327
  "output_type": "stream",
328
  "text": [
329
- "Running on local URL: http://127.0.0.1:7866\n",
330
  "\n",
331
  "To create a public link, set `share=True` in `launch()`.\n"
332
  ]
@@ -334,7 +391,7 @@
334
  {
335
  "data": {
336
  "text/html": [
337
- "<div><iframe src=\"http://127.0.0.1:7866/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
338
  ],
339
  "text/plain": [
340
  "<IPython.core.display.HTML object>"
@@ -347,7 +404,7 @@
347
  "data": {
348
  "text/plain": []
349
  },
350
- "execution_count": 20,
351
  "metadata": {},
352
  "output_type": "execute_result"
353
  },
@@ -355,19 +412,45 @@
355
  "name": "stdout",
356
  "output_type": "stream",
357
  "text": [
 
358
  "\n",
359
  "\n",
360
  "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
361
- "\u001b[32;1m\u001b[1;3mI need to use the Chicken Recipes tool to find the last baked chicken recipe.\n",
362
  "Action: Chicken Recipes tool\n",
363
- "Action Input: {}\u001b[0m\n",
364
  "Observation: \u001b[36;1m\u001b[1;3m['https://www.allrecipes.com/recipe/228363/crispy-roasted-chicken/', 'https://www.allrecipes.com/recipe/254877/roasted-spatchcocked-chicken-with-potatoes/', 'https://www.allrecipes.com/recipe/235153/easy-baked-chicken-thighs/', 'https://www.allrecipes.com/recipe/258878/crispy-baked-chicken-thighs/', 'https://www.allrecipes.com/recipe/235151/crispy-and-tender-baked-chicken-thighs/', 'https://www.allrecipes.com/recipe/233953/million-dollar-chicken/', 'https://www.allrecipes.com/recipe/70679/simple-whole-roasted-chicken/', 'https://www.allrecipes.com/recipe/214618/beer-can-chicken/', 'https://www.allrecipes.com/recipe/272858/air-fryer-chicken-thighs/', 'https://www.allrecipes.com/recipe/214478/happy-roast-chicken/']\u001b[0m\n",
365
- "Thought:\u001b[32;1m\u001b[1;3mThe last URL in the list seems to be the last baked chicken recipe. I need to use the Get a Recipe tool to fetch the recipe details.\n",
366
  "Action: Get a Recipe tool\n",
367
- "Action Input: {'url': 'https://www.allrecipes.com/recipe/214478/happy-roast-chicken/'}\u001b[0m\n",
368
- "Observation: \u001b[38;5;200m\u001b[1;3m{'error': 'Invalid url format', 'url': '{url: https://www.allrecipes.com/recipe/214478/happy-roast-chicken/}'}\u001b[0m\n",
369
- "Thought:\u001b[32;1m\u001b[1;3mThe URL format seems to be invalid. I can't fetch the recipe details with this URL. \n",
370
- "Final Answer: I'm sorry, but I can't fetch the recipe details at the moment due to an invalid URL format.\u001b[0m\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371
  "\n",
372
  "\u001b[1m> Finished chain.\u001b[0m\n"
373
  ]
@@ -380,7 +463,9 @@
380
  " gr.Markdown(\"Start typing below and then click **Run** to see the output.\")\n",
381
  " with gr.Row():\n",
382
  " with gr.Column():\n",
383
- " inp = gr.Textbox(placeholder=\"Type your question here?\", label=\"Question\") \n",
 
 
384
  " btn = gr.Button(\"Run\") \n",
385
  " examples = [\"Can you show tell me what ingredients I need for the first baked chicken recipe?\",\n",
386
  " \"I have 15 guests coming to visit, if I make the 'Chocolate Snack Cake' recipe will there be enough? \",\n",
@@ -397,7 +482,7 @@
397
  " with gr.Column():\n",
398
  " out = gr.TextArea(label=\"ReAct Answer\", placeholder=\"The answer will go here...\")\n",
399
  " \n",
400
- " btn.click(fn=ask_query, inputs=inp, outputs=out)\n",
401
  " \n",
402
  "demo.launch(show_error=True)"
403
  ]
 
40
  },
41
  {
42
  "cell_type": "code",
43
+ "execution_count": 2,
44
  "metadata": {},
45
+ "outputs": [],
 
 
 
 
 
 
 
 
46
  "source": [
47
  "import requests\n",
48
  "from bs4 import BeautifulSoup\n",
 
98
  },
99
  {
100
  "cell_type": "code",
101
+ "execution_count": 3,
102
  "metadata": {},
103
  "outputs": [
104
  {
 
124
  },
125
  {
126
  "cell_type": "code",
127
+ "execution_count": 4,
128
  "metadata": {},
129
  "outputs": [],
130
  "source": [
131
  "dessertList = [\n",
132
+ " {\n",
133
+ " \"title\": \"Chocolate Snack Cake\",\n",
134
+ " \"url\": \"https://www.allrecipes.com/chocolate-snack-cake-recipe-8350343\"\n",
135
+ " },\n",
136
+ " {\n",
137
+ " \"title\": \"Charred Spiced Pears with Smoky Vanilla Cherry Sauce\",\n",
138
+ " \"url\": \"https://www.allrecipes.com/charred-spiced-pears-with-smoky-vanilla-cherry-sauce-recipe-8347080\"\n",
139
+ " },\n",
140
+ " {\n",
141
+ " \"title\": \"Meringue Topped Banana Pudding\",\n",
142
+ " \"url\": \"https://www.allrecipes.com/meringue-topped-banana-pudding-recipe-8347040\"\n",
143
+ " },\n",
144
+ " {\n",
145
+ " \"title\": \"White Chocolate Cinnamon Toast Crunch Bars\",\n",
146
+ " \"url\": \"https://www.allrecipes.com/white-chocolate-cinnamon-toast-crunch-bars-recipe-7556790\"\n",
147
+ " },\n",
148
+ " {\n",
149
+ " \"title\": \"Plum Cobbler for Two\",\n",
150
+ " \"url\": \"https://www.allrecipes.com/plum-cobbler-for-two-recipe-8304143\"\n",
151
+ " },\n",
152
+ " {\n",
153
+ " \"title\": \"Pumpkin Cheesecake Cookies\",\n",
154
+ " \"url\": \"https://www.allrecipes.com/pumpkin-cheesecake-cookies-recipe-7972485\"\n",
155
+ " },\n",
156
+ " {\n",
157
+ " \"title\": \"Chocolate Whipped Cottage Cheese\",\n",
158
+ " \"url\": \"https://www.allrecipes.com/chocolate-whipped-cottage-cheese-recipe-8303272\"\n",
159
+ " },\n",
160
+ " {\n",
161
+ " \"title\": \"Nutella Ice Cream\",\n",
162
+ " \"url\": \"https://www.allrecipes.com/nutella-ice-cream-recipe-7508716\"\n",
163
+ " },\n",
164
+ " {\n",
165
+ " \"title\": \"3-Ingredient Banana Oatmeal Cookies\",\n",
166
+ " \"url\": \"https://www.allrecipes.com/3-ingredient-banana-oatmeal-cookies-recipe-7972686\"\n",
167
+ " },\n",
168
+ " {\n",
169
+ " \"title\": \"Caramel Apple Pie Cookies\",\n",
170
+ " \"url\": \"https://www.allrecipes.com/caramel-apple-pie-cookies-recipe-7642173\"\n",
171
+ " }\n",
172
  "]\n",
173
  "\n",
174
  "chickenDishList = [\n",
175
+ " {\n",
176
+ " \"title\": \"Crispy Roasted Chicken\",\n",
177
+ " \"url\": \"https://www.allrecipes.com/recipe/228363/crispy-roasted-chicken/\"\n",
178
+ " },\n",
179
+ " {\n",
180
+ " \"title\": \"Roasted Spatchcocked Chicken With Potatoes\",\n",
181
+ " \"url\": \"https://www.allrecipes.com/recipe/254877/roasted-spatchcocked-chicken-with-potatoes/\"\n",
182
+ " },\n",
183
+ " {\n",
184
+ " \"title\": \"Easy Baked Chicken Thighs\",\n",
185
+ " \"url\": \"https://www.allrecipes.com/recipe/235153/easy-baked-chicken-thighs/\"\n",
186
+ " },\n",
187
+ " {\n",
188
+ " \"title\": \"Crispy Baked Chicken Thighs\",\n",
189
+ " \"url\": \"https://www.allrecipes.com/recipe/258878/crispy-baked-chicken-thighs/\"\n",
190
+ " },\n",
191
+ " {\n",
192
+ " \"title\": \"Crispy and Tender Baked Chicken Thighs\",\n",
193
+ " \"url\": \"https://www.allrecipes.com/recipe/235151/crispy-and-tender-baked-chicken-thighs/\"\n",
194
+ " },\n",
195
+ " {\n",
196
+ " \"title\": \"Million Dollar Chicken\",\n",
197
+ " \"url\": \"https://www.allrecipes.com/recipe/233953/million-dollar-chicken/\"\n",
198
+ " },\n",
199
+ " {\n",
200
+ " \"title\": \"Simple Whole Roasted Chicken\",\n",
201
+ " \"url\": \"https://www.allrecipes.com/recipe/70679/simple-whole-roasted-chicken/\"\n",
202
+ " },\n",
203
+ " {\n",
204
+ " \"title\": \"Beer Can Chicken\",\n",
205
+ " \"url\": \"https://www.allrecipes.com/recipe/214618/beer-can-chicken/\"\n",
206
+ " },\n",
207
+ " {\n",
208
+ " \"title\": \"Air Fryer Chicken Thighs\",\n",
209
+ " \"url\": \"https://www.allrecipes.com/recipe/272858/air-fryer-chicken-thighs/\"\n",
210
+ " },\n",
211
+ " {\n",
212
+ " \"title\": \"Happy Roast Chicken\",\n",
213
+ " \"url\": \"https://www.allrecipes.com/recipe/214478/happy-roast-chicken/\"\n",
214
+ " }\n",
215
  "]"
216
  ]
217
  },
 
224
  },
225
  {
226
  "cell_type": "code",
227
+ "execution_count": 5,
228
  "metadata": {},
229
  "outputs": [],
230
  "source": [
 
260
  },
261
  {
262
  "cell_type": "code",
263
+ "execution_count": 6,
264
  "metadata": {},
265
  "outputs": [],
266
  "source": [
 
287
  },
288
  {
289
  "cell_type": "code",
290
+ "execution_count": 7,
291
  "metadata": {},
292
  "outputs": [],
293
  "source": [
 
323
  },
324
  {
325
  "cell_type": "code",
326
+ "execution_count": 8,
327
  "metadata": {},
328
  "outputs": [],
329
  "source": [
 
333
  "from langchain.chat_models import ChatOpenAI\n",
334
  "from langchain.load.dump import dumps\n",
335
  "\n",
336
+ "def ask_query(model, apiKey, query):\n",
337
+ " \n",
338
+ " if len(apiKey) > 0:\n",
339
+ " os.environ['OPENAI_API_KEY'] = apiKey\n",
340
+ " \n",
341
+ " print(model)\n",
342
  " \n",
343
  " # LLM \n",
344
+ " llm = ChatOpenAI(temperature=0.2, model_name=model) # 'gpt-3.5-turbo' # gpt-4\n",
345
  " agent = initialize_agent(agent=\"zero-shot-react-description\", tools=tools, llm=llm, verbose=True, max_iterations=7, return_intermediate_steps=True)\n",
346
  " system = \"\"\"\n",
347
  " If the answer is not in the tools or context passed to you then don't answer. \\n\n",
 
376
  },
377
  {
378
  "cell_type": "code",
379
+ "execution_count": 10,
380
  "metadata": {},
381
  "outputs": [
382
  {
383
  "name": "stdout",
384
  "output_type": "stream",
385
  "text": [
386
+ "Running on local URL: http://127.0.0.1:7861\n",
387
  "\n",
388
  "To create a public link, set `share=True` in `launch()`.\n"
389
  ]
 
391
  {
392
  "data": {
393
  "text/html": [
394
+ "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
395
  ],
396
  "text/plain": [
397
  "<IPython.core.display.HTML object>"
 
404
  "data": {
405
  "text/plain": []
406
  },
407
+ "execution_count": 10,
408
  "metadata": {},
409
  "output_type": "execute_result"
410
  },
 
412
  "name": "stdout",
413
  "output_type": "stream",
414
  "text": [
415
+ "gpt-3.5-turbo\n",
416
  "\n",
417
  "\n",
418
  "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
419
+ "\u001b[32;1m\u001b[1;3mI need to find the first baked chicken recipe and fetch its ingredients.\n",
420
  "Action: Chicken Recipes tool\n",
421
+ "Action Input: None\u001b[0m\n",
422
  "Observation: \u001b[36;1m\u001b[1;3m['https://www.allrecipes.com/recipe/228363/crispy-roasted-chicken/', 'https://www.allrecipes.com/recipe/254877/roasted-spatchcocked-chicken-with-potatoes/', 'https://www.allrecipes.com/recipe/235153/easy-baked-chicken-thighs/', 'https://www.allrecipes.com/recipe/258878/crispy-baked-chicken-thighs/', 'https://www.allrecipes.com/recipe/235151/crispy-and-tender-baked-chicken-thighs/', 'https://www.allrecipes.com/recipe/233953/million-dollar-chicken/', 'https://www.allrecipes.com/recipe/70679/simple-whole-roasted-chicken/', 'https://www.allrecipes.com/recipe/214618/beer-can-chicken/', 'https://www.allrecipes.com/recipe/272858/air-fryer-chicken-thighs/', 'https://www.allrecipes.com/recipe/214478/happy-roast-chicken/']\u001b[0m\n",
423
+ "Thought:\u001b[32;1m\u001b[1;3mI need to fetch the first baked chicken recipe and get its ingredients.\n",
424
  "Action: Get a Recipe tool\n",
425
+ "Action Input: 'https://www.allrecipes.com/recipe/228363/crispy-roasted-chicken/'\u001b[0m\n",
426
+ "Observation: \u001b[38;5;200m\u001b[1;3m{'@context': 'http://schema.org', '@type': ['Recipe'], 'headline': 'Crispy Roasted Chicken', 'datePublished': '2014-08-26T18:22:55.000-04:00', 'dateModified': '2023-01-30T04:44:54.000-05:00', 'author': [{'@type': 'Person', 'name': 'Doc Simonson', 'url': 'https://www.allrecipes.com/cook/docsimonson'}], 'description': 'This roasted half chicken is prepared Bavarian-style with spices and herbs, including caraway, sage, fennel, garlic, rosemary, coriander, and paprika.', 'name': 'Crispy Roasted Chicken', 'aggregateRating': {'@type': 'AggregateRating', 'ratingValue': '4.7', 'ratingCount': '134'}, 'cookTime': 'PT60M', 'nutrition': {'@type': 'NutritionInformation', 'calories': '495 kcal', 'carbohydrateContent': '3 g', 'cholesterolContent': '129 mg', 'fiberContent': '1 g', 'proteinContent': '42 g', 'saturatedFatContent': '8 g', 'sodiumContent': '446 mg', 'sugarContent': '1 g', 'fatContent': '35 g', 'unsaturatedFatContent': '0 g'}, 'prepTime': 'PT20M', 'recipeCategory': ['Dinner', 'Drink'], 'recipeCuisine': ['German'], 'recipeIngredient': ['1 teaspoon kosher salt', '0.5 teaspoon caraway seeds', '0.5 teaspoon dried sage', '0.25 teaspoon fennel seeds', '0.25 teaspoon coriander seeds', '0.25 teaspoon dried rosemary', '2 tablespoons paprika', '2 teaspoons garlic powder', '2 teaspoons all-purpose flour', '1 teaspoon onion powder', '5 tablespoons vegetable oil', '1 (4 pound) broiler-fryer chicken, cut in half lengthwise'], 'recipeInstructions': [{'@type': 'HowToStep', 'text': 'Preheat the oven to 425 degrees F (220 degrees C).'}, {'@type': 'HowToStep', 'text': 'Combine kosher salt, caraway, sage, fennel, coriander, and rosemary in a spice grinder or mortar. Grind to a coarse powder. Transfer spice mixture to a bowl; stir in paprika, garlic powder, flour, and onion powder. Mix in vegetable oil to make a smooth paste.'}, {'@type': 'HowToStep', 'text': 'Pat chicken halves dry with paper towels and tuck wing tips behind the back. Brush spice paste onto chicken halves, coating all sides and seasoning under wings and legs. Place chicken halves, skin-sides up, in a baking dish or roasting pan, leaving space around chickens so halves aren&#39;t touching.'}, {'@type': 'HowToStep', 'text': 'Roast in the preheated oven until no longer pink at the bone and the juices run clear, about 1 hour. An instant-read thermometer inserted into the thickest part of the thigh, near the bone, should read 165 degrees F (74 degrees C). Remove from the oven and let rest for 10 minutes before slicing.'}], 'recipeYield': ['6'], 'totalTime': 'PT90M', 'about': []}\u001b[0m\n",
427
+ "Thought:\u001b[32;1m\u001b[1;3mI have fetched the first baked chicken recipe and its ingredients are:\n",
428
+ "- 1 teaspoon kosher salt\n",
429
+ "- 0.5 teaspoon caraway seeds\n",
430
+ "- 0.5 teaspoon dried sage\n",
431
+ "- 0.25 teaspoon fennel seeds\n",
432
+ "- 0.25 teaspoon coriander seeds\n",
433
+ "- 0.25 teaspoon dried rosemary\n",
434
+ "- 2 tablespoons paprika\n",
435
+ "- 2 teaspoons garlic powder\n",
436
+ "- 2 teaspoons all-purpose flour\n",
437
+ "- 1 teaspoon onion powder\n",
438
+ "- 5 tablespoons vegetable oil\n",
439
+ "- 1 (4 pound) broiler-fryer chicken, cut in half lengthwise\n",
440
+ "\n",
441
+ "Final Answer: The ingredients needed for the first baked chicken recipe are listed above.\u001b[0m\n",
442
+ "\n",
443
+ "\u001b[1m> Finished chain.\u001b[0m\n",
444
+ "gpt-3.5-turbo\n",
445
+ "\n",
446
+ "\n",
447
+ "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
448
+ "\u001b[32;1m\u001b[1;3mI need to use the Chicken Recipes tool to get a list of all the chicken recipes.\n",
449
+ "Action: Chicken Recipes tool\n",
450
+ "Action Input: None\u001b[0m\n",
451
+ "Observation: \u001b[36;1m\u001b[1;3m['https://www.allrecipes.com/recipe/228363/crispy-roasted-chicken/', 'https://www.allrecipes.com/recipe/254877/roasted-spatchcocked-chicken-with-potatoes/', 'https://www.allrecipes.com/recipe/235153/easy-baked-chicken-thighs/', 'https://www.allrecipes.com/recipe/258878/crispy-baked-chicken-thighs/', 'https://www.allrecipes.com/recipe/235151/crispy-and-tender-baked-chicken-thighs/', 'https://www.allrecipes.com/recipe/233953/million-dollar-chicken/', 'https://www.allrecipes.com/recipe/70679/simple-whole-roasted-chicken/', 'https://www.allrecipes.com/recipe/214618/beer-can-chicken/', 'https://www.allrecipes.com/recipe/272858/air-fryer-chicken-thighs/', 'https://www.allrecipes.com/recipe/214478/happy-roast-chicken/']\u001b[0m\n",
452
+ "Thought:\u001b[32;1m\u001b[1;3mI have a list of chicken recipes.\n",
453
+ "Final Answer: ['https://www.allrecipes.com/recipe/228363/crispy-roasted-chicken/', 'https://www.allrecipes.com/recipe/254877/roasted-spatchcocked-chicken-with-potatoes/', 'https://www.allrecipes.com/recipe/235153/easy-baked-chicken-thighs/', 'https://www.allrecipes.com/recipe/258878/crispy-baked-chicken-thighs/', 'https://www.allrecipes.com/recipe/235151/crispy-and-tender-baked-chicken-thighs/', 'https://www.allrecipes.com/recipe/233953/million-dollar-chicken/', 'https://www.allrecipes.com/recipe/70679/simple-whole-roasted-chicken/', 'https://www.allrecipes.com/recipe/214618/beer-can-chicken/', 'https://www.allrecipes.com/recipe/272858/air-fryer-chicken-thighs/', 'https://www.allrecipes.com/recipe/214478/happy-roast-chicken/']\u001b[0m\n",
454
  "\n",
455
  "\u001b[1m> Finished chain.\u001b[0m\n"
456
  ]
 
463
  " gr.Markdown(\"Start typing below and then click **Run** to see the output.\")\n",
464
  " with gr.Row():\n",
465
  " with gr.Column():\n",
466
+ " modelDD = gr.Dropdown(['gpt-3.5-turbo', 'gpt-4'], value='gpt-3.5-turbo')\n",
467
+ " openAIKey = gr.Textbox(placeholder=\"Paste your OpenAI API Key Here\", label=\"OpenAI API Key\") \n",
468
+ " inp = gr.Textbox(placeholder=\"Type your question here...\", label=\"Question\") \n",
469
  " btn = gr.Button(\"Run\") \n",
470
  " examples = [\"Can you show tell me what ingredients I need for the first baked chicken recipe?\",\n",
471
  " \"I have 15 guests coming to visit, if I make the 'Chocolate Snack Cake' recipe will there be enough? \",\n",
 
482
  " with gr.Column():\n",
483
  " out = gr.TextArea(label=\"ReAct Answer\", placeholder=\"The answer will go here...\")\n",
484
  " \n",
485
+ " btn.click(fn=ask_query, inputs=[modelDD, openAIKey, inp], outputs=out)\n",
486
  " \n",
487
  "demo.launch(show_error=True)"
488
  ]