Client for the Recommender System API
npm install @exceleratedk/recommender-api-clientA modern TypeScript/JavaScript client for the internal Recommender System API.
---
``bash`
npm install @exceleratedk/recommender-api-client
---
`typescript
import { RecommenderAPI } from 'recommender-api-client';
const api = new RecommenderAPI({
baseURL: 'http://localhost:8000',
token: 'YOUR_API_TOKEN',
});
// Get job recommendations for a candidate
const jobResponse = await api.getJobRecommendations({ candidateId: 'candidate123' });
console.log('Job recommendations:', jobResponse.recommendations);
console.log('Suggestions:', jobResponse.suggestions);
// Get candidate recommendations for a job
const candidateResponse = await api.getCandidateRecommendations({ jobId: 'job456', limit: 10 });
console.log('Candidate recommendations:', candidateResponse.recommendations);
console.log('Suggestions:', candidateResponse.suggestions);
`
---
#### new RecommenderAPI(config){ baseURL: string; token: string; }
- config ():baseURL
- : The base URL of the API (e.g., 'http://localhost:8000')token
- : Bearer token for authentication
#### getJobRecommendations(config): Promise{ candidateId: string; limit?: number; }
- config ():candidateId
- : The candidate's unique ID (required)limit
- : Number of recommendations to return (default: 5)Promise
- Returns: with recommendations and suggestions
#### getCandidateRecommendations(config): Promise{ jobId: string; limit?: number; }
- config ():jobId
- : The job's unique ID (required)limit
- : Number of recommendations to return (default: 5)Promise
- Returns: with recommendations and suggestions
---
`typescript`
export interface RecommenderResponse {
recommendations: JobRecommendation[] | CandidateRecommendation[];
suggestions: string[];
}
`typescript
export interface JobRecommendation {
jobId: string;
score?: number;
explanation?: RecommendationExplanation;
}
export interface CandidateRecommendation {
candidateId: string;
score?: number;
explanation?: RecommendationExplanation;
}
`
`typescript
export interface ExplanationFactor {
factor_type: string; // e.g., "skill_match", "industry_match", "interest_match"
factor_name: string; // e.g., "Python", "Technology", "Machine Learning"
factor_value: number; // Contribution score
factor_description: string; // Human-readable description
factor_weight: number; // Weight of the factor
}
export interface RecommendationExplanation {
recommendation_id: string; // ID of the recommended item
explanation_type: string; // Type of explanation
factors: ExplanationFactor[]; // Contributing factors
total_score: number; // Overall recommendation score
explanation_summary: string; // Human-readable summary
missing_features: Record
}
`
`typescript
export interface RecommenderAPIConfig {
baseURL: string;
token: string;
}
export interface JobRecommendationConfig {
candidateId: string;
limit?: number;
}
export interface CandidateRecommendationConfig {
jobId: string;
limit?: number;
}
`
---
The API now returns complete responses with both recommendations and suggestions. Here's how to work with them:
`typescript
// Get job recommendations with explanations and suggestions
const jobResponse = await api.getJobRecommendations({
candidateId: 'candidate123',
limit: 3
});
// Access recommendations
jobResponse.recommendations.forEach(recommendation => {
console.log(Job: ${recommendation.jobId}, Score: ${recommendation.score});Summary: ${recommendation.explanation.explanation_summary}
if (recommendation.explanation) {
console.log();Total Score: ${recommendation.explanation.total_score}
console.log();- ${factor.factor_name}: ${factor.factor_description} (${factor.factor_value})
// List contributing factors
recommendation.explanation.factors.forEach(factor => {
console.log();
});
}
});
// Access suggestions for improvement
console.log('Suggestions:', jobResponse.suggestions);
`
`typescript`
{
recommendations: [
{
jobId: "job_123",
score: 6.03,
explanation: {
recommendation_id: "job_123",
explanation_type: "path_based",
total_score: 6.03,
explanation_summary: "Strong match based on: Core Interest Match (1.0), Core Skill Match (1.0), Content Similarity (0.2)",
factors: [
{
factor_type: "interests_core_positive",
factor_name: "Core Interest Match",
factor_value: 1,
factor_description: "Essential interest requirements that align (strength: 1.0, impact: 37.10)",
factor_weight: 37.1
},
{
factor_type: "skills_core_positive",
factor_name: "Core Skill Match",
factor_value: 1,
factor_description: "Essential skill requirements that align (strength: 1.0, impact: 6.31)",
factor_weight: 6.31
}
],
missing_features: []
}
}
],
suggestions: [
"Add more interests to your profile to improve job matching. Include both professional and personal interests."
]
}
---
`bash``
npm test
---