File size: 2,076 Bytes
4ec2c90
 
 
 
 
 
 
 
 
 
f7d1f05
 
4ec2c90
f7d1f05
4ec2c90
bd53c47
4ec2c90
f7d1f05
bd53c47
 
f7d1f05
3df0b02
bd53c47
 
 
4ec2c90
bd53c47
4ec2c90
bd53c47
 
4ec2c90
bd53c47
 
 
 
3df0b02
f7d1f05
4ec2c90
 
 
 
 
 
 
f7d1f05
4ec2c90
f7d1f05
 
4ec2c90
 
f7d1f05
4ec2c90
 
f7d1f05
4ec2c90
f7d1f05
 
4ec2c90
 
 
 
f7d1f05
4ec2c90
 
 
 
f7d1f05
e8110e4
4ec2c90
 
 
 
 
f7d1f05
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
import os
import json
import pandas as pd
from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.embedder.openai import OpenAIEmbedder
from phi.vectordb.lancedb import LanceDb, SearchType
from phi.knowledge.json import JSONKnowledgeBase
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# Paths
BNI_CSV_FILE = "bni_pearl_chapter.csv"
BNI_JSON_FILE = "bni_pearl_chapter.json"

# Convert CSV to JSON if JSON doesn't exist
def convert_csv_to_json():
    if not os.path.exists(BNI_CSV_FILE):
        raise FileNotFoundError(f"❌ Error: {BNI_CSV_FILE} is missing.")

    df = pd.read_csv(BNI_CSV_FILE)
    if df.empty:
        raise ValueError(f"❌ Error: {BNI_CSV_FILE} is empty!")

    json_data = df.to_dict(orient="records")

    with open(BNI_JSON_FILE, "w") as file:
        json.dump(json_data, file, indent=4)

    print(f"✅ Converted {BNI_CSV_FILE} to JSON format.")

if not os.path.exists(BNI_JSON_FILE):
    convert_csv_to_json()

# Initialize LanceDb (vector DB)
vector_db = LanceDb(
    table_name="bni_pearl",
    uri="tmp/lancedb",
    search_type=SearchType.vector,
    embedder=OpenAIEmbedder(model="text-embedding-3-small"),
)

# Initialize JSON Knowledge Base
knowledge_base = JSONKnowledgeBase(
    path=BNI_JSON_FILE,  # Important: `path` instead of `file_path`
    vector_db=vector_db
)

# Load the knowledge base
knowledge_base.load()

# Initialize the RAG Agent
rag_agent = Agent(
    model=OpenAIChat(model="gpt-4o"),
    knowledge=knowledge_base,
    show_tool_calls=True,
    markdown=True,
)

# Define Function to Recommend BNI Members
def recommend_bni_connections(company_data: str) -> str:
    query = f"""
    Given the following business details:
    - **Company Information:** {company_data}

    Recommend **5-6 members** from the BNI Pearl Chapter who can help this business through referrals, networking, or industry connections. Provide:
    1. **Member Name**
    2. **Company & Industry**
    3. **How They Can Help**
    """
    response = rag_agent.run(query)
    return response.content