{ "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: 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 }