-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchains.py
70 lines (65 loc) · 2.7 KB
/
chains.py
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
60
61
62
63
64
65
66
67
68
69
70
import os
from dotenv import load_dotenv
from langchain_groq import ChatGroq
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import JsonOutputParser
from langchain_core.exceptions import OutputParserException
load_dotenv()
class Chain:
def __init__(self):
key = os.getenv('GROQ_API_KEY')
self.llm = ChatGroq(
groq_api_key=key,
model="llama3-8b-8192",
temperature=1,
max_tokens=None,
max_retries=3,
timeout=None
)
def write_mail(self, job, links):
prompt = PromptTemplate.from_template(
"""
### JOB DESCRIPTION:
{job_description}
### INSTRUCTION:
You are Dhruv Yadav, a Business Development Executive (BDE) at DY IT. DY IT is an AI & Software Consulting company dedicated to facilitating
the seamless integration of business processes through automated tools.
Over our experience, we have empowered numerous enterprises with tailored solutions, fostering scalability,
process optimization, cost reduction, and heightened overall efficiency.
Your job is to write a cold email to the client regarding the job mentioned above describing the capability of DY IT
in fulfilling their needs.
Also add the most relevant ones from the following links to showcase DY IT portfolio: {link_list}
Remember you are Dhruv Yadav, BDE at DY IT.
Do not provide a preamble.
### EMAIL (NO PREAMBLE):
"""
)
chain = prompt | self.llm
result = chain.invoke({
"job_description": str(job),
"link_list": links
})
return result.content
def extract_jobs(self, text):
prompt = 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 = prompt | self.llm
result = chain.invoke({
"page_data": text
})
try:
json = JsonOutputParser()
result = json.parse(result.content)
return result if isinstance(result, list) else [result] # we want to return the list of jobs available
except Exception as e:
raise OutputParserException("Retry!")