Skip to content

Major Bug Fixes and Notebook Improvements - #2

Merged
allanps merged 4 commits into
mainfrom
develop
Jun 28, 2025
Merged

Major Bug Fixes and Notebook Improvements#2
allanps merged 4 commits into
mainfrom
develop

Conversation

@allanps

@allanps allanps commented Jun 28, 2025

Copy link
Copy Markdown
Owner

Major Bug Fixes and Notebook Improvements

Overview

This PR resolves critical issues in the LLMomics notebook and core functionality, making the library fully functional for end-users.

Issues Fixed

1. OpenAI API Authentication Issues

  • Problem: Error code: 401 - Incorrect API key provided due to quoted API keys
  • Solution: Fixed environment variable handling and API key validation
  • Impact: Users can now authenticate successfully with OpenAI API

2. JSON Mode Compatibility Issues

  • Problem: Error code: 400 - 'response_format' of type 'json_object' is not supported with this model
  • Solution: Added model compatibility detection and fallback JSON parsing
  • Impact: Works with all OpenAI models (GPT-4, GPT-3.5-turbo, etc.)

3. Pipeline Template Formatting Errors

  • Problem: IndexError: Replacement index 0 out of range for positional args tuple
  • Solution: Fixed empty {} placeholders in Snakemake templates by proper escaping
  • Impact: Pipeline generation now works correctly

4. End-to-End Function Parameter Mismatch

  • Problem: TypeError: generate() got an unexpected keyword argument 'dataset_ids'
  • Solution: Corrected parameter mapping between ParsedQuery and PipelineGenerator
  • Impact: Complete workflow now functions end-to-end

Files Changed

Core Functionality

  • src/llmomics/core/llm_provider.py - Enhanced JSON mode compatibility and error handling
  • src/llmomics/core/config.py - Fixed environment variable handling
  • src/llmomics/pipeline/templates.py - Fixed template placeholder escaping

Documentation & Examples

  • examples/getting_started.ipynb - Updated with corrected functions and working examples

Testing

All notebook sessions now work correctly:

  • Basic LLM interaction - API authentication and JSON parsing
  • Query parsing - Natural language processing
  • Pipeline generation - Template rendering and file creation
  • Complete end-to-end - Full workflow from query to pipeline

Impact

Before

  • Notebook sessions failed with authentication, formatting, and parameter errors
  • Users couldn't complete basic workflows
  • Multiple TypeError and IndexError exceptions

After

  • All notebook sessions work seamlessly
  • Complete end-to-end pipeline generation functional
  • Robust error handling and fallback mechanisms
  • Compatible with all supported OpenAI models

🔧 Technical Details

API Key Handling

# Before: API key wrapped in quotes causing 401 errors
OPENAI_API_KEY = "sk-proj-..."

# After: Proper environment variable handling
api_key = os.getenv("OPENAI_API_KEY", "").strip().strip('"')

JSON Mode Compatibility

# Added model detection and fallback
json_mode_models = ["gpt-4-turbo", "gpt-3.5-turbo", ...]
use_json_mode = self.model in json_mode_models

if use_json_mode:
    api_params["response_format"] = {"type": "json_object"}

Template Escaping

# Before: Empty {} caused IndexError
THREADS = config.get("threads", {})

# After: Proper escaping for Snakemake
THREADS = config.get("threads", {{}})

Ready for Production

This PR makes LLMomics fully functional for:

  • Bioinformatics researchers using the notebook interface
  • Developers integrating LLM-powered pipeline generation
  • CI/CD pipelines requiring stable API interactions

All critical user-facing issues have been resolved with comprehensive testing.

allanps added 4 commits June 28, 2025 16:39
…y issues

- Fix API key validation by properly handling environment variables in config.py
- Add fallback support for models without JSON mode in llm_provider.py
- Change default model from gpt-4 to gpt-3.5-turbo for better JSON mode support
- Implement robust JSON parsing with automatic error recovery
- Add model compatibility detection for response_format parameter

Resolves issues with API key authentication errors and model compatibility
- Fix empty {} placeholders in pipeline templates that were causing 'Replacement index 0 out of range' error
- Escape Python dictionary literals ({} -> {{}}) in config.get() calls
- Escape Snakemake placeholders ({sample} -> {{sample}}) to preserve them for Snakemake processing
- Preserve generator placeholders ({llmomics_version}, {generated_date}) for Python .format() method
- Fixes pipeline generation in notebook 'generating a complete pipeline' session

Resolves IndexError when calling PipelineGenerator.generate() with RNA-seq and ChIP-seq templates
- Fix TypeError in 'Complete end-to-end example' session
- Correct parameter mapping between ParsedQuery and PipelineGenerator.generate()
- Fix LLM analyze_query method call signature
- Add proper data structure conversion for dataset_ids and tools
- Implement fallback logic for LLM analysis results

Resolves TypeError: generate() got an unexpected keyword argument 'dataset_ids'
- Format src/llmomics/core/config.py with Black
- Format src/llmomics/core/llm_provider.py with Black
- Resolves 'Format check with black' CI failure
@allanps
allanps merged commit 8a74d2f into main Jun 28, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant