feat: implement YAML-based configuration, .env support, and customizable prompt templates for AI analysis

This commit is contained in:
2026-08-22 10:17:38 -07:00
parent 7ec91f384f
commit 0de312edbd
30 changed files with 895 additions and 211 deletions
+50 -19
View File
@@ -12,38 +12,48 @@ import (
)
type DeepSeekAnalyzer struct {
apiKey string
baseURL string
client *http.Client
apiKey string
baseURL string
systemPrompt string
userPromptTemplate string
client *http.Client
}
func NewDeepSeekAnalyzer(apiKey, baseURL string) *DeepSeekAnalyzer {
func NewDeepSeekAnalyzer(apiKey, baseURL, systemPrompt, userPromptTemplate string) *DeepSeekAnalyzer {
if baseURL == "" {
baseURL = "https://api.deepseek.com"
}
return &DeepSeekAnalyzer{
apiKey: apiKey,
baseURL: strings.TrimRight(baseURL, "/"),
client: &http.Client{Timeout: 30 * time.Second},
apiKey: apiKey,
baseURL: strings.TrimRight(baseURL, "/"),
systemPrompt: systemPrompt,
userPromptTemplate: userPromptTemplate,
client: &http.Client{Timeout: 30 * time.Second},
}
}
func (d *DeepSeekAnalyzer) 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.
func (d *DeepSeekAnalyzer) buildUserPrompt(jobTitle, rawContent string) string {
if d.userPromptTemplate == "" {
return fmt.Sprintf("Analyze the following job description for candidate Pengzhan Hao.\n\nJob Title: %s\n\nJob Description:\n%s\n\nProvide the structured evaluation adhering to the JSON schema.", jobTitle, rawContent)
}
res := strings.ReplaceAll(d.userPromptTemplate, "{{.JobTitle}}", jobTitle)
res = strings.ReplaceAll(res, "{{.JobContent}}", rawContent)
return res
}
Job Title: %s
Job Content:
%s`, jobTitle, jobTitle, rawContent)
func (d *DeepSeekAnalyzer) AnalyzeJD(ctx context.Context, jobTitle, rawContent string) (*AnalysisOutput, error) {
sysPrompt := d.systemPrompt
if sysPrompt == "" {
sysPrompt = "You are an expert technical resume screener. You MUST respond with a valid JSON object matching {\"ai_score\": 80.0, \"is_qualified\": true, \"summary\": \"...\", \"matched_highlights\": [...], \"missing_highlights\": [...], \"tailoring_suggestions\": [...]}."
}
userPrompt := d.buildUserPrompt(jobTitle, rawContent)
reqBody := map[string]interface{}{
"model": "deepseek-chat",
"messages": []map[string]string{
{"role": "system", "content": "You are a professional hiring assistant. You MUST respond ONLY with valid JSON matching {\"matched_highlights\": [...], \"missing_highlights\": [...], \"tailoring_suggestions\": [...]}."},
{"role": "user", "content": prompt},
{"role": "system", "content": sysPrompt},
{"role": "user", "content": userPrompt},
},
"response_format": map[string]string{
"type": "json_object",
@@ -99,7 +109,28 @@ Job Content:
var output AnalysisOutput
if err := json.Unmarshal([]byte(rawJSON), &output); err != nil {
return nil, fmt.Errorf("failed to parse DeepSeek JSON output: %w", err)
return nil, fmt.Errorf("failed to parse DeepSeek JSON output: %w (content: %s)", err, rawJSON)
}
// Sanitize output bounds
if output.AIScore < 0 {
output.AIScore = 0
} else if output.AIScore > 100 {
output.AIScore = 100
}
if output.AIScore >= 60.0 {
output.IsQualified = true
}
if output.MatchedHighlights == nil {
output.MatchedHighlights = []string{}
}
if output.MissingHighlights == nil {
output.MissingHighlights = []string{}
}
if output.TailoringSuggestions == nil {
output.TailoringSuggestions = []string{}
}
return &output, nil