|
49 | 49 | "cell_type": "markdown", |
50 | 50 | "metadata": {}, |
51 | 51 | "source": [ |
52 | | - "You will need to export your API key which can be found [here](https://weco-app.vercel.app/account)." |
| 52 | + "Export your API key which can be found [here](https://weco-app.vercel.app/account)." |
53 | 53 | ] |
54 | 54 | }, |
55 | 55 | { |
|
65 | 65 | "cell_type": "markdown", |
66 | 66 | "metadata": {}, |
67 | 67 | "source": [ |
68 | | - "You can build functions for complex systems quickly and without friction in just a few lines of code...For example you can create a function for the following task in the [web console](https://weco-app.vercel.app/function): \n", |
| 68 | + "You can build powerful AI functions for complex tasks quickly and without friction. For example, you can create a function in the [web console](https://weco-app.vercel.app/function) with this description:\n", |
69 | 69 | "\n", |
70 | | - "> \"I want to evaluate the feasibility of a machine learning task. Give me a json object with three keys - 'feasibility', 'justification', and 'suggestions'.\"\n", |
| 70 | + "> \"Analyze a business idea and provide a structured evaluation. Output a JSON with 'viability_score' (0-100), 'strengths' (list), 'weaknesses' (list), and 'next_steps' (list).\"\n", |
71 | 71 | "\n", |
72 | | - "Now, you're ready to query this function anywhere in your code!" |
| 72 | + "Once created, you can query this function anywhere in your code with just a few lines:" |
73 | 73 | ] |
74 | 74 | }, |
75 | 75 | { |
|
79 | 79 | "outputs": [], |
80 | 80 | "source": [ |
81 | 81 | "from weco import query\n", |
| 82 | + "\n", |
82 | 83 | "response = query(\n", |
83 | | - " fn_name=<YOUR_FUNCTION_NAME>,\n", |
84 | | - " fn_input=\"I want to train a model to predict house prices using the Boston Housing dataset hosted on Kaggle.\",\n", |
85 | | - ")" |
| 84 | + " fn_name=\"BusinessIdeaAnalyzer-XYZ123\", # Replace with your actual function name\n", |
| 85 | + " text_input=\"A subscription service for personalized, AI-generated bedtime stories for children.\"\n", |
| 86 | + ")\n", |
| 87 | + "\n", |
| 88 | + "print(response)" |
| 89 | + ] |
| 90 | + }, |
| 91 | + { |
| 92 | + "cell_type": "markdown", |
| 93 | + "metadata": {}, |
| 94 | + "source": [ |
| 95 | + "## Multimodality" |
| 96 | + ] |
| 97 | + }, |
| 98 | + { |
| 99 | + "cell_type": "markdown", |
| 100 | + "metadata": {}, |
| 101 | + "source": [ |
| 102 | + "Our AI functions can interpret complex visual information, follow instructions in natural language and provide practical insights. Let's explore how we can all have a chef give us personalized advice! They can look at the food we have and offer recipe suggestions even providing nutritional information.\n", |
| 103 | + "As shown in the example above, you can provde the image input in various ways such as:\n", |
| 104 | + "1. Base64 encoding\n", |
| 105 | + "3. Public URL\n", |
| 106 | + "4. Local Path" |
| 107 | + ] |
| 108 | + }, |
| 109 | + { |
| 110 | + "cell_type": "code", |
| 111 | + "execution_count": null, |
| 112 | + "metadata": {}, |
| 113 | + "outputs": [], |
| 114 | + "source": [ |
| 115 | + "from weco import build, query\n", |
| 116 | + "import base64\n", |
| 117 | + "\n", |
| 118 | + "task_description = \"\"\"\n", |
| 119 | + "Create a Smart Home Energy Analyzer that can process images of smart meters, home exteriors, \n", |
| 120 | + "and indoor spaces to provide energy efficiency insights. The analyzer should:\n", |
| 121 | + " 1. Interpret smart meter readings\n", |
| 122 | + " 2. Assess home features relevant to energy consumption\n", |
| 123 | + " 3. Analyze thermostat settings\n", |
| 124 | + " 4. Provide energy-saving recommendations\n", |
| 125 | + " 5. Evaluate renewable energy potential\n", |
| 126 | + "\n", |
| 127 | + "The output should include:\n", |
| 128 | + " - 'energy_consumption': current usage and comparison to average\n", |
| 129 | + " - 'home_analysis': visible energy features and potential issues\n", |
| 130 | + " - 'thermostat_settings': current settings and recommendations\n", |
| 131 | + " - 'energy_saving_recommendations': actionable suggestions with estimated savings\n", |
| 132 | + " - 'renewable_energy_potential': assessment of current and potential renewable energy use\n", |
| 133 | + " - 'estimated_carbon_footprint': current footprint and potential reduction\n", |
| 134 | + "\"\"\"\n", |
| 135 | + "\n", |
| 136 | + "fn_name, _ = build(task_description=task_description)\n", |
| 137 | + "\n", |
| 138 | + "request = \"\"\"\n", |
| 139 | + "Analyze these images of my home and smart meter to provide energy efficiency insights \n", |
| 140 | + "and recommendations for reducing my electricity consumption.\n", |
| 141 | + "\"\"\"\n", |
| 142 | + "\n", |
| 143 | + "# Base64 encoded image\n", |
| 144 | + "with open(\"/path/to/home_exterior.jpeg\", \"rb\") as img_file:\n", |
| 145 | + " my_home_exterior = base64.b64encode(img_file.read()).decode('utf-8')\n", |
| 146 | + "\n", |
| 147 | + "response = query(\n", |
| 148 | + " fn_name=fn_name,\n", |
| 149 | + " text_input=request,\n", |
| 150 | + " images_input=[\n", |
| 151 | + " \"https://example.com/my_smart_meter_reading.png\", # Public URL\n", |
| 152 | + " f\"data:image/jpeg;base64,{my_home_exterior}\", # Base64 encoding\n", |
| 153 | + " \"/path/to/living_room_thermostat.jpg\" # Local image path\n", |
| 154 | + " ]\n", |
| 155 | + ")\n", |
| 156 | + "\n", |
| 157 | + "print(response)" |
| 158 | + ] |
| 159 | + }, |
| 160 | + { |
| 161 | + "cell_type": "markdown", |
| 162 | + "metadata": {}, |
| 163 | + "source": [ |
| 164 | + "## Running Example" |
| 165 | + ] |
| 166 | + }, |
| 167 | + { |
| 168 | + "cell_type": "markdown", |
| 169 | + "metadata": {}, |
| 170 | + "source": [ |
| 171 | + "Consider the previous example of:\n", |
| 172 | + "> \"I want to evaluate the feasibility of a machine learning task. Help me understand this through - 'feasibility', 'justification', and 'suggestions'.\"\n", |
| 173 | + "\n", |
| 174 | + "Here's how you can take advantage of our API to best suit your needs." |
| 175 | + ] |
| 176 | + }, |
| 177 | + { |
| 178 | + "cell_type": "code", |
| 179 | + "execution_count": null, |
| 180 | + "metadata": {}, |
| 181 | + "outputs": [], |
| 182 | + "source": [ |
| 183 | + "task_description = \"I want to evaluate the feasibility of a machine learning task. Give me a json object with three keys - 'feasibility', 'justification', and 'suggestions'.\"" |
86 | 184 | ] |
87 | 185 | }, |
88 | 186 | { |
|
108 | 206 | "from weco import build, query\n", |
109 | 207 | "\n", |
110 | 208 | "# Describe the task you want the function to perform\n", |
111 | | - "fn_name, fn_desc = build(\n", |
112 | | - " task_description=\"I want to evaluate the feasibility of a machine learning task. Give me a json object with three keys - 'feasibility', 'justification', and 'suggestions'.\",\n", |
113 | | - ")\n", |
114 | | - "print(f\"Model Name: {fn_name}\\nModel Description:\\n{fn_desc}\")\n", |
| 209 | + "fn_name, fn_desc = build(task_description=task_description)\n", |
| 210 | + "print(f\"AI Function {fn_name} built. This does the following - \\n{fn_desc}.\")\n", |
115 | 211 | "\n", |
116 | 212 | "# Query the function with a specific input\n", |
117 | 213 | "query_response = query(\n", |
118 | 214 | " fn_name=fn_name,\n", |
119 | | - " fn_input=\"I want to train a model to predict house prices using the Boston Housing dataset hosted on Kaggle.\",\n", |
| 215 | + " text_input=\"I want to train a model to predict house prices using the Boston Housing dataset hosted on Kaggle.\"\n", |
120 | 216 | ")\n", |
121 | 217 | "for key, value in query_response.items(): print(f\"{key}: {value}\")" |
122 | 218 | ] |
|
136 | 232 | "source": [ |
137 | 233 | "from weco import WecoAI\n", |
138 | 234 | "\n", |
| 235 | + "# Connect to our service, using our client\n", |
139 | 236 | "client = WecoAI()\n", |
140 | 237 | "\n", |
141 | | - "# Describe the task you want the function to perform\n", |
142 | | - "fn_name, fn_desc = client.build(\n", |
143 | | - " task_description=\"I want to evaluate the feasibility of a machine learning task. Give me a json object with three keys - 'feasibility', 'justification', and 'suggestions'.\"\n", |
144 | | - ")\n", |
145 | | - "print(f\"Model Name: {fn_name}\\nModel Description:\\n{fn_desc}\")\n", |
146 | | - "\n", |
147 | | - "# Query the function with a specific input\n", |
| 238 | + "# Make the same query as before\n", |
148 | 239 | "query_response = client.query(\n", |
149 | 240 | " fn_name=fn_name,\n", |
150 | | - " fn_input=\"I want to train a model to predict house prices using the Boston Housing dataset hosted on Kaggle.\",\n", |
| 241 | + " text_input=\"I want to train a model to predict house prices using the Boston Housing dataset hosted on Kaggle.\"\n", |
151 | 242 | ")\n", |
152 | 243 | "for key, value in query_response.items(): print(f\"{key}: {value}\")" |
153 | 244 | ] |
|
175 | 266 | "from weco import batch_query\n", |
176 | 267 | "\n", |
177 | 268 | "# Query the same function with multiple inputs by batching them for maximum efficiency\n", |
| 269 | + "input_1 = {\"text_input\": \"I want to train a model to predict house prices using the Boston Housing dataset hosted on Kaggle.\"}\n", |
| 270 | + "input_2 = {\n", |
| 271 | + " \"text_input\": \"I want to train a model to classify digits using the MNIST dataset hosted on Kaggle using a Google Colab notebook. Attached is an example of what some of the digits would look like.\",\n", |
| 272 | + " \"images_input\": [\"https://machinelearningmastery.com/wp-content/uploads/2019/02/Plot-of-a-Subset-of-Images-from-the-MNIST-Dataset-1024x768.png\"]\n", |
| 273 | + "}\n", |
178 | 274 | "query_responses = batch_query(\n", |
179 | | - " fn_names=YOUR_FUNCTION_NAME, # The name of the function we built in the previous step\n", |
180 | | - " batch_inputs=[\n", |
181 | | - " \"I want to train a model to predict house prices using the Boston Housing dataset hosted on Kaggle.\",\n", |
182 | | - " \"I want to train a model to classify digits using the MNIST dataset hosted on Kaggle using a Google Colab notebook.\",\n", |
183 | | - " ],\n", |
| 275 | + " fn_names=fn_name,\n", |
| 276 | + " batch_inputs=[input_1, input_2]\n", |
184 | 277 | ")" |
185 | 278 | ] |
186 | 279 | }, |
187 | 280 | { |
188 | 281 | "cell_type": "markdown", |
189 | 282 | "metadata": {}, |
190 | 283 | "source": [ |
191 | | - "You can do the same using the `weco.WecoAI` client. If you wanted to batch different functions, you can pass a list of function names to the `batch_query()` function. Note that the names of functions would need to be ordered the same as the function inputs provided." |
| 284 | + "You can do the same using the `weco.WecoAI` client. If you wanted to batch different functions, you can pass a list of function names to the `batch_query()` function. Note that the names of functions would need to be ordered the same as the function inputs provided.\n", |
| 285 | + "\n", |
| 286 | + "In addition, `weco.batch_query` takes the input batch as an array of individual inputs formatted in the following way -\n", |
| 287 | + "```json\n", |
| 288 | + "{\n", |
| 289 | + " \"text_input\": \"Your text input\",\n", |
| 290 | + " \"images_input\": [\"image1\", \"image2\"]\n", |
| 291 | + "}\n", |
| 292 | + "```" |
192 | 293 | ] |
193 | 294 | }, |
194 | 295 | { |
|
202 | 303 | "cell_type": "markdown", |
203 | 304 | "metadata": {}, |
204 | 305 | "source": [ |
205 | | - "Until now you've been making synchronous calls to our client by we also support asynchronous programmers. This is actually how we implement batching! You can also make asynchronous calls to our service using our `weco.WecoAI` client or as shown below:" |
| 306 | + "Until now you've been making synchronous calls to our client by we also support asynchronous programmers. This is actually how we implement batching! You can also make asynchronous calls to our service using our `weco.WecoAI` client or as shown below for the same example as before:" |
206 | 307 | ] |
207 | 308 | }, |
208 | 309 | { |
|
214 | 315 | "from weco import abuild, aquery\n", |
215 | 316 | "\n", |
216 | 317 | "# Describe the task you want the function to perform\n", |
217 | | - "fn_name, fn_desc = await abuild(\n", |
218 | | - " task_description=\"I want to evaluate the feasibility of a machine learning task. Give me a json object with three keys - 'feasibility', 'justification', and 'suggestions'.\",\n", |
219 | | - ")\n", |
220 | | - "print(f\"Model Name: {fn_name}\\nModel Description:\\n{fn_desc}\")\n", |
| 318 | + "fn_name, fn_desc = await abuild(task_description=task_description)\n", |
| 319 | + "print(f\"AI Function {fn_name} built. This does the following - \\n{fn_desc}.\")\n", |
221 | 320 | "\n", |
222 | 321 | "# Query the function with a specific input\n", |
223 | 322 | "query_response = await aquery(\n", |
224 | 323 | " fn_name=fn_name,\n", |
225 | | - " fn_input=\"I want to train a model to predict house prices using the Boston Housing dataset hosted on Kaggle.\",\n", |
| 324 | + " text_input=\"I want to train a model to predict house prices using the Boston Housing dataset hosted on Kaggle.\"\n", |
226 | 325 | ")\n", |
227 | 326 | "for key, value in query_response.items(): print(f\"{key}: {value}\")" |
228 | 327 | ] |
|
0 commit comments