HuyDN
Phase2/HuyDN: Optimization speed and fix bugs
d6ef950
raw history blame
No virus
2.59 kB
import os
import docx
from dotenv import load_dotenv
# import prompt template
from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate
from langchain_core.messages import SystemMessage
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_anthropic import ChatAnthropic
from langchain_openai import OpenAI
# import the json oupput parser from the langchain core
from langchain_core.output_parsers import JsonOutputParser
# define the parser object
parser = JsonOutputParser()
# Import API key
load_dotenv()
# Define the google api key
os.environ['GOOGLE_API_KEY'] = os.getenv('GOOGLE_API_KEY')
os.environ['CLAUDE_API_KEY'] = os.getenv('CLAUDE_API_KEY')
os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY')
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
CLAUDE_API_KEY = os.environ.get("CLAUDE_API_KEY")
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
llm = ChatGoogleGenerativeAI(model="gemini-pro", temperature=0.3, convert_system_message_to_human=True, api_key=GOOGLE_API_KEY, request_timeout=120)
# llm = ChatAnthropic(temperature=0.3, model_name="claude-3-opus-20240229", anthropic_api_key=CLAUDE_API_KEY, default_request_timeout=120)
# llm = OpenAI(model_name="gpt-3.5-turbo-0125", openai_api_key=OPENAI_API_KEY)
chain = llm | parser
# create the prompt template
chat_template = ChatPromptTemplate.from_messages(
[
SystemMessage(
content=(
"""
Given the following CV and JD, calculate the percentage match between the candidate's qualifications and the job requirements:
CV: {cv}
JD: {jd}
To determine the match percentage, analyze the skills and experience in the CV and compare them to the requirements outlined in the JD. Provide the final match percentage as a numeric value between 0-100%, along with a brief explanation of your analysis. Follow this json format: {"Skills Match": {"Required Skills": "","Candidate Skills": "","Match Percentage": "",}, "Experience Match": {"Required Experience": "","Candidate Experience": "","Match Percentage": "",}, "Overall Match Percentage:": "", "Explanation": ""}
"""
)
),
HumanMessagePromptTemplate.from_template(["{cv}", "{jd}"]),
]
)
# def matching cv and jd return percentage of matching using prompt template
def result_matching_cv_jd(cv_text:str, jd_text:str):
# create the chat message
chat_message = chat_template.format_messages(cv=cv_text, jd=jd_text)
result = chain.invoke(chat_message)
return result