jd_generation / utils.py
hitz02's picture
Update utils.py
f2824c9
from langchain import PromptTemplate, FewShotPromptTemplate
from langchain import HuggingFaceHub, LLMChain, OpenAI
import os
input_temp = """Candidate Name -
jobs in -
distance -
pay range -
job details -
position available at - """
example_input_feat_temp = """Candidate Name - Alex
jobs in - Netsuite ERP domain
distance - 5 miles
pay range - $180,000 to $200,000 per year
job details - implementing and upgrading the NetSuite system, understanding client requirements, and providing maintenance and support
position available at - Atlanta, Peachtree City, and Woodstock in Georgia, US"""
example_input_subj_body_temp = """Subject:
Netsuite ERP jobs 5 miles from you - Earn upto $200,000/year!
Body:
Hi Alex!
We haven't connected in a while, and I would love to get back in touch to help you find your next assignment!
We have several exciting job opportunities available for you in the NetSuite ERP domain. These positions include NetSuite Financial Consultant, NetSuite ARM Consultant, NetSuite Manager, and NetSuite Supply Chain Consultant. You can earn between $180,000 to $200,000 per year for any of these jobs. Each role involves implementing and upgrading the NetSuite system, understanding client requirements, and providing maintenance and support. As a successful candidate, you will work with stakeholders to optimize business processes and provide customizations to the NetSuite system. We have positions available in Atlanta, Peachtree City, and Woodstock in Georgia, US."""
def return_template(ex_feat, ex_subj_body):
examples = [{"Input" : ex_feat, "Output" : ex_subj_body}]
example_formatter_template = """
Input: {Input}
Output: {Output}\n
"""
example_prompt = PromptTemplate(
input_variables=["Input","Output"],
template=example_formatter_template,
)
# Finally, we create the `FewShotPromptTemplate` object.
few_shot_prompt = FewShotPromptTemplate(
# These are the examples we want to insert into the prompt.
examples=examples,
# This is how we want to format the examples when we insert them into the prompt.
example_prompt=example_prompt,
# The prefix is some text that goes before the examples in the prompt.
# Usually, this consists of intructions.
prefix="Generate an email subject and body by taking following inputs-",
# The suffix is some text that goes after the examples in the prompt.
# Usually, this is where the user input will go
suffix="Input: {input}\n\nOutput:",
# The input variables are the variables that the overall prompt expects.
input_variables=["input"],
# The example_separator is the string we will use to join the prefix, examples, and suffix together with.
example_separator="\n\n",
)
return few_shot_prompt
def llm_dict_func(llm, api_key):
if llm == "gpt-3.5-turbo":
return OpenAI(model_name="gpt-3.5-turbo",
openai_api_key = api_key)
elif llm == "google_flan_t5_xxl":
return HuggingFaceHub(repo_id="google/flan-t5-xxl",
huggingfacehub_api_token = api_key,
model_kwargs={"temperature":0.001, "max_new_tokens":500})
def llm_chain_func(fs_prompt, llm, api_key):
llm_chain = LLMChain(prompt=fs_prompt,
llm=llm_dict_func(llm, api_key)
)
return llm_chain