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
+
import faiss
|
| 3 |
+
import numpy as np
|
| 4 |
+
from phi.agent import Agent
|
| 5 |
+
from phi.tools.firecrawl import FirecrawlTools
|
| 6 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
| 7 |
+
from phi.tools.exa import ExaTools
|
| 8 |
+
from phi.model.openai import OpenAIChat
|
| 9 |
+
from phi.embedder.openai import OpenAIEmbedder
|
| 10 |
+
from typing import List
|
| 11 |
+
from pydantic import BaseModel, Field
|
| 12 |
+
from fastapi import UploadFile
|
| 13 |
+
|
| 14 |
+
# Load environment variables (API keys, etc.)
|
| 15 |
+
from dotenv import load_dotenv
|
| 16 |
+
load_dotenv()
|
| 17 |
+
|
| 18 |
+
#####################################################################################
|
| 19 |
+
# PHASE 1 #
|
| 20 |
+
#####################################################################################
|
| 21 |
+
|
| 22 |
+
##############################
|
| 23 |
+
# 1️⃣ Company Search Agent #
|
| 24 |
+
##############################
|
| 25 |
+
company_search_agent = Agent(
|
| 26 |
+
name="Company Search Agent",
|
| 27 |
+
model=OpenAIChat(id="gpt-4o"),
|
| 28 |
+
tools=[DuckDuckGo()],
|
| 29 |
+
description="Finds company details based on name using web search.",
|
| 30 |
+
instructions=["Always include sources in search results."],
|
| 31 |
+
show_tool_calls=True,
|
| 32 |
+
markdown=True,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
def search_company(company_name: str):
|
| 36 |
+
query = f"Find detailed company information for {company_name}. Extract its official website, mission, services, and any AI-related initiatives. Prioritize official sources and provide links where available."
|
| 37 |
+
return company_search_agent.print_response(query)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
##############################
|
| 41 |
+
# 2️⃣ Website Scraper Agent #
|
| 42 |
+
##############################
|
| 43 |
+
firecrawl_agent = Agent(
|
| 44 |
+
name="Website Scraper Agent",
|
| 45 |
+
tools=[FirecrawlTools(scrape=True, crawl=False)],
|
| 46 |
+
description="Extracts content from company websites.",
|
| 47 |
+
show_tool_calls=True,
|
| 48 |
+
markdown=True,
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
def scrape_website(url: str):
|
| 52 |
+
return firecrawl_agent.print_response(f"Extract all relevant business information from {url}, including mission statement, services, case studies, and AI-related content. Provide structured output.")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
##############################
|
| 56 |
+
# 3️⃣ Text Processing Agent #
|
| 57 |
+
##############################
|
| 58 |
+
class CompanySummary(BaseModel):
|
| 59 |
+
summary: str = Field(..., description="Summarized company details based on user input.")
|
| 60 |
+
|
| 61 |
+
text_processing_agent = Agent(
|
| 62 |
+
model=OpenAIChat(id="gpt-4o"),
|
| 63 |
+
description="Summarizes user-written company descriptions.",
|
| 64 |
+
response_model=CompanySummary,
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
def process_company_description(text: str):
|
| 68 |
+
return text_processing_agent.print_response(f"Summarize the following company description: {text}. Focus on key services, mission, industry, and potential AI use cases where applicable.")
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
#################################
|
| 72 |
+
# 4️⃣ Document Processing Agent #
|
| 73 |
+
#################################
|
| 74 |
+
# FAISS Index for storing extracted knowledge
|
| 75 |
+
embedding_model = OpenAIEmbedder(model="text-embedding-3-small")
|
| 76 |
+
dimension = 1536 # OpenAI's embedding dimension
|
| 77 |
+
faiss_index = faiss.IndexFlatL2(dimension)
|
| 78 |
+
|
| 79 |
+
def process_uploaded_document(file: UploadFile):
|
| 80 |
+
file_path = f"tmp/{file.filename}"
|
| 81 |
+
with open(file_path, "wb") as buffer:
|
| 82 |
+
buffer.write(file.file.read())
|
| 83 |
+
|
| 84 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
| 85 |
+
document_text = f.read()
|
| 86 |
+
|
| 87 |
+
# Generate embedding
|
| 88 |
+
embedding = np.array(embedding_model.embed([document_text])).astype("float32")
|
| 89 |
+
faiss_index.add(embedding)
|
| 90 |
+
|
| 91 |
+
return f"Document processed and stored in FAISS index: {file.filename}"
|
| 92 |
+
|
| 93 |
+
#####################################################################################
|
| 94 |
+
# PHASE 2 #
|
| 95 |
+
#####################################################################################
|
| 96 |
+
|
| 97 |
+
##############################
|
| 98 |
+
# 1️⃣ Industry Trends Agent #
|
| 99 |
+
##############################
|
| 100 |
+
industry_trends_agent = Agent(
|
| 101 |
+
name="Industry Trends Agent",
|
| 102 |
+
model=OpenAIChat(id="gpt-4o"),
|
| 103 |
+
tools=[ExaTools(include_domains=["cnbc.com", "reuters.com", "bloomberg.com"])],
|
| 104 |
+
description="Finds the latest AI advancements in a given industry.",
|
| 105 |
+
show_tool_calls=True,
|
| 106 |
+
markdown=True,
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
def get_industry_trends(industry: str):
|
| 110 |
+
query = f"Find the latest AI advancements, innovations, and emerging technologies in the {industry} sector. Include breakthroughs, adoption trends, and notable implementations by leading companies. Provide references and insights from credible sources."
|
| 111 |
+
return industry_trends_agent.print_response(query)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
##############################
|
| 115 |
+
# 2️⃣ AI Use Case Discovery Agent #
|
| 116 |
+
##############################
|
| 117 |
+
ai_use_case_agent = Agent(
|
| 118 |
+
name="AI Use Case Discovery Agent",
|
| 119 |
+
model=OpenAIChat(id="gpt-4o"),
|
| 120 |
+
tools=[DuckDuckGo()],
|
| 121 |
+
description="Identifies AI applications relevant to a given industry.",
|
| 122 |
+
show_tool_calls=True,
|
| 123 |
+
markdown=True,
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
def get_ai_use_cases(industry: str):
|
| 127 |
+
query = f"Identify the most impactful AI use cases in the {industry} sector. Include real-world applications, automation improvements, cost-saving innovations, and data-driven decision-making processes. Provide case studies and examples of successful AI implementation."
|
| 128 |
+
return ai_use_case_agent.print_response(query)
|
| 129 |
+
|
| 130 |
+
#####################################################################################
|
| 131 |
+
# PHASE 3 #
|
| 132 |
+
#####################################################################################
|
| 133 |
+
|
| 134 |
+
##############################
|
| 135 |
+
# 1️⃣ Reasoning Agent #
|
| 136 |
+
##############################
|
| 137 |
+
reasoning_agent = Agent(
|
| 138 |
+
name="Reasoning Agent",
|
| 139 |
+
model=OpenAIChat(id="gpt-4o"),
|
| 140 |
+
description="Processes all collected data and generates structured AI adoption strategies.",
|
| 141 |
+
show_tool_calls=True,
|
| 142 |
+
markdown=True,
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
def generate_ai_strategy(company_data: str, industry_trends: str, ai_use_cases: str):
|
| 146 |
+
query = f"""
|
| 147 |
+
Given the following:
|
| 148 |
+
- Company Overview: {company_data}
|
| 149 |
+
- Industry Trends: {industry_trends}
|
| 150 |
+
- AI Use Cases: {ai_use_cases}
|
| 151 |
+
Generate a structured AI adoption strategy, including key opportunities, recommended AI tools, implementation roadmap, and future scalability.
|
| 152 |
+
"""
|
| 153 |
+
return reasoning_agent.print_response(query)
|