CoolFace
Apppublic

hitz02/jd_generation

sourceHugging Faceccupdated 3y agoView on Hugging Face
0likes
utils.py85 linesDownload Raw Back to root
1 2from langchain import PromptTemplate, FewShotPromptTemplate3from langchain import HuggingFaceHub, LLMChain, OpenAI4import os5 6 7input_temp = """Candidate Name - 8jobs in - 9distance - 10pay range - 11job details - 12position available at - """13 14 15example_input_feat_temp = """Candidate Name - Alex16jobs in - Netsuite ERP domain17distance - 5 miles18pay range - $180,000 to $200,000 per year19job details - implementing and upgrading the NetSuite system, understanding client requirements, and providing maintenance and support20position available at - Atlanta, Peachtree City, and Woodstock in Georgia, US"""21 22 23example_input_subj_body_temp = """Subject: 24Netsuite ERP jobs 5 miles from you - Earn upto $200,000/year!25    26Body:27Hi Alex!28We haven't connected in a while, and I would love to get back in touch to help you find your next assignment!29We 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."""30 31 32def return_template(ex_feat, ex_subj_body):33    34    examples = [{"Input" : ex_feat, "Output" : ex_subj_body}]35 36    example_formatter_template = """37    Input: {Input}38    Output: {Output}\n39    """40 41    example_prompt = PromptTemplate(42        input_variables=["Input","Output"],43        template=example_formatter_template,44    )45    46    # Finally, we create the `FewShotPromptTemplate` object.47    few_shot_prompt = FewShotPromptTemplate(48        # These are the examples we want to insert into the prompt.49        examples=examples,50        # This is how we want to format the examples when we insert them into the prompt.51        example_prompt=example_prompt,52        # The prefix is some text that goes before the examples in the prompt.53        # Usually, this consists of intructions.54        prefix="Generate an email subject and body by taking following inputs-",55        # The suffix is some text that goes after the examples in the prompt.56        # Usually, this is where the user input will go57        suffix="Input: {input}\n\nOutput:",58        # The input variables are the variables that the overall prompt expects.59        input_variables=["input"],60        # The example_separator is the string we will use to join the prefix, examples, and suffix together with.61        example_separator="\n\n",62    )63    64    return few_shot_prompt65 66 67def llm_dict_func(llm, api_key):68    69    if llm == "gpt-3.5-turbo":70        return OpenAI(model_name="gpt-3.5-turbo",71                      openai_api_key = api_key)72    73    elif llm == "google_flan_t5_xxl":74        return HuggingFaceHub(repo_id="google/flan-t5-xxl",75                                huggingfacehub_api_token = api_key,76                                model_kwargs={"temperature":0.001, "max_new_tokens":500})77    78    79def llm_chain_func(fs_prompt, llm, api_key):80    llm_chain = LLMChain(prompt=fs_prompt,81                         llm=llm_dict_func(llm, api_key)82                         )83    84    return llm_chain85