Spaces:
Sleeping
Sleeping
| import os | |
| from phi.agent import Agent | |
| from phi.model.openai import OpenAIChat | |
| import markdown2 | |
| import pdfkit | |
| from bni_agent import get_bni_benefits | |
| from rag_agent import recommend_bni_connections | |
| # Load environment variables (API keys, etc.) | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| ##################################################################################### | |
| # PHASE 3 # | |
| ##################################################################################### | |
| ############################## | |
| # 1️⃣ Reasoning Agent # | |
| ############################## | |
| reasoning_agent = Agent( | |
| name="Reasoning Agent", | |
| model=OpenAIChat(id="gpt-4o"), | |
| description="Processes all collected data and generates structured AI adoption strategies.", | |
| show_tool_calls=True, | |
| markdown=True, | |
| ) | |
| def generate_ai_strategy(company_data: str, industry_trends: str, ai_use_cases: str) -> str: | |
| """Generates a structured AI adoption strategy based on company details and industry insights.""" | |
| query = f""" | |
| You are an AI business strategist analyzing a company's AI adoption potential. Given: | |
| - **Company Overview:** {company_data} | |
| - **Industry Trends:** {industry_trends} | |
| - **AI Use Cases:** {ai_use_cases} | |
| Generate a structured AI strategy including: | |
| 1. Key AI Opportunities | |
| 2. Recommended AI Tools & Technologies | |
| 3. AI Implementation Roadmap | |
| 4. Future Scalability Plan | |
| """ | |
| response = reasoning_agent.run(query) | |
| return response.content # Returns the generated AI strategy | |
| ############################## | |
| # 2️⃣ AI Integration Advisor # | |
| ############################## | |
| ai_integration_agent = Agent( | |
| name="AI Integration Advisor", | |
| model=OpenAIChat(id="gpt-4o"), | |
| description="Suggests AI implementation strategies based on industry insights and company operations.", | |
| show_tool_calls=True, | |
| markdown=True, | |
| ) | |
| def suggest_ai_integration(company_data: str, ai_strategy: str) -> str: | |
| """Suggests a structured AI implementation plan.""" | |
| query = f""" | |
| Based on the AI adoption strategy: | |
| - **Company Context:** {company_data} | |
| - **AI Strategy Summary:** {ai_strategy} | |
| Provide a structured AI implementation plan including: | |
| 1. Step-by-step AI adoption process | |
| 2. Required AI Technologies & Infrastructure | |
| 3. Workforce training & AI skill development | |
| 4. Risk considerations (data security, compliance, ethical AI) | |
| 5. Key performance indicators (KPIs) for AI success. | |
| """ | |
| response = ai_integration_agent.run(query) | |
| return response.content # Returns AI integration plan | |
| ############################## | |
| # 3️⃣ Revenue Growth Agent # | |
| ############################## | |
| revenue_growth_agent = Agent( | |
| name="Revenue Growth Agent", | |
| model=OpenAIChat(id="gpt-4o"), | |
| description="Identifies AI-driven opportunities to enhance revenue and efficiency.", | |
| show_tool_calls=True, | |
| markdown=True, | |
| ) | |
| def identify_revenue_opportunities(company_data: str, ai_strategy: str) -> str: | |
| """Identifies AI-driven revenue generation opportunities for a business.""" | |
| query = f""" | |
| You are an AI business analyst identifying AI-driven revenue growth opportunities for: | |
| - **Company Overview:** {company_data} | |
| - **AI Strategy:** {ai_strategy} | |
| Provide: | |
| 1. AI-based Monetization Strategies (new revenue streams) | |
| 2. Cost Reduction & Operational Efficiency | |
| 3. Market Expansion through AI-driven solutions | |
| 4. Competitive Positioning & Differentiation using AI. | |
| """ | |
| response = revenue_growth_agent.run(query) | |
| return response.content # Returns revenue opportunities | |
| ############################## | |
| # 4️⃣ BNI Agent: Membership Benefits # | |
| ############################## | |
| def get_bni_membership_benefits(company_data: str) -> str: | |
| """Fetches BNI membership benefits tailored to the user's company.""" | |
| return get_bni_benefits(company_data) | |
| ############################## | |
| # 5️⃣ BNI RAG Agent: Pearl Chapter Connections # | |
| ############################## | |
| def get_bni_recommendations(company_data: str) -> str: | |
| """Recommends relevant BNI Pearl Chapter members based on the user's company data.""" | |
| return recommend_bni_connections(company_data) | |
| ############################## | |
| # 6️⃣ Report Generation Agent # | |
| ############################## | |
| def generate_report(company_name: str, company_data: str, industry_trends: str, ai_use_cases: str, | |
| ai_strategy: str, ai_integration: str, revenue_opportunities: str, | |
| bni_benefits: str, bni_recommendations: str) -> str: | |
| """ | |
| Generates a structured AI strategy report in PDF format using `pdfkit`. | |
| Returns: | |
| str: Filename of the generated PDF. | |
| """ | |
| report_content = f""" | |
| # AI Strategy Report for {company_name} | |
| ## 1️⃣ Company Overview | |
| {company_data} | |
| ## 2️⃣ Industry Trends | |
| {industry_trends} | |
| ## 3️⃣ AI Use Cases | |
| {ai_use_cases} | |
| ## 4️⃣ AI Adoption Strategy | |
| {ai_strategy} | |
| ## 5️⃣ AI Implementation Plan | |
| {ai_integration} | |
| ## 6️⃣ Revenue Growth Opportunities | |
| {revenue_opportunities} | |
| ## 7️⃣ How BNI Can Help Your Business | |
| {bni_benefits} | |
| ## 8️⃣ Recommended BNI Pearl Chapter Connections | |
| {bni_recommendations} | |
| """ | |
| # Convert to Markdown | |
| markdown_report = markdown2.markdown(report_content) | |
| # Convert Markdown to PDF (Ensure wkhtmltopdf is installed) | |
| pdf_filename = f"{company_name}_AI_Report.pdf" | |
| pdfkit.from_string(markdown_report, pdf_filename) | |
| return pdf_filename # Returns the generated PDF filename |