Skip to content

Conversation

aksg87
Copy link
Collaborator

@aksg87 aksg87 commented Aug 11, 2025

Description

Fixes #110 - Local Ollama models were incorrectly requiring API keys because provider patterns weren't registered before model resolution.

Root cause: PR #97's lazy loading meant providers weren't imported when registry.resolve() was called, causing fallback to cloud providers.

Bug fix

Solution

  • Load providers before pattern matching in factory.create_model()
  • Skip loading when provider is explicitly specified (optimization)
  • Remove redundant eager imports that defeated lazy loading

Changes

  1. Added load_builtins_once() to ensure providers are registered before resolution
  2. Optimized to only load when pattern matching is needed
  3. Removed duplicate module-level imports in providers/__init__.py
  4. Added regression test for canonical Ollama models

How Has This Been Tested?

pytest tests/factory_test.py -v
# 18 passed

# New test covers: llama3, gemma2:2b, mistral:7b, qwen3:0.6b
pytest tests/factory_test.py::FactoryTest::test_ollama_models_select_without_api_keys -v

Checklist:

  • I have read and acknowledged Google's Open Source Code of conduct.
  • I have read the Contributing page, and I either signed the Google Individual CLA or am covered by my company's Corporate CLA.
  • I have discussed my proposed solution with code owners in the linked issue(s) and we have agreed upon the general approach.
  • I have made any needed documentation changes, or noted in the linked issue(s) that documentation elsewhere needs updating.
  • I have added tests, or I have ensured existing tests cover the changes
  • I have followed Google's Python Style Guide and ran pylint over the affected code.

@github-actions github-actions bot added the size/S Pull request with 50-150 lines changed label Aug 11, 2025
@aksg87 aksg87 force-pushed the fix-ollama-api-key-issue-110 branch from d6a2e68 to 90191b8 Compare August 11, 2025 00:27
Ensure providers are loaded before pattern matching to prevent API key
errors when using local models. Optimize to skip loading when provider
is explicitly specified.
@aksg87 aksg87 force-pushed the fix-ollama-api-key-issue-110 branch from 90191b8 to ecc76d1 Compare August 11, 2025 00:47
@aksg87 aksg87 self-assigned this Aug 11, 2025
@aksg87 aksg87 marked this pull request as ready for review August 11, 2025 00:52
@aksg87 aksg87 merged commit 1a25621 into main Aug 11, 2025
13 checks passed
@aksg87 aksg87 deleted the fix-ollama-api-key-issue-110 branch August 11, 2025 02:46
aksg87 added a commit that referenced this pull request Aug 21, 2025
Ensure providers are loaded before pattern matching to prevent API key
errors when using local models. Optimize to skip loading when provider
is explicitly specified.
sinnaj pushed a commit to sinnaj/langextract that referenced this pull request Sep 3, 2025
Ensure providers are loaded before pattern matching to prevent API key
errors when using local models. Optimize to skip loading when provider
is explicitly specified.
aksg87 added a commit that referenced this pull request Sep 12, 2025
Ensure providers are loaded before pattern matching to prevent API key
errors when using local models. Optimize to skip loading when provider
is explicitly specified.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Pull request with 50-150 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] langextract still asking for API key on local Ollama API setup

1 participant