cover letter bug fixed

This commit is contained in:
feder-cr 2024-08-12 23:00:55 +01:00
parent 2531f9c824
commit 2dcd7943e8
3 changed files with 21 additions and 24 deletions

View File

@ -108,9 +108,9 @@ This file contains sensitive information. Never share or commit this file to ver
- `openai_api_key: [Your OpenAI API key]`
- Replace with your OpenAI API key for GPT integration
- To obtain an API key, follow the tutorial at: https://medium.com/@lorenzozar/how-to-get-your-own-openai-api-key-f4d44e60c327
- Note: You need to add credit to your OpenAI account to use the API. You can add credit by visiting the [OpenAI billing dashboard](https://platform.openai.com/account/billing).
**P.S.:**You need to add some credit to your OpenAI account to continue using the API. Without credit, the API will not function properly.
You can add credit by visiting the [OpenAI billing dashboard](https://platform.openai.com/account/billing).
### 2. config.yaml

18
gpt.py
View File

@ -196,7 +196,7 @@ class GPTAnswerer:
def answer_question_textual_wide_range(self, question: str) -> str:
# Define chains for each section of the resume
self.chains = {
chains = {
"personal_information": self._create_chain(strings.personal_information_template),
"self_identification": self._create_chain(strings.self_identification_template),
"legal_authorization": self._create_chain(strings.legal_authorization_template),
@ -209,29 +209,29 @@ class GPTAnswerer:
"certifications": self._create_chain(strings.certifications_template),
"languages": self._create_chain(strings.languages_template),
"interests": self._create_chain(strings.interests_template),
"cover_letter": self._create_chain(strings.coverletter_template),
}
section_prompt = (
f"For the following question: '{question}', which section of the resume is relevant? "
"Respond with one of the following: Personal information, Self Identification, Legal Authorization, "
"Work Preferences, Education Details, Experience Details, Projects, Availability, Salary Expectations, "
"Certifications, Languages, Interests."
"Certifications, Languages, Interests, Cover letter"
)
prompt = ChatPromptTemplate.from_template(section_prompt)
chain = prompt | self.llm_cheap | StrOutputParser()
output = chain.invoke({"question": question})
section_name = output.lower().replace(" ", "_")
if section_name == "cover_letter":
chain = chains.get(section_name)
output= chain.invoke({"resume": self.resume, "job_description": self.job_description})
return output
resume_section = getattr(self.resume, section_name, None)
if resume_section is None:
raise ValueError(f"Section '{section_name}' not found in the resume.")
# Use the corresponding chain to answer the question
chain = self.chains.get(section_name)
chain = chains.get(section_name)
if chain is None:
raise ValueError(f"Chain not defined for section '{section_name}'")
output_str = chain.invoke({"resume_section": resume_section, "question": question})
return output_str
return chain.invoke({"resume_section": resume_section, "question": question})
def answer_question_textual(self, question: str) -> str:
template = self._preprocess_template_string(strings.resume_stuff_template)

View File

@ -399,29 +399,26 @@ This comprehensive overview will serve as a guideline for the recruitment proces
coverletter_template = """
The following is a resume, a job description, and an answered question using this information, being answered by the person who's resume it is (first person).
Compose a brief and impactful cover letter based on the provided job description and resume. The letter should be no longer than three paragraphs and should be written in a professional, yet conversational tone. Avoid using any placeholders, and ensure that the letter flows naturally and is tailored to the job.
## Rules
- Answer questions directly.
- If seems likely that you have the experience, even if is not explicitly defined, answer as if you have the experience.
- Find relations between the job description and the resume, and answer questions about that.
- Only add periods if the answer has multiple sentences/paragraphs.
- If the question is "cover letter," answer with a cover letter based on job_description, but using my resume details
Analyze the job description to identify key qualifications and requirements. Introduce the candidate succinctly, aligning their career objectives with the role. Highlight relevant skills and experiences from the resume that directly match the jobs demands, using specific examples to illustrate these qualifications. Reference notable aspects of the company, such as its mission or values, that resonate with the candidates professional goals. Conclude with a strong statement of why the candidate is a good fit for the position, expressing a desire to discuss further.
Please write the cover letter in a way that directly addresses the job role and the companys characteristics, ensuring it remains concise and engaging without unnecessary embellishments. The letter should be formatted into paragraphs and should not include a greeting or signature.
## Rules:
- Provide only the text of the cover letter.
- Do not include any introductions, explanations, or additional information.
- The letter should be formatted into paragraph.
## Job Description:
```
{job_description}
```
## My resume:
```
{resume}
```
## Question:
{question}
## """
"""
resume_stuff_template = """