feat: implement YAML-based configuration, .env support, and customizable prompt templates for AI analysis
This commit is contained in:
+36
-17
@@ -7,40 +7,49 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type GeminiAnalyzer struct {
|
||||
apiKey string
|
||||
client *http.Client
|
||||
apiKey string
|
||||
systemPrompt string
|
||||
userPromptTemplate string
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
func NewGeminiAnalyzer(apiKey string) *GeminiAnalyzer {
|
||||
func NewGeminiAnalyzer(apiKey, systemPrompt, userPromptTemplate string) *GeminiAnalyzer {
|
||||
return &GeminiAnalyzer{
|
||||
apiKey: apiKey,
|
||||
client: &http.Client{Timeout: 30 * time.Second},
|
||||
apiKey: apiKey,
|
||||
systemPrompt: systemPrompt,
|
||||
userPromptTemplate: userPromptTemplate,
|
||||
client: &http.Client{Timeout: 30 * time.Second},
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GeminiAnalyzer) buildUserPrompt(jobTitle, rawContent string) string {
|
||||
if g.userPromptTemplate == "" {
|
||||
return fmt.Sprintf("Analyze the following job description for candidate Pengzhan Hao.\n\nJob Title: %s\n\nJob Content:\n%s\n\nRespond with structured JSON.", jobTitle, rawContent)
|
||||
}
|
||||
res := strings.ReplaceAll(g.userPromptTemplate, "{{.JobTitle}}", jobTitle)
|
||||
res = strings.ReplaceAll(res, "{{.JobContent}}", rawContent)
|
||||
return res
|
||||
}
|
||||
|
||||
func (g *GeminiAnalyzer) AnalyzeJD(ctx context.Context, jobTitle, rawContent string) (*AnalysisOutput, error) {
|
||||
prompt := fmt.Sprintf(`You are an expert technical resume screener. Analyze the following job description for the title "%s".
|
||||
Provide a structured JSON output with 3 fields:
|
||||
- "matched_highlights": list of 3-5 core technical skills/requirements matched (e.g. ["Go (Golang)", "Microservices", "REST APIs"]).
|
||||
- "missing_highlights": list of 1-3 missing skills, experience gaps, or extra requirements (e.g. ["10+ yrs experience", "Kubernetes administration"]).
|
||||
- "tailoring_suggestions": list of 2-3 specific action points for tailoring a resume to this JD.
|
||||
sysPrompt := g.systemPrompt
|
||||
if sysPrompt == "" {
|
||||
sysPrompt = "You are an expert technical resume screener. Respond STRICTLY with valid JSON matching {\"ai_score\": 85.0, \"is_qualified\": true, \"summary\": \"...\", \"matched_highlights\": [...], \"missing_highlights\": [...], \"tailoring_suggestions\": [...]}."
|
||||
}
|
||||
|
||||
Job Title: %s
|
||||
Job Content:
|
||||
%s
|
||||
|
||||
Respond STRICTLY with valid JSON matching the format:
|
||||
{"matched_highlights": [...], "missing_highlights": [...], "tailoring_suggestions": [...]}`, jobTitle, jobTitle, rawContent)
|
||||
userPrompt := g.buildUserPrompt(jobTitle, rawContent)
|
||||
fullPrompt := fmt.Sprintf("%s\n\n%s", sysPrompt, userPrompt)
|
||||
|
||||
reqBody := map[string]interface{}{
|
||||
"contents": []map[string]interface{}{
|
||||
{
|
||||
"parts": []map[string]string{
|
||||
{"text": prompt},
|
||||
{"text": fullPrompt},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -102,5 +111,15 @@ Respond STRICTLY with valid JSON matching the format:
|
||||
return nil, fmt.Errorf("failed to parse Gemini JSON output: %w", err)
|
||||
}
|
||||
|
||||
if output.AIScore < 0 {
|
||||
output.AIScore = 0
|
||||
} else if output.AIScore > 100 {
|
||||
output.AIScore = 100
|
||||
}
|
||||
|
||||
if output.AIScore >= 60.0 {
|
||||
output.IsQualified = true
|
||||
}
|
||||
|
||||
return &output, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user