Update chains.py
Browse files
chains.py
CHANGED
|
@@ -1,60 +1,60 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from langchain_groq import ChatGroq
|
| 3 |
-
from langchain_core.prompts import PromptTemplate
|
| 4 |
-
from langchain_core.output_parsers import JsonOutputParser
|
| 5 |
-
from langchain_core.exceptions import OutputParserException
|
| 6 |
-
from dotenv import load_dotenv
|
| 7 |
-
|
| 8 |
-
load_dotenv()
|
| 9 |
-
|
| 10 |
-
class Chain:
|
| 11 |
-
def __init__(self):
|
| 12 |
-
self.llm = ChatGroq(temperature=0, groq_api_key=os.getenv("GROQ_API_KEY"), model_name="llama-3.
|
| 13 |
-
|
| 14 |
-
def extract_jobs(self, cleaned_text):
|
| 15 |
-
prompt_extract = PromptTemplate.from_template(
|
| 16 |
-
"""
|
| 17 |
-
### SCRAPED TEXT FROM WEBSITE:
|
| 18 |
-
{page_data}
|
| 19 |
-
### INSTRUCTION:
|
| 20 |
-
The scraped text is from the career's page of a website.
|
| 21 |
-
Your job is to extract the job postings and return them in JSON format containing the following keys: `role`, `experience`, `skills` and `description`.
|
| 22 |
-
Only return the valid JSON.
|
| 23 |
-
### VALID JSON (NO PREAMBLE):
|
| 24 |
-
"""
|
| 25 |
-
)
|
| 26 |
-
chain_extract = prompt_extract | self.llm
|
| 27 |
-
res = chain_extract.invoke(input={"page_data": cleaned_text})
|
| 28 |
-
try:
|
| 29 |
-
json_parser = JsonOutputParser()
|
| 30 |
-
res = json_parser.parse(res.content)
|
| 31 |
-
except OutputParserException:
|
| 32 |
-
raise OutputParserException("Context too big. Unable to parse jobs.")
|
| 33 |
-
return res if isinstance(res, list) else [res]
|
| 34 |
-
|
| 35 |
-
def write_mail(self, job, links):
|
| 36 |
-
prompt_email = PromptTemplate.from_template(
|
| 37 |
-
"""
|
| 38 |
-
### JOB DESCRIPTION:
|
| 39 |
-
{job_description}
|
| 40 |
-
|
| 41 |
-
### INSTRUCTION:
|
| 42 |
-
You are Mohan, a business development executive at AtliQ. AtliQ is an AI & Software Consulting company dedicated to facilitating
|
| 43 |
-
the seamless integration of business processes through automated tools.
|
| 44 |
-
Over our experience, we have empowered numerous enterprises with tailored solutions, fostering scalability,
|
| 45 |
-
process optimization, cost reduction, and heightened overall efficiency.
|
| 46 |
-
Your job is to write a cold email to the client regarding the job mentioned above describing the capability of AtliQ
|
| 47 |
-
in fulfilling their needs.
|
| 48 |
-
Also add the most relevant ones from the following links to showcase Atliq's portfolio: {link_list}
|
| 49 |
-
Remember you are Mohan, BDE at AtliQ.
|
| 50 |
-
Do not provide a preamble.
|
| 51 |
-
### EMAIL (NO PREAMBLE):
|
| 52 |
-
|
| 53 |
-
"""
|
| 54 |
-
)
|
| 55 |
-
chain_email = prompt_email | self.llm
|
| 56 |
-
res = chain_email.invoke({"job_description": str(job), "link_list": links})
|
| 57 |
-
return res.content
|
| 58 |
-
|
| 59 |
-
if __name__ == "__main__":
|
| 60 |
print(os.getenv("GROQ_API_KEY"))
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from langchain_groq import ChatGroq
|
| 3 |
+
from langchain_core.prompts import PromptTemplate
|
| 4 |
+
from langchain_core.output_parsers import JsonOutputParser
|
| 5 |
+
from langchain_core.exceptions import OutputParserException
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
class Chain:
|
| 11 |
+
def __init__(self):
|
| 12 |
+
self.llm = ChatGroq(temperature=0, groq_api_key=os.getenv("GROQ_API_KEY"), model_name="llama-3.3-70b-versatile")
|
| 13 |
+
|
| 14 |
+
def extract_jobs(self, cleaned_text):
|
| 15 |
+
prompt_extract = PromptTemplate.from_template(
|
| 16 |
+
"""
|
| 17 |
+
### SCRAPED TEXT FROM WEBSITE:
|
| 18 |
+
{page_data}
|
| 19 |
+
### INSTRUCTION:
|
| 20 |
+
The scraped text is from the career's page of a website.
|
| 21 |
+
Your job is to extract the job postings and return them in JSON format containing the following keys: `role`, `experience`, `skills` and `description`.
|
| 22 |
+
Only return the valid JSON.
|
| 23 |
+
### VALID JSON (NO PREAMBLE):
|
| 24 |
+
"""
|
| 25 |
+
)
|
| 26 |
+
chain_extract = prompt_extract | self.llm
|
| 27 |
+
res = chain_extract.invoke(input={"page_data": cleaned_text})
|
| 28 |
+
try:
|
| 29 |
+
json_parser = JsonOutputParser()
|
| 30 |
+
res = json_parser.parse(res.content)
|
| 31 |
+
except OutputParserException:
|
| 32 |
+
raise OutputParserException("Context too big. Unable to parse jobs.")
|
| 33 |
+
return res if isinstance(res, list) else [res]
|
| 34 |
+
|
| 35 |
+
def write_mail(self, job, links):
|
| 36 |
+
prompt_email = PromptTemplate.from_template(
|
| 37 |
+
"""
|
| 38 |
+
### JOB DESCRIPTION:
|
| 39 |
+
{job_description}
|
| 40 |
+
|
| 41 |
+
### INSTRUCTION:
|
| 42 |
+
You are Mohan, a business development executive at AtliQ. AtliQ is an AI & Software Consulting company dedicated to facilitating
|
| 43 |
+
the seamless integration of business processes through automated tools.
|
| 44 |
+
Over our experience, we have empowered numerous enterprises with tailored solutions, fostering scalability,
|
| 45 |
+
process optimization, cost reduction, and heightened overall efficiency.
|
| 46 |
+
Your job is to write a cold email to the client regarding the job mentioned above describing the capability of AtliQ
|
| 47 |
+
in fulfilling their needs.
|
| 48 |
+
Also add the most relevant ones from the following links to showcase Atliq's portfolio: {link_list}
|
| 49 |
+
Remember you are Mohan, BDE at AtliQ.
|
| 50 |
+
Do not provide a preamble.
|
| 51 |
+
### EMAIL (NO PREAMBLE):
|
| 52 |
+
|
| 53 |
+
"""
|
| 54 |
+
)
|
| 55 |
+
chain_email = prompt_email | self.llm
|
| 56 |
+
res = chain_email.invoke({"job_description": str(job), "link_list": links})
|
| 57 |
+
return res.content
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
print(os.getenv("GROQ_API_KEY"))
|