Spaces:
Runtime error
Runtime error
File size: 11,728 Bytes
1cb59e8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/anaconda3/envs/agents/lib/python3.10/site-packages/pydantic/_internal/_config.py:295: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.10/migration/\n",
" warnings.warn(DEPRECATION_MESSAGE, DeprecationWarning)\n",
"/opt/anaconda3/envs/agents/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:502: UserWarning: <built-in function callable> is not a Python type (it may be an instance of an object), Pydantic will allow any object with no validation since we cannot even enforce that the input is an instance of the given type. To get rid of this error wrap the type with `pydantic.SkipValidation`.\n",
" warn(\n",
"/opt/anaconda3/envs/agents/lib/python3.10/site-packages/crewai_tools/tools/scrapegraph_scrape_tool/scrapegraph_scrape_tool.py:34: PydanticDeprecatedSince20: Pydantic V1 style `@validator` validators are deprecated. You should migrate to Pydantic V2 style `@field_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.10/migration/\n",
" @validator(\"website_url\")\n",
"/opt/anaconda3/envs/agents/lib/python3.10/site-packages/crewai_tools/tools/selenium_scraping_tool/selenium_scraping_tool.py:26: PydanticDeprecatedSince20: Pydantic V1 style `@validator` validators are deprecated. You should migrate to Pydantic V2 style `@field_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.10/migration/\n",
" @validator(\"website_url\")\n",
"/opt/anaconda3/envs/agents/lib/python3.10/site-packages/crewai_tools/tools/vision_tool/vision_tool.py:15: PydanticDeprecatedSince20: Pydantic V1 style `@validator` validators are deprecated. You should migrate to Pydantic V2 style `@field_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.10/migration/\n",
" @validator(\"image_path_url\")\n"
]
}
],
"source": [
"import os\n",
"from crewai import Agent, Crew, Task, LLM, Process\n",
"from crewai_tools import ScrapeWebsiteTool, SerperDevTool\n",
"from dotenv import load_dotenv"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"load_dotenv()\n",
"CEREBRAS_API_KEY = os.getenv(\"CEREBRAS_API_KEY\")\n",
"SERPER_API_KEY = os.getenv(\"SERPER_API_KEY\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"if not CEREBRAS_API_KEY:\n",
" raise ValueError(\"Missing Cerebras API Key! Set CEREBRAS_API_KEY in environment variables.\")\n",
"\n",
"if not SERPER_API_KEY:\n",
" raise ValueError(\"Missing Serper API Key! Set SERPER_API_KEY in environment variables.\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"cerebras_llm = LLM(\n",
" model=\"cerebras/llama-3.3-70b\",\n",
" temperature=0.7,\n",
" max_tokens=8192,\n",
" api_key=CEREBRAS_API_KEY,\n",
" base_url=\"https://api.cerebras.ai/v1\",\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Tools"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"search_tool = SerperDevTool()\n",
"scrape_tool = ScrapeWebsiteTool()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Agents"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"search = Agent(\n",
" role=\"E-Commerce Market Research Analyst\",\n",
" goal=f\"Provide up-to-date market analysis of {product_name} from E-commerce Industry\",\n",
" backstory=\"An expert analyst with a keen eye for market trends\",\n",
" tools=[search_tool, scrape_tool],\n",
" verbose=True,\n",
" llm=cerebras_llm\n",
" )\n",
"\n",
"data_cleaner = Agent(\n",
" role=\"Data Cleaning Specialist\",\n",
" goal=f\"Ensure all price values for {product_name} are accurate, properly formatted, and free of inconsistencies.\",\n",
" backstory=(\n",
" \"An experienced data analyst with a strong background in data preprocessing, \"\n",
" \"error detection, and price standardization. With expertise in handling messy datasets, \"\n",
" \"you identify and clean incorrect, missing, or inconsistent price values, ensuring the data is reliable for further analysis.\"\n",
" ),\n",
" tools=[],\n",
" verbose=True,\n",
" llm=cerebras_llm\n",
")\n",
"\n",
"comparison = Agent(\n",
" role=\"Price Comparison Expert\",\n",
" goal=f\"Analyze and compare {product_name} prices to identify the lowest price available.\",\n",
" backstory=(\n",
" \"A meticulous price analyst with expertise in comparing product prices across different sources. \"\n",
" \"You efficiently process pricing data, highlight discrepancies, and determine the best deal for consumers.\"\n",
" ),\n",
" tools=[],\n",
" verbose=True,\n",
" llm=cerebras_llm\n",
")\n",
"\n",
"reporting_agent = Agent(\n",
" role=\"Market Insights Reporter\",\n",
" goal=f\"Generate a comprehensive report summarizing price trends, differences, and the best available deals for {product_name}.\",\n",
" backstory=(\n",
" \"A skilled data journalist with experience in analyzing pricing trends and market fluctuations. \"\n",
" \"You transform raw pricing data into insightful reports, providing actionable insights on cost-effective options.\"\n",
" ),\n",
" tools=[],\n",
" verbose=True,\n",
" llm=cerebras_llm\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Tasks "
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"search_task = Task(\n",
" description=f\"Collect current pricing data for {product_name} from at least 3 major e-commerce platforms. Include product name, model, specifications, price, and any ongoing promotions or discounts.\",\n",
" expected_output=f\"A structured dataset containing {product_name} information and pricing from multiple sources, with complete pricing details.\",\n",
" agent=search\n",
")\n",
"\n",
"cleaning_task = Task(\n",
" description=f\"Process the raw pricing data for {product_name} to standardize formats, handle currency conversions, remove outliers, and identify any inconsistencies or errors in the collected price information.\",\n",
" expected_output=f\"A cleaned dataset with uniformly formatted prices for {product_name}, standardized currencies, and annotations for any identified anomalies or special pricing conditions.\",\n",
" agent=data_cleaner\n",
")\n",
"\n",
"comparison_task = Task(\n",
" description=f\"Analyze the cleaned pricing data to identify the lowest available price for {product_name}, calculate price differences between retailers, and determine price-to-value ratios based on product specifications.\",\n",
" expected_output=f\"A comparative analysis showing price rankings for {product_name}, percentage differences between retailers, and identification of the best value options across different price points.\",\n",
" agent=comparison\n",
")\n",
"\n",
"reporting_task = Task(\n",
" description=f\"Create a comprehensive market insights report based on the {product_name} pricing analysis, highlighting best deals, pricing trends, and actionable recommendations for price-conscious consumers.\",\n",
" expected_output=f\"A detailed report for {product_name} with executive summary, visualizations of price comparisons, identification of pricing patterns, and specific recommendations for optimal purchasing decisions.\",\n",
" agent=reporting_agent\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-02-25 03:19:07,616 - 8480639040 - __init__.py-__init__:537 - WARNING: Overriding of current TracerProvider is not allowed\n"
]
}
],
"source": [
"product_price_crew = Crew(\n",
" agents=[search, data_cleaner, comparison, reporting_agent],\n",
" tasks=[search_task, cleaning_task, comparison_task, reporting_task], \n",
" verbose=True,\n",
" process=Process.sequential,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"product_name = \"Sony WH-1000XM5\"\n",
"country = \"United States\"\n",
"# format = {'product': product_name, 'country': country}\n",
"format = {'product': product_name}"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"product_name = \"Lenovo Earbuds LP40\"\n",
"country = \"United States\"\n",
"format = {'product': product_name, 'country': country}"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'product_price_crew' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[1], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Execute Crew\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m event_analysis \u001b[38;5;241m=\u001b[39m \u001b[43mproduct_price_crew\u001b[49m\u001b[38;5;241m.\u001b[39mkickoff(inputs\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mformat\u001b[39m)\n\u001b[1;32m 3\u001b[0m \u001b[38;5;66;03m# Print the final report\u001b[39;00m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(event_analysis)\n",
"\u001b[0;31mNameError\u001b[0m: name 'product_price_crew' is not defined"
]
}
],
"source": [
"# Execute Crew\n",
"event_analysis = product_price_crew.kickoff(inputs=format)\n",
"# Print the final report\n",
"print(event_analysis)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "agents",
"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",
"version": "3.10.16"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|