### Install CV Parser Gem Source: https://github.com/gysmuller/cv-parser/blob/main/README.md Instructions for installing the CV Parser Ruby gem using a Gemfile or direct installation via the command line. ```ruby gem 'cv-parser' ``` ```bash $ bundle install ``` ```bash $ gem install cv-parser ``` -------------------------------- ### Simple CV Parser Faker Provider Usage in Ruby Source: https://github.com/gysmuller/cv-parser/blob/main/README.md This Ruby snippet provides a straightforward example of using the `CvParser` Faker provider. It shows how to configure the parser to use `:faker`, then instantiate and use the `Extractor` as usual. The Faker provider will generate realistic-looking, structured data based on the provided output schema, ignoring the actual file path, which is ideal for development and quick demonstrations. ```ruby # Configure with Faker provider CvParser.configure do |config| config.provider = :faker end # Use the extractor as normal extractor = CvParser::Extractor.new result = extractor.extract( file_path: "path/to/resume.pdf", # Path will be ignored by faker output_schema: schema # Using the JSON Schema format defined above ) # Faker will generate structured data based on your schema puts result.inspect ``` -------------------------------- ### Basic CV Parser Command-Line Usage Source: https://github.com/gysmuller/cv-parser/blob/main/README.md This Bash snippet illustrates the fundamental command-line interface (CLI) commands for `cv-parser`. It shows how to parse a PDF, specify a provider (e.g., Anthropic), format output (e.g., YAML) to a file, use a custom schema, and access the help documentation. ```bash cv-parser path/to/resume.pdf cv-parser --provider anthropic path/to/resume.pdf cv-parser --format yaml --output result.yaml path/to/resume.pdf cv-parser --schema custom-schema.json path/to/resume.pdf cv-parser --help ``` -------------------------------- ### Set Up CV Parser Faker Provider for RSpec Tests Source: https://github.com/gysmuller/cv-parser/blob/main/README.md This Ruby RSpec test snippet demonstrates how to integrate the `CvParser` Faker provider into your test suite. It shows how to configure `CvParser` to use the `:faker` provider before tests, define a JSON schema for data generation, and then assert on the structure and content of the fake data returned by the extractor, ensuring consistent and fast testing without actual API calls. ```ruby # spec/your_resume_processor_spec.rb require 'spec_helper' RSpec.describe YourResumeProcessor do # Define a JSON Schema format schema for testing let(:test_schema) do { type: "json_schema", name: "cv_parsing_test", description: "Test schema for CV parsing", properties: { personal_info: { type: "object", description: "Personal information", properties: { name: { type: "string", description: "Full name" }, email: { type: "string", description: "Email address" } }, required: %w[name email] }, skills: { type: "array", description: "List of skills", items: { type: "string", description: "A skill" } } }, required: %w[personal_info skills] } end before do # Configure CV Parser to use the faker provider CvParser.configure do |config| config.provider = :faker end end after do # Reset configuration after tests CvParser.reset end it "processes a resume and extracts relevant fields" do processor = YourResumeProcessor.new result = processor.process_resume("spec/fixtures/sample_resume.pdf", test_schema) # The faker provider will return consistent test data expect(result.personal_info.name).to eq("John Doe") expect(result.personal_info.email).to eq("john.doe@example.com") expect(result.skills).to be_an(Array) expect(result.skills).not_to be_empty end end ``` -------------------------------- ### Configure CV Parser CLI with Environment Variables Source: https://github.com/gysmuller/cv-parser/blob/main/README.md This Bash snippet demonstrates how to set environment variables to configure the `cv-parser` CLI. It shows how to export API keys for OpenAI and Anthropic, and how to set the default provider and a generic API key, allowing for secure and flexible configuration without hardcoding credentials. ```bash export OPENAI_API_KEY=your-openai-key export ANTHROPIC_API_KEY=your-anthropic-key export CV_PARSER_PROVIDER=openai export CV_PARSER_API_KEY=your-api-key cv-parser resume.pdf ``` -------------------------------- ### Configure CV Parser with LLM Providers (OpenAI, Anthropic, Faker) Source: https://github.com/gysmuller/cv-parser/blob/main/README.md Configure the CV Parser gem to use different LLM providers such as OpenAI, Anthropic, or Faker for testing. Each configuration requires an API key (except Faker) and a specified model, along with an output schema. ```ruby require 'cv_parser' # OpenAI CvParser.configure do |config| config.provider = :openai config.api_key = ENV['OPENAI_API_KEY'] config.model = 'gpt-4.1-mini' config.output_schema = schema end # Anthropic CvParser.configure do |config| config.provider = :anthropic config.api_key = ENV['ANTHROPIC_API_KEY'] config.model = 'claude-3-sonnet-20240229' config.output_schema = schema end # Faker (for testing/development) CvParser.configure do |config| config.provider = :faker config.output_schema = schema end ``` -------------------------------- ### Configure Advanced CV Parser Options in Ruby Source: https://github.com/gysmuller/cv-parser/blob/main/README.md This Ruby snippet details how to customize `CvParser` behavior using the `configure` block. It covers setting the LLM provider, API key, model, timeouts, max retries, provider-specific options (like OpenAI organization ID), custom prompts, output schema, max tokens, and temperature for fine-grained control over the parsing process. ```ruby CvParser.configure do |config| # Configure OpenAI with organization ID config.provider = :openai config.api_key = ENV['OPENAI_API_KEY'] config.model = 'gpt-4.1-mini' # Set timeout for file uploads (important for larger files) config.timeout = 120 # TODO - not yet implemented config.max_retries = 2 # TODO - not yet implemented # Provider-specific options config.provider_options[:organization_id] = ENV['OPENAI_ORG_ID'] # You can also set custom prompts for the LLM: config.prompt = "Extract the following fields from the CV..." config.system_prompt = "You are a CV parsing assistant." # Set the output schema (JSON Schema format) config.output_schema = schema # Set the max tokens and temperature config.max_tokens = 4000 config.temperature = 0.1 end ``` -------------------------------- ### Extract Structured Data from a CV File Source: https://github.com/gysmuller/cv-parser/blob/main/README.md Instantiate the `CvParser::Extractor` and use its `extract` method to parse a CV file (e.g., PDF), retrieving structured data based on the configured or provided output schema. The extracted data can then be accessed like a Ruby hash. ```ruby extractor = CvParser::Extractor.new result = extractor.extract( file_path: "path/to/resume.pdf" ) puts "Name: #{result['personal_info']['name']}" puts "Email: #{result['personal_info']['email']}" result['skills'].each { |skill| puts "- #{skill}" } ``` -------------------------------- ### Handle CV Parser Extraction Errors in Ruby Source: https://github.com/gysmuller/cv-parser/blob/main/README.md This Ruby snippet demonstrates robust error handling for the `CvParser::Extractor`. It catches specific exceptions like `FileNotFoundError`, `FileNotReadableError`, `ParseError`, `APIError`, and `ConfigurationError`, providing distinct messages for each type of issue during the CV extraction process. ```ruby begin result = extractor.extract( file_path: "path/to/resume.pdf" ) rescue CvParser::FileNotFoundError, CvParser::FileNotReadableError => e puts "File error: #{e.message}" rescue CvParser::ParseError => e puts "Error parsing the response: #{e.message}" rescue CvParser::APIError => e puts "LLM API error: #{e.message}" rescue CvParser::ConfigurationError => e puts "Configuration error: #{e.message}" end ``` -------------------------------- ### Define and Apply Custom JSON Output Schema for CV Data Source: https://github.com/gysmuller/cv-parser/blob/main/README.md Define a custom JSON Schema in Ruby to specify the desired structure for extracted CV data, including personal information, experience, education, and skills. This schema can be applied globally via configuration or overridden per extraction call. ```ruby schema = { type: "json_schema", name: "cv_parsing", description: "Schema for a CV or resume document", properties: { personal_info: { type: "object", description: "Personal and contact information for the candidate", properties: { name: { type: "string", description: "Full name of the individual" }, email: { type: "string", description: "Email address of the individual" }, phone: { type: "string", description: "Phone number of the individual" }, location: { type: "string", description: "Geographic location or city of residence" } }, required: %w[name email] }, experience: { type: "array", description: "List of professional experience entries", items: { type: "object", description: "A professional experience entry", properties: { company: { type: "string", description: "Name of the company or organization" }, position: { type: "string", description: "Job title or position held" }, start_date: { type: "string", description: "Start date of employment (e.g. '2020-01')" }, end_date: { type: "string", description: "End date of employment or 'present'" }, description: { type: "string", description: "Description of responsibilities and achievements" } }, required: %w[company position start_date] } }, education: { type: "array", description: "List of educational qualifications", items: { type: "object", description: "An education entry", properties: { institution: { type: "string", description: "Name of the educational institution" }, degree: { type: "string", description: "Degree or certification received" }, field: { type: "string", description: "Field of study" }, graduation_date: { type: "string", description: "Graduation date (e.g. '2019-06')" } }, required: %w[institution degree] } }, skills: { type: "array", description: "List of relevant skills", items: { type: "string", description: "A single skill" } } }, required: %w[personal_info experience education skills] } ``` ```ruby CvParser.configure do |config| config.output_schema = schema end ``` ```ruby extractor = CvParser::Extractor.new extractor.extract( output_schema: schema ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.