Skip to content

refactor: instructor_llm_factory merge with llm_factory - #2382

Merged
anistark merged 2 commits into
vibrantlabsai:mainfrom
anistark:refactor/llm-factory
Oct 25, 2025
Merged

refactor: instructor_llm_factory merge with llm_factory#2382
anistark merged 2 commits into
vibrantlabsai:mainfrom
anistark:refactor/llm-factory

Conversation

@anistark

@anistark anistark commented Oct 24, 2025

Copy link
Copy Markdown
Member

Consolidates dual LLM factories into a single, explicit llm_factory() API. Removes instructor_llm_factory() entirely.

Changes

Core Changes

  • Unified llm_factory(): Single factory supporting multiple LLM providers (OpenAI, Anthropic, Cohere, Google, LiteLLM)

    • Requires explicit parameters: model, provider, client
    • Returns: InstructorBaseRagasLLM (structured outputs only)
    • Clear error messages for missing parameters
  • Removed instructor_llm_factory(): Deleted entirely (~97 lines)

    • Functionality merged into unified llm_factory()
    • Removed from public exports

API Change

Before:

from ragas.llms import instructor_llm_factory
llm = instructor_llm_factory("openai", model="gpt-4o", client=client)

After:

from ragas.llms import llm_factory
llm = llm_factory("gpt-4o", client=client)  # provider defaults to "openai"

Migration for Users

# Old code
llm = llm_factory("gpt-4o-mini")

# Error message:
# ValueError: llm_factory() requires a client instance.
# Text-only mode has been removed.

# To migrate:
from openai import OpenAI
client = OpenAI(api_key='...')
llm = llm_factory('gpt-4o-mini', client=client)

Notes

This is a breaking change for the public API, but justified because:

  1. Old text-only factory was already deprecated
  2. All new metrics require structured outputs (InstructorLLM)
  3. Unified API is simpler and more maintainable
  4. Clear error messages guide easy migration

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. size:XL This PR changes 500-999 lines, ignoring generated files. labels Oct 24, 2025
@anistark
anistark force-pushed the refactor/llm-factory branch from b79406a to e5985d3 Compare October 24, 2025 13:03
@anistark anistark changed the title refactor: instructor_llm_factory merge with llm_factory refactor: instructor_llm_factory merge with llm_factory Oct 24, 2025
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Oct 24, 2025
@anistark
anistark merged commit 34b4733 into vibrantlabsai:main Oct 25, 2025
9 checks passed
@anistark
anistark deleted the refactor/llm-factory branch October 25, 2025 16:21
anistark added a commit that referenced this pull request Nov 17, 2025
Consolidates dual LLM factories into a single, explicit `llm_factory()`
API. Removes `instructor_llm_factory()` entirely.

- Unified `llm_factory()`: Single factory supporting multiple LLM
providers (OpenAI, Anthropic, Cohere, Google, LiteLLM)
  - Requires explicit parameters: `model`, `provider`, `client`
  - Returns: `InstructorBaseRagasLLM` (structured outputs only)
  - Clear error messages for missing parameters

- Removed `instructor_llm_factory()`: Deleted entirely (~97 lines)
  - Functionality merged into unified `llm_factory()`
  - Removed from public exports

**Before:**
```py
from ragas.llms import instructor_llm_factory
llm = instructor_llm_factory("openai", model="gpt-4o", client=client)
```

**After:**
```py
from ragas.llms import llm_factory
llm = llm_factory("gpt-4o", client=client)  # provider defaults to "openai"
```

```py
llm = llm_factory("gpt-4o-mini")

from openai import OpenAI
client = OpenAI(api_key='...')
llm = llm_factory('gpt-4o-mini', client=client)
```

This is a **breaking change** for the public API, but justified because:
1. Old text-only factory was already deprecated
2. All new metrics require structured outputs (InstructorLLM)
3. Unified API is simpler and more maintainable
4. Clear error messages guide easy migration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant