Spaces:
Build error
Build error
File size: 2,616 Bytes
95b4af1 |
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 |
import os
from langchain_groq import ChatGroq
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import JsonOutputParser
from langchain_core.exceptions import OutputParserException
from dotenv import load_dotenv
load_dotenv()
class Chain:
def __init__(self):
self.llm = ChatGroq(temperature=0, groq_api_key=os.getenv("GROQ_API_KEY"), model_name="llama3-70b-8192")
def extract_jobs(self, cleaned_text):
prompt_extract = PromptTemplate.from_template(
"""
### SCRAPED TEXT FROM WEBSITE:
{page_data}
### INSTRUCTION:
The scraped text is from the career's page of a website.
Your job is to extract the job postings and return them in JSON format containing the following keys: `role`, `experience`, `skills` and `description`.
Only return the valid JSON.
### VALID JSON (NO PREAMBLE):
"""
)
chain_extract = prompt_extract | self.llm
res = chain_extract.invoke(input={"page_data": cleaned_text})
try:
json_parser = JsonOutputParser()
res = json_parser.parse(res.content)
except OutputParserException:
raise OutputParserException("Context too big. Unable to parse jobs.")
return res if isinstance(res, list) else [res]
def write_mail(self, job, links):
prompt_email = PromptTemplate.from_template(
"""
### JOB DESCRIPTION:
{job_description}
### INSTRUCTION:
You are ARBAJ's AI, a Placement Cell Executive at ITINFO. ITINFO is an AI Consulting company dedicated to facilitating
the seamless integration of business processes through training corporate indivisuals AI & ML tools.
Over our experience, we have empowered numerous enterprises with good candidates, who heightened overall efficiency.
Your job is to write a cold email to the client regarding the job mentioned above describing the capability of ITINFO
in fulfilling their needs.
Also add the most relevant ones from the following links to show candidate's LinkedIn profile : {link_list}
Remember you are AI-Placement Agent, at ITINFO.
Do not provide a preamble.
### EMAIL (NO PREAMBLE):
"""
)
chain_email = prompt_email | self.llm
res = chain_email.invoke({"job_description": str(job), "link_list": links})
return res.content
if __name__ == "__main__":
print(os.getenv("GROQ_API_KEY")) |