siddhartharya
commited on
Commit
•
e7bb3db
1
Parent(s):
0c3b71f
Update app.py
Browse files
app.py
CHANGED
@@ -27,12 +27,11 @@ class AutonomousEmailAgent:
|
|
27 |
def autonomous_reasoning(self):
|
28 |
print("Autonomous Reasoning: Letting the LLM fully reason and act on available data...")
|
29 |
|
30 |
-
# LLM reasoning prompt
|
31 |
reasoning_prompt = f"""
|
32 |
You are an autonomous agent responsible for generating a job application email.
|
33 |
|
34 |
-
Here
|
35 |
-
|
36 |
- LinkedIn profile: {self.linkedin_url}
|
37 |
- Company Name: {self.company_name}
|
38 |
- Role: {self.role}
|
@@ -42,13 +41,14 @@ class AutonomousEmailAgent:
|
|
42 |
- Company Information: {self.company_info}
|
43 |
- Role Description: {self.role_description}
|
44 |
|
45 |
-
Based on this data, decide if it is sufficient to generate the email. If some information is missing or insufficient:
|
46 |
-
|
47 |
-
|
|
|
48 |
|
49 |
-
|
50 |
"""
|
51 |
-
|
52 |
# Send the reasoning prompt to the LLM
|
53 |
url = "https://api.groq.com/openai/v1/chat/completions"
|
54 |
headers = {
|
@@ -72,21 +72,34 @@ class AutonomousEmailAgent:
|
|
72 |
print(f"Error: {response.status_code}, {response.text}")
|
73 |
return "Error: Unable to complete reasoning."
|
74 |
|
75 |
-
# Function to act on the LLM's instructions
|
76 |
def act_on_llm_instructions(self, reasoning_output):
|
77 |
-
#
|
78 |
-
|
|
|
|
|
79 |
# Action: Scrape the company's website for more information
|
80 |
self.fetch_company_info_with_firecrawl()
|
81 |
# Reflect again by invoking the LLM to reassess
|
82 |
return self.autonomous_reasoning()
|
83 |
|
84 |
-
elif "
|
85 |
# Action: Proceed to generate the email
|
86 |
return self.generate_email()
|
87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
else:
|
89 |
-
|
|
|
|
|
90 |
|
91 |
# Action: Fetch LinkedIn data via Proxycurl
|
92 |
def fetch_linkedin_data(self):
|
|
|
27 |
def autonomous_reasoning(self):
|
28 |
print("Autonomous Reasoning: Letting the LLM fully reason and act on available data...")
|
29 |
|
30 |
+
# Modify LLM reasoning prompt to ask for clear, structured instructions
|
31 |
reasoning_prompt = f"""
|
32 |
You are an autonomous agent responsible for generating a job application email.
|
33 |
|
34 |
+
Here’s the current data:
|
|
|
35 |
- LinkedIn profile: {self.linkedin_url}
|
36 |
- Company Name: {self.company_name}
|
37 |
- Role: {self.role}
|
|
|
41 |
- Company Information: {self.company_info}
|
42 |
- Role Description: {self.role_description}
|
43 |
|
44 |
+
Based on this data, decide if it is sufficient to generate the email. If some information is missing or insufficient, respond with:
|
45 |
+
1. "scrape" to fetch more data from the company website.
|
46 |
+
2. "generate_email" to proceed with the email generation.
|
47 |
+
3. "fallback" to use default values.
|
48 |
|
49 |
+
After generating the email, reflect on whether the content aligns with the role and company and whether any improvements are needed. Respond clearly with one of the above options.
|
50 |
"""
|
51 |
+
|
52 |
# Send the reasoning prompt to the LLM
|
53 |
url = "https://api.groq.com/openai/v1/chat/completions"
|
54 |
headers = {
|
|
|
72 |
print(f"Error: {response.status_code}, {response.text}")
|
73 |
return "Error: Unable to complete reasoning."
|
74 |
|
75 |
+
# Function to act on the LLM's structured instructions
|
76 |
def act_on_llm_instructions(self, reasoning_output):
|
77 |
+
# Convert the output to lowercase and trim whitespace for easier parsing
|
78 |
+
instruction = reasoning_output.lower().strip()
|
79 |
+
|
80 |
+
if "scrape" in instruction:
|
81 |
# Action: Scrape the company's website for more information
|
82 |
self.fetch_company_info_with_firecrawl()
|
83 |
# Reflect again by invoking the LLM to reassess
|
84 |
return self.autonomous_reasoning()
|
85 |
|
86 |
+
elif "generate_email" in instruction:
|
87 |
# Action: Proceed to generate the email
|
88 |
return self.generate_email()
|
89 |
|
90 |
+
elif "fallback" in instruction:
|
91 |
+
# Action: Use fallback logic or default values
|
92 |
+
print("Action: Using fallback values for missing data.")
|
93 |
+
if not self.company_info:
|
94 |
+
self.company_info = "A leading company in its field."
|
95 |
+
if not self.role_description:
|
96 |
+
self.role_description = f"The role of {self.role} involves leadership and team management."
|
97 |
+
return self.generate_email()
|
98 |
+
|
99 |
else:
|
100 |
+
# If the LLM returns an unrecognized instruction, fall back to using the current available data
|
101 |
+
print("Error: Unrecognized instruction from LLM. Proceeding with available data.")
|
102 |
+
return self.generate_email()
|
103 |
|
104 |
# Action: Fetch LinkedIn data via Proxycurl
|
105 |
def fetch_linkedin_data(self):
|