Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] trulens-legacy and trulens-api #1307

Draft
wants to merge 219 commits into
base: main
Choose a base branch
from

Conversation

sfc-gh-pmardziel
Copy link
Contributor

@sfc-gh-pmardziel sfc-gh-pmardziel commented Jul 26, 2024

This PR is being split into multiple ones. Keep this open until the splits are merged:

Description

Creates trulens-legacy package:

  1. Preserved trulens_eval.* names defined in __init__.py files for backwards compatibility to be deprecated later. Until then, a warning is issued of an old module is imported or a class or function imported via the old name is invoked. This is tested by new "static" tests in test_deprecation.py.

Example warning when importing from trulens_eval

from trulens_eval import Tru
DeprecationWarning: The `trulens_eval` module is deprecated. See https://trulens.org/docs/migration-guide for instructions on migrating to `trulens.*` modules.

Example warning when using something imported from trulens_eval:

Tru(...)
DeprecationWarning: Class `Tru` has moved:
    New import: `from trulens.core.tru import Tru`
 See https://trulens.org/docs/migration-guide for instructions on migrating to `trulens` modules.
  1. Brought back some utilities for optional imports which will not be needed after the package is removed in the future. Optional imports are used to preserve how trulens_eval behaved with respect to optional imports in the past. However, in many cases, the packages that need to be installed have been changed to the optional trulens-* packages instead of what was is now these packages' dependencies.

  2. Added versioning and deprecation policies doc POLICIES.md and included it in the contributing nav item group.

  3. (TODO, waiting for another PR for testing this). Preserve other trulens_eval names that are public enough that they need to have aliases for some time before removal.

  4. Created trulens-api package containing the Interactive API. This provides the trulens.api module and submodules for a public, package-independent, access to trulens components like Tru:

from trulens.api import Tru

Some lookups are dynamic into the various trulens-* packages and either install the packages automatically or give the user instructions on installing additional packages if appropriate. The installation is the default but can be disabled. For example:

from trulens.api.providers import Cortex

If trulens-providers-cortex is installed, the above will work. If it is not installed, an instruction is issued alongside the import error:

RuntimeError: Package trulens-providers-cortex is not installed. Enable automatic installation by calling `trulens.api.set_no_install(False)` or install it manually with pip: 
    ```bash
    pip install 'trulens-providers-cortex'
    ```

The interactive API also gives better import errors if someone tries to import something that does not exist showing information of what is actually contained in the api modules and whether the optional packages that they need are installed:

from trulens.api import Blah

Output:

...
ImportError: Module trulens.api has no attribute Blah.
Module 'trulens.api' from '/Users/pmardziel/repos/truera/trulens/src/api/trulens/api/__init__.py contains:
provider: 
  Bedrock	[trulens-providers-bedrock]	[1.0.1a0]
  Cortex	[trulens-providers-cortex]	[not installed]
  Huggingface	[trulens-providers-huggingface]	[1.0.1a0]
  HuggingfaceLocal	[trulens-providers-huggingface]	[1.0.1a0]
  Langchain	[trulens-providers-langchain]	[1.0.1a0]
  LiteLLM	[trulens-providers-litellm]	[1.0.1a0]
  OpenAI	[trulens-providers-openai]	[1.0.1a0]
  AzureOpenAI	[trulens-providers-openai]	[1.0.1a0]
recorder: 
  TruBasicApp	[trulens-core]	[1.0.1a0]
  TruCustomApp	[trulens-core]	[1.0.1a0]
  TruVirtual	[trulens-core]	[1.0.1a0]
  TruChain	[trulens-instrument-langchain]	[1.0.1a0]
  TruLlama	[trulens-instrument-llamaindex]	[1.0.1a0]
  TruRails	[trulens-instrument-nemo]	[not installed]
class: 
  Tru	[trulens-core]	[1.0.1a0]
  TP	[trulens-core]	[1.0.1a0]
  Feedback	[trulens-core]	[1.0.1a0]
  Provider	[trulens-core]	[1.0.1a0]
enum: 
  FeedbackMode	[trulens-core]	[1.0.1a0]
  FeedbackResultStatus	[trulens-core]	[1.0.1a0]
  FeedbackOnMissingParameters	[trulens-core]	[1.0.1a0]
  FeedbackCombinations	[trulens-core]	[1.0.1a0]
utility: 
  Select	[trulens-core]	[1.0.1a0]
  set_no_install	[trulens-api]	[1.0.1a0]
schema: 
  FeedbackResult	[trulens-core]	[1.0.1a0]
  FeedbackCall	[trulens-core]	[1.0.1a0]
  FeedbackDefinition	[trulens-core]	[1.0.1a0]

Importing from this module will install the required package. You can disable this by calling `trulens.api.set_no_install()`.
  1. Added a main API reference index page that describes the Interactive API and the behaviour summarized here.

Other details good to know for developers

Please include any other details of this change useful for TruLens developers.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to
    not work as expected)
  • This change requires a documentation update

Base automatically changed from corey/package to main August 9, 2024 18:02
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Aug 9, 2024
@sfc-gh-pdharmana
Copy link
Contributor

sfc-gh-pdharmana commented Aug 14, 2024

@sfc-gh-pmardziel can you please remove all the format changes in this PR and just include backwards compat. Also change the title of the PR?

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Aug 14, 2024
@sfc-gh-pmardziel sfc-gh-pmardziel changed the title legacy aliases trulens-legacy and trulens-api Aug 14, 2024
Copy link
Contributor

@sfc-gh-dkurokawa sfc-gh-dkurokawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't check:

  1. The poetry.lock files as these are auto-generated.
  2. Can you spin the trulens.api stuff into a separate PR that's not as urgent.
  3. In the future when you do a mass renaming can you put it in its own PR. That way the reviewers don't have to look at it as it's just a simple find and replace.

Makefile Show resolved Hide resolved
Makefile Show resolved Hide resolved
src/legacy/trulens_eval/utils/__init__.py Show resolved Hide resolved
src/feedback/trulens/feedback/feedback.py Outdated Show resolved Hide resolved
POLICIES.md Outdated Show resolved Hide resolved
src/feedback/trulens/feedback/embeddings.py Show resolved Hide resolved
src/feedback/trulens/feedback/groundtruth.py Outdated Show resolved Hide resolved
src/legacy/pyproject.toml Outdated Show resolved Hide resolved
src/legacy/pyproject.toml Outdated Show resolved Hide resolved
@sfc-gh-pmardziel sfc-gh-pmardziel marked this pull request as draft August 19, 2024 22:50
@sfc-gh-pmardziel sfc-gh-pmardziel changed the title trulens-legacy and trulens-api [DRAFT] trulens-legacy and trulens-api Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants