Update app.py
Browse files
app.py
CHANGED
@@ -20,7 +20,6 @@ class AutonomousEmailAgent:
|
|
20 |
self.role_description = None
|
21 |
self.attempts = 0 # Counter for iterations
|
22 |
|
23 |
-
# Fetch LinkedIn data via Proxycurl
|
24 |
def fetch_linkedin_data(self):
|
25 |
proxycurl_api_key = os.getenv("PROXYCURL_API_KEY")
|
26 |
if not self.linkedin_url:
|
@@ -43,19 +42,16 @@ class AutonomousEmailAgent:
|
|
43 |
print("Error: Unable to fetch LinkedIn profile. Status Code:", response.status_code)
|
44 |
self.use_default_profile()
|
45 |
|
46 |
-
# Set default profile information if LinkedIn scraping fails
|
47 |
def use_default_profile(self):
|
48 |
print("Using default profile values.")
|
49 |
self.bio = "A professional with a versatile background and extensive experience."
|
50 |
self.skills = ["Leadership", "Communication", "Problem-solving"]
|
51 |
self.experiences = [{"title": "Project Manager"}, {"title": "Team Leader"}]
|
52 |
|
53 |
-
# Main loop following ReAct pattern
|
54 |
def run(self):
|
55 |
self.fetch_linkedin_data()
|
56 |
return self.autonomous_reasoning()
|
57 |
|
58 |
-
# Reason and Act via LLM: Let the LLM control reasoning and actions dynamically
|
59 |
def autonomous_reasoning(self):
|
60 |
print("Autonomous Reasoning: Letting the LLM fully reason and act on available data...")
|
61 |
|
@@ -78,7 +74,6 @@ class AutonomousEmailAgent:
|
|
78 |
|
79 |
return self.send_request_to_llm(reasoning_prompt)
|
80 |
|
81 |
-
# Send request to Groq Cloud LLM with enhanced debugging and error handling
|
82 |
def send_request_to_llm(self, prompt):
|
83 |
print("Sending request to Groq Cloud LLM...")
|
84 |
api_key = os.getenv("GROQ_API_KEY")
|
@@ -105,7 +100,7 @@ class AutonomousEmailAgent:
|
|
105 |
if choices and "message" in choices[0]:
|
106 |
content = choices[0]["message"]["content"]
|
107 |
print(f"Content: {content}")
|
108 |
-
return self.
|
109 |
else:
|
110 |
print("Error: Unrecognized format in LLM response.")
|
111 |
return "Error: Unrecognized response format."
|
@@ -116,19 +111,20 @@ class AutonomousEmailAgent:
|
|
116 |
print(f"Error: Unable to connect to Groq Cloud LLM. Status Code: {response.status_code}")
|
117 |
return "Error: Unable to generate response."
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
Best regards,
|
126 |
{self.user_name}
|
127 |
Email: {self.email}
|
128 |
Phone: {self.phone}
|
129 |
LinkedIn: {self.linkedin}
|
130 |
"""
|
131 |
-
|
|
|
132 |
|
133 |
# Gradio UI setup remains unchanged
|
134 |
def gradio_ui():
|
|
|
20 |
self.role_description = None
|
21 |
self.attempts = 0 # Counter for iterations
|
22 |
|
|
|
23 |
def fetch_linkedin_data(self):
|
24 |
proxycurl_api_key = os.getenv("PROXYCURL_API_KEY")
|
25 |
if not self.linkedin_url:
|
|
|
42 |
print("Error: Unable to fetch LinkedIn profile. Status Code:", response.status_code)
|
43 |
self.use_default_profile()
|
44 |
|
|
|
45 |
def use_default_profile(self):
|
46 |
print("Using default profile values.")
|
47 |
self.bio = "A professional with a versatile background and extensive experience."
|
48 |
self.skills = ["Leadership", "Communication", "Problem-solving"]
|
49 |
self.experiences = [{"title": "Project Manager"}, {"title": "Team Leader"}]
|
50 |
|
|
|
51 |
def run(self):
|
52 |
self.fetch_linkedin_data()
|
53 |
return self.autonomous_reasoning()
|
54 |
|
|
|
55 |
def autonomous_reasoning(self):
|
56 |
print("Autonomous Reasoning: Letting the LLM fully reason and act on available data...")
|
57 |
|
|
|
74 |
|
75 |
return self.send_request_to_llm(reasoning_prompt)
|
76 |
|
|
|
77 |
def send_request_to_llm(self, prompt):
|
78 |
print("Sending request to Groq Cloud LLM...")
|
79 |
api_key = os.getenv("GROQ_API_KEY")
|
|
|
100 |
if choices and "message" in choices[0]:
|
101 |
content = choices[0]["message"]["content"]
|
102 |
print(f"Content: {content}")
|
103 |
+
return self.format_email(content)
|
104 |
else:
|
105 |
print("Error: Unrecognized format in LLM response.")
|
106 |
return "Error: Unrecognized response format."
|
|
|
111 |
print(f"Error: Unable to connect to Groq Cloud LLM. Status Code: {response.status_code}")
|
112 |
return "Error: Unable to generate response."
|
113 |
|
114 |
+
def format_email(self, llm_response):
|
115 |
+
# Remove unnecessary tabs and spaces and format consistently
|
116 |
+
lines = [line.strip() for line in llm_response.split("\n")]
|
117 |
+
formatted_email = "\n\n".join([line for line in lines if line])
|
118 |
+
|
119 |
+
signature = f"""
|
120 |
Best regards,
|
121 |
{self.user_name}
|
122 |
Email: {self.email}
|
123 |
Phone: {self.phone}
|
124 |
LinkedIn: {self.linkedin}
|
125 |
"""
|
126 |
+
|
127 |
+
return f"{formatted_email}\n\n{signature.strip()}"
|
128 |
|
129 |
# Gradio UI setup remains unchanged
|
130 |
def gradio_ui():
|