Skip to content

Commit

Permalink
added llm personalization
Browse files Browse the repository at this point in the history
  • Loading branch information
cankurttekin committed Oct 29, 2024
1 parent 1a55e09 commit 00f9692
Show file tree
Hide file tree
Showing 69 changed files with 302 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class LlmServiceImpl implements LlmService {

Expand All @@ -20,7 +24,7 @@ public class LlmServiceImpl implements LlmService {
private final OkHttpClient client = new OkHttpClient();

@Override
public String generateInterviewQuestions(String jobDescription, String jobTitle, ResumeDTO resume) {
public String generateInterviewQuestions(String jobDescription, String jobTitle, ResumeDTO resume, Map<String, Object> personalization) {
// Extract skills and work experience from ResumeDTO
String resumeSkills = String.join(", ", resume.getSkills());
StringBuilder workExperiences = new StringBuilder();
Expand All @@ -33,13 +37,20 @@ public String generateInterviewQuestions(String jobDescription, String jobTitle,
.append(experience.getDescription()).append("\n");
}

// Create the prompt
String prompt = "You are an interviewer. Generate questions for a candidate applying for a "
+ jobTitle + " position with the following job description: "
+ jobDescription + "\n\n"
+ "The candidate has the following skills: " + resumeSkills + ".\n"
+ "Work Experience:\n" + workExperiences.toString();

// Create the prompt
StringBuilder prompt = new StringBuilder("You are an interviewer. Generate questions for a candidate applying for a ")
.append(jobTitle).append(" position with the following job description: ")
.append(jobDescription).append("\n\n")
.append("The candidate has the following skills: ").append(resumeSkills).append(".\n")
.append("Work Experience:\n").append(workExperiences.toString());

// Add personalization to the prompt
if (personalization != null) {
addListToPrompt(prompt, personalization.get("tone"), "Preferred tones");
addListToPrompt(prompt, personalization.get("focusAreas"), "Focus areas");
addListToPrompt(prompt, personalization.get("questionTypes"), "Question types");
addStringToPrompt(prompt, personalization.get("experienceLevel"), "Experience level");
}
try {
// Create the JSON body
JSONObject jsonBody = new JSONObject();
Expand Down Expand Up @@ -78,6 +89,25 @@ public String generateInterviewQuestions(String jobDescription, String jobTitle,
}
}

/**
* Adds a section to the prompt for list-based personalization fields if the list is not empty.
*/
private void addListToPrompt(StringBuilder prompt, Object listObj, String label) {
if (listObj instanceof List<?> list && list.stream().allMatch(item -> item instanceof String) && !list.isEmpty()) {
String joinedList = list.stream().map(String.class::cast).collect(Collectors.joining(", "));
prompt.append(label).append(": ").append(joinedList).append(".\n");
}
}

/**
* Adds a section to the prompt for string-based personalization fields if the string is non-null and non-empty.
*/
private void addStringToPrompt(StringBuilder prompt, Object strObj, String label) {
if (strObj instanceof String str && !str.isBlank()) {
prompt.append(label).append(": ").append(str).append(".\n");
}
}

private String parseQuestions(JSONObject responseJson) {
if (responseJson.has("candidates") && !responseJson.getJSONArray("candidates").isEmpty()) {
JSONArray parts = responseJson.getJSONArray("candidates")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.kurttekin.can.job_track.domain.service;

import com.kurttekin.can.job_track.application.dto.ResumeDTO;
import com.kurttekin.can.job_track.domain.model.resume.Resume;

import java.util.Map;

public interface LlmService {
String generateInterviewQuestions(String jobDescription, String jobTitle, ResumeDTO resume);
String generateInterviewQuestions(String jobDescription, String jobTitle, ResumeDTO resume, Map<String, Object> personalization);
String generateQuizQuestions(String jobDescription, String jobTitle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ public ResponseEntity<Map<String, Object>> generateInterviewQuestions(@RequestBo
String jobTitle = (String) payload.get("jobTitle");
ResumeDTO resume = parseResumeFromPayload(payload); // Update method to parse ResumeDTO

// Retrieve personalization preferences
Map<String, Object> personalization = (Map<String, Object>) payload.get("personalization");


System.out.println("Received request for generating interview questions:");
System.out.println("Job Title: " + jobTitle);
System.out.println("Resume: " + resume);
System.out.println("Personalization: " + personalization);

// Generate the interview questions
String questions = llmService.generateInterviewQuestions(jobDescription, jobTitle, resume);
//String questions = llmService.generateInterviewQuestions(jobDescription, jobTitle, resume);
String questions = llmService.generateInterviewQuestions(jobDescription, jobTitle, resume, personalization);

// Split the questions string into a list
List<String> questionList = Arrays.stream(questions.split("\n"))
Expand Down
2 changes: 1 addition & 1 deletion frontend/node_modules/.cache/.eslintcache

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 00f9692

Please sign in to comment.