base_ai_client module

Base AI Client - Abstract interface for different AI providers

class base_ai_client.BaseAIClient(base_dir='.')[source]

Bases: ABC

Abstract base class for AI content generation clients

__init__(base_dir='.')[source]
abstract is_available()[source]

Check if AI client is available and configured

Return type:

bool

abstract generate_content(request)[source]

Generate AI content for the given request

Return type:

AIContentResponse

abstract generate_all_cover_letter_content(job_description, profile_content, company_name, position_title)[source]

Generate all cover letter content variables at once

Return type:

Dict[str, str]

abstract extract_company_and_position(job_description)[source]

Extract company name and position title from job description

Return type:

Dict[str, str]

get_provider_name()[source]

Get the name of the AI provider

Return type:

str

abstract get_model_name()[source]

Get the specific model name (e.g., ‘sonnet-4’, ‘3.2-3b’, ‘content’)

Return type:

str

get_client_model_folder()[source]

Get formatted folder name for client and model

Return type:

str

get_usage_stats()[source]

Get usage statistics

Return type:

Dict[str, Any]

test_content_generation()[source]

Test content generation with sample data

Return type:

bool

exception base_ai_client.AIProviderError[source]

Bases: Exception

Exception raised when AI provider is not available or configured incorrectly

exception base_ai_client.AIContentError[source]

Bases: Exception

Exception raised when AI content generation fails

Abstract Base Class

class base_ai_client.BaseAIClient(base_dir='.')[source]

Abstract base class for AI content generation clients

__init__(base_dir='.')[source]
abstract is_available()[source]

Check if AI client is available and configured

Return type:

bool

abstract generate_content(request)[source]

Generate AI content for the given request

Return type:

AIContentResponse

abstract generate_all_cover_letter_content(job_description, profile_content, company_name, position_title)[source]

Generate all cover letter content variables at once

Return type:

Dict[str, str]

abstract extract_company_and_position(job_description)[source]

Extract company name and position title from job description

Return type:

Dict[str, str]

get_provider_name()[source]

Get the name of the AI provider

Return type:

str

abstract get_model_name()[source]

Get the specific model name (e.g., ‘sonnet-4’, ‘3.2-3b’, ‘content’)

Return type:

str

get_client_model_folder()[source]

Get formatted folder name for client and model

Return type:

str

get_usage_stats()[source]

Get usage statistics

Return type:

Dict[str, Any]

test_content_generation()[source]

Test content generation with sample data

Return type:

bool

Abstract Methods

All AI client implementations must provide these methods:

Utility Methods

abstract BaseAIClient.extract_company_and_position(job_description)[source]

Extract company name and position title from job description

Return type:

Dict[str, str]

abstract BaseAIClient.generate_all_cover_letter_content(job_description, profile_content, company_name, position_title)[source]

Generate all cover letter content variables at once

Return type:

Dict[str, str]

abstract BaseAIClient.is_available()[source]

Check if AI client is available and configured

Return type:

bool

abstract BaseAIClient.get_model_name()[source]

Get the specific model name (e.g., ‘sonnet-4’, ‘3.2-3b’, ‘content’)

Return type:

str

BaseAIClient.get_client_model_folder()[source]

Get formatted folder name for client and model

Return type:

str

Exception Classes

exception base_ai_client.AIProviderError[source]

Exception raised when AI provider is not available or configured incorrectly

Implementation Guide

To create a new AI provider, inherit from BaseAIClient and implement all abstract methods:

from base_ai_client import BaseAIClient, AIProviderError

class CustomAIClient(BaseAIClient):
    def __init__(self, base_dir: str = ".", use_cache: bool = True):
        super().__init__(base_dir, use_cache)
        # Initialize your AI provider

    def is_available(self) -> bool:
        # Check if your AI provider is accessible
        return True

    def get_model_name(self) -> str:
        return "custom-model-v1"

    def generate_einstiegstext(self, job_description: str,
                             profile_content: str, company_name: str,
                             position_title: str) -> str:
        # Implement content generation
        return "Generated introduction text..."

    # Implement other required methods...

Content Generation Methods

Each content generation method follows the same pattern:

Parameters

  • job_description (str): Full text of the job posting

  • profile_content (str): Applicant’s profile information

  • company_name (str): Name of the hiring company

  • position_title (str): Title of the position being applied for

Returns

  • str: Generated German text content for the specific section

Content Sections

  • einstiegstext: Opening paragraph expressing interest

  • fachliche_passung: Technical qualifications and experience match

  • motivationstext: Personal motivation and enthusiasm

  • mehrwert: Value proposition and unique contributions

  • abschlusstext: Professional closing and call to action

Caching Behavior

The base client provides automatic caching:

  • Content is cached by hash of input parameters

  • Cache survives between application runs

  • Cache can be disabled by setting use_cache=False

  • Cache location: .cache/ai_content_cache.json

Error Handling

All methods should raise AIProviderError for provider-specific issues:

from base_ai_client import AIProviderError

def generate_content(self, ...):
    try:
        # AI provider call
        response = self.ai_api.generate(...)
        return response.text
    except Exception as e:
        raise AIProviderError(f"Failed to generate content: {e}")