HuyDN commited on
Commit
62d3b3c
1 Parent(s): 718dcb3

phase1/HuyDN: Add function jd2text and text2tector

Browse files
app/modules/question_retrieval/__init__.py CHANGED
@@ -1,7 +1,21 @@
1
- from fastapi import APIRouter, UploadFile
 
 
 
2
 
3
  qtretrieval_router = APIRouter(prefix="/qtretrieval", tags=["qtretrieval"])
4
 
5
  @qtretrieval_router.get("/")
6
  async def index():
7
- return {"message": "Welcome to question retrieval page"}
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import APIRouter, UploadFile, File
2
+ from typing import Annotated
3
+
4
+ from app.modules.question_retrieval.models.jd2text import jobdes2text
5
 
6
  qtretrieval_router = APIRouter(prefix="/qtretrieval", tags=["qtretrieval"])
7
 
8
  @qtretrieval_router.get("/")
9
  async def index():
10
+ return {"message": "Welcome to question retrieval page"}
11
+
12
+ @qtretrieval_router.post("/send_jd")
13
+ # only upload .txt file
14
+ async def send_jd(txt_file: Annotated[UploadFile, File(..., description="The JD file", media_type=["text/plain"])]):
15
+ try:
16
+ # read the txt file with format
17
+ jobdes = txt_file.file.read().decode("utf-8")
18
+ result = jobdes2text(jobdes)
19
+ return {"message": "Send JD successfully", "text": result}
20
+ except Exception as e:
21
+ return {"message": "Error", "error": "Please check the file format or the file content. The file should be .txt format."}
app/modules/question_retrieval/models/jd2text.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_google_genai import ChatGoogleGenerativeAI
2
+ from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate
3
+ from langchain_core.messages import SystemMessage
4
+ from langchain_core.output_parsers import JsonOutputParser
5
+ import os
6
+ from dotenv import load_dotenv
7
+
8
+ # load the environment variables
9
+ load_dotenv()
10
+
11
+ # Define the google api key
12
+ os.environ['GOOGLE_API_KEY'] = os.getenv('GOOGLE_API_KEY')
13
+ GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
14
+
15
+ # define the parser object
16
+ parser = JsonOutputParser()
17
+
18
+ def jobdes2text(jobdes):
19
+ # setup the gemini pro
20
+ llm = ChatGoogleGenerativeAI(model="gemini-pro", temperature=0.3, convert_system_message_to_human=True, api_key=GOOGLE_API_KEY)
21
+
22
+ # create the prompt template
23
+ finnal_jd_chat_template = ChatPromptTemplate.from_messages(
24
+ [
25
+ SystemMessage(
26
+ content=(
27
+ """Return Job title, level(Fresher, Junior, Senior, ...) and Brief summary of required skills about 20 words from the job description. Use the following format: Job Title is {job title}, Level is {level}, and Brief summary of required skills is {brief summary of required skills}."""
28
+ )
29
+ ),
30
+ HumanMessagePromptTemplate.from_template("{text}"),
31
+ ]
32
+ )
33
+
34
+ # create the chat message
35
+ chat_message = finnal_jd_chat_template.format_messages(text=jobdes)
36
+
37
+ # create a chain
38
+ chain = llm
39
+
40
+ result = chain.invoke(chat_message)
41
+
42
+ return result
app/modules/question_retrieval/models/text2tector.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ from langchain_google_genai import GoogleGenerativeAIEmbeddings
4
+
5
+ # Define the google api key
6
+ os.environ['GOOGLE_API_KEY'] = os.getenv('GOOGLE_API_KEY')
7
+ GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
8
+
9
+ def text2vector(text):
10
+ embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001", google_api_key=GOOGLE_API_KEY)
11
+ vector = embeddings.embed_query(text)
12
+ return vector
data/test_data/jd_1.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Senior AI Engineer
2
+
3
+ This position focuses on developing algorithms for multilingual conversational systems and improving chatbots using advanced Natural Language Processing (NLP) techniques. Responsibilities include collaborating on NLP applications, conducting research, and optimizing AI models.
4
+
5
+ Responsibilities:
6
+ • Develop algorithms in multilingual conversational systems
7
+ • Implement NLP techniques to enhance text analysis & chatbots understanding of user intent, sentiment analysis, and context-aware responses
8
+ • Team up with software engineers to build end-to-end NLP applications
9
+ • Conduct research and stay up-to-date with the latest advancements in NLP
10
+ • Monitor and analyze the performance of AI models in production, identify and troubleshoot any issues or bottlenecks, and propose solutions for optimization
11
+ • Communicating complex analytical findings and recommendations to non-technical stakeholders, including senior management.