Update app.py
Browse files
app.py
CHANGED
|
@@ -8,14 +8,19 @@ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
|
| 8 |
PROXYCURL_API_KEY = os.getenv("PROXYCURL_API_KEY")
|
| 9 |
FIRECRAWL_API_KEY = os.getenv("FIRECRAWL_API_KEY")
|
| 10 |
|
| 11 |
-
# Function to fetch LinkedIn data using Proxycurl API
|
| 12 |
def fetch_linkedin_data(linkedin_url):
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
if response.status_code == 200:
|
| 16 |
return response.json()
|
| 17 |
else:
|
| 18 |
-
return {"error": "
|
| 19 |
|
| 20 |
# Function to fetch company information using Firecrawl API
|
| 21 |
def fetch_company_info(company_url):
|
|
@@ -24,7 +29,7 @@ def fetch_company_info(company_url):
|
|
| 24 |
if response.status_code == 200:
|
| 25 |
return response.json()
|
| 26 |
else:
|
| 27 |
-
return {"error": "
|
| 28 |
|
| 29 |
# Function to structure the email using the "Start with Why" model
|
| 30 |
def structure_email(user_data, linkedin_info, company_info):
|
|
@@ -56,7 +61,6 @@ class Agent:
|
|
| 56 |
self.user_data = user_data
|
| 57 |
|
| 58 |
def act(self):
|
| 59 |
-
# Agent performs its task based on instructions
|
| 60 |
if self.name == "Data Collection Agent":
|
| 61 |
linkedin_info = fetch_linkedin_data(self.user_data['linkedin_url'])
|
| 62 |
company_info = fetch_company_info(self.user_data['company_url'])
|
|
@@ -113,7 +117,6 @@ def run_agent(name, email, phone, linkedin_url, company_url, role):
|
|
| 113 |
if validate_email(email_content):
|
| 114 |
return email_content
|
| 115 |
else:
|
| 116 |
-
# Refine the prompt based on the feedback or iteration logic
|
| 117 |
refined_prompt = f"Refine: {structure_email(user_data, linkedin_info, company_info)}"
|
| 118 |
email_content = generate_email_content(OPENAI_API_KEY, refined_prompt)
|
| 119 |
|
|
|
|
| 8 |
PROXYCURL_API_KEY = os.getenv("PROXYCURL_API_KEY")
|
| 9 |
FIRECRAWL_API_KEY = os.getenv("FIRECRAWL_API_KEY")
|
| 10 |
|
| 11 |
+
# Function to fetch LinkedIn data using the Proxycurl API
|
| 12 |
def fetch_linkedin_data(linkedin_url):
|
| 13 |
+
api_key = os.getenv("PROXYCURL_API_KEY")
|
| 14 |
+
headers = {'Authorization': f'Bearer {api_key}'}
|
| 15 |
+
api_endpoint = 'https://nubela.co/proxycurl/api/v2/linkedin'
|
| 16 |
+
|
| 17 |
+
response = requests.get(api_endpoint,
|
| 18 |
+
params={'url': linkedin_url},
|
| 19 |
+
headers=headers)
|
| 20 |
if response.status_code == 200:
|
| 21 |
return response.json()
|
| 22 |
else:
|
| 23 |
+
return {"error": f"Error fetching LinkedIn data: {response.text}"}
|
| 24 |
|
| 25 |
# Function to fetch company information using Firecrawl API
|
| 26 |
def fetch_company_info(company_url):
|
|
|
|
| 29 |
if response.status_code == 200:
|
| 30 |
return response.json()
|
| 31 |
else:
|
| 32 |
+
return {"error": f"Error fetching company information: {response.text}"}
|
| 33 |
|
| 34 |
# Function to structure the email using the "Start with Why" model
|
| 35 |
def structure_email(user_data, linkedin_info, company_info):
|
|
|
|
| 61 |
self.user_data = user_data
|
| 62 |
|
| 63 |
def act(self):
|
|
|
|
| 64 |
if self.name == "Data Collection Agent":
|
| 65 |
linkedin_info = fetch_linkedin_data(self.user_data['linkedin_url'])
|
| 66 |
company_info = fetch_company_info(self.user_data['company_url'])
|
|
|
|
| 117 |
if validate_email(email_content):
|
| 118 |
return email_content
|
| 119 |
else:
|
|
|
|
| 120 |
refined_prompt = f"Refine: {structure_email(user_data, linkedin_info, company_info)}"
|
| 121 |
email_content = generate_email_content(OPENAI_API_KEY, refined_prompt)
|
| 122 |
|