Repository: truera/trulens
Issue: [BUG] TypeError: Type parameter +R without a default follows type parameter with a default
Root cause: External Dependency Breakage

**Bug Description**
When attempting to import modules from trulens_eval, a TypeError is raised. The error occurs in a chain of imports, ultimately failing in the langsmith library.

**To Reproduce**
from openai import OpenAI
from trulens_eval import Feedback, OpenAI as fOpenAI, Tru, TruBasicApp

**Expected behavior**
The imports should succeed without any errors.

**Relevant Logs/Tracebacks**
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[6], line 3
      1 # Imports
      2 from openai import OpenAI
----> 3 from trulens_eval import Feedback, OpenAI as fOpenAI, Tru, TruBasicApp
      4 import os
      6 # Set OpenAI API key

File /opt/conda/lib/python3.10/site-packages/trulens_eval/__init__.py:22
     18 check_imports()
     20 import sys
---> 22 from trulens_eval import tru as mod_tru
     23 from trulens_eval import tru_basic_app as mod_tru_basic_app
     24 from trulens_eval import tru_chain as mod_tru_chain

File /opt/conda/lib/python3.10/site-packages/trulens_eval/tru.py:29
     26 from typing_extensions import Annotated
     27 from typing_extensions import Doc
---> 29 from trulens_eval.database import sqlalchemy
     30 from trulens_eval.database.base import DB
     31 from trulens_eval.database.exceptions import DatabaseVersionException

File /opt/conda/lib/python3.10/site-packages/trulens_eval/database/sqlalchemy.py:22
     19 from sqlalchemy.orm import sessionmaker
     20 from sqlalchemy.sql import text as sql_text
---> 22 from trulens_eval import app as mod_app
     23 from trulens_eval.database import base as mod_db
     24 from trulens_eval.database import orm as mod_orm

File /opt/conda/lib/python3.10/site-packages/trulens_eval/app.py:22
     19 import pydantic
     21 from trulens_eval import app as mod_app
---> 22 from trulens_eval import feedback as mod_feedback
     23 from trulens_eval import instruments as mod_instruments
     24 from trulens_eval.schema import app as mod_app_schema

File /opt/conda/lib/python3.10/site-packages/trulens_eval/feedback/__init__.py:3
      1 # Specific feedback functions:
      2 # Main class holding and running feedback functions:
----> 3 from trulens_eval.feedback import feedback as mod_feedback
      4 from trulens_eval.feedback.embeddings import Embeddings
      5 from trulens_eval.feedback.groundtruth import GroundTruthAgreement

File /opt/conda/lib/python3.10/site-packages/trulens_eval/feedback/feedback.py:25
     22 from rich.markdown import Markdown
     23 from rich.pretty import pretty_repr
---> 25 from trulens_eval.feedback.provider import base as mod_base_provider
     26 from trulens_eval.feedback.provider.endpoint import base as mod_base_endpoint
     27 from trulens_eval.schema import app as mod_app_schema

File /opt/conda/lib/python3.10/site-packages/trulens_eval/feedback/provider/__init__.py:1
----> 1 from trulens_eval.feedback.provider.base import Provider
      2 from trulens_eval.feedback.provider.hugs import Huggingface
      3 from trulens_eval.feedback.provider.hugs import HuggingfaceLocal

File /opt/conda/lib/python3.10/site-packages/trulens_eval/feedback/provider/base.py:11
      8 from nltk.tokenize import sent_tokenize
      9 import numpy as np
---> 11 from trulens_eval.feedback import prompts
     12 from trulens_eval.feedback.provider.endpoint import base as mod_endpoint
     13 from trulens_eval.utils import generated as mod_generated_utils

File /opt/conda/lib/python3.10/site-packages/trulens_eval/feedback/prompts.py:6
      1 # NOTE: Try not to put anything new here. Prompts should go into
      2 # trulens_eval.feedback.v2.feedback unless they are related to computing
      3 # feedback reasons which can stay here for now as there is no good place for
      4 # those yet.
----> 6 from trulens_eval.feedback.v2 import feedback as v2
      8 COT_REASONS_TEMPLATE = \
      9 """
     10 Please answer using the entire template below.
   (...)
     15 Supporting Evidence: <Provide your reasons for scoring based on the listed criteria step by step. Tie it back to the evaluation being completed.>
     16 """
     18 # Keep this in line with the LLM output template as above

File /opt/conda/lib/python3.10/site-packages/trulens_eval/feedback/v2/feedback.py:4
      1 from abc import abstractmethod
      2 from typing import ClassVar, List, Optional
----> 4 from langchain.evaluation.criteria.eval_chain import _SUPPORTED_CRITERIA
      5 from langchain.prompts import PromptTemplate
      6 import pydantic

File /opt/conda/lib/python3.10/site-packages/langchain/evaluation/__init__.py:56
      1 """**Evaluation** chains for grading LLM and Chain outputs.
      2 
      3 This module contains off-the-shelf evaluation chains for grading the output of
   (...)
     53 
     54 """  # noqa: E501
---> 56 from langchain.evaluation.agents import TrajectoryEvalChain
     57 from langchain.evaluation.comparison import (
     58     LabeledPairwiseStringEvalChain,
     59     PairwiseStringEvalChain,
     60 )
     61 from langchain.evaluation.criteria import (
     62     Criteria,
     63     CriteriaEvalChain,
     64     LabeledCriteriaEvalChain,
     65 )

File /opt/conda/lib/python3.10/site-packages/langchain/evaluation/agents/__init__.py:3
      1 """Chains for evaluating ReAct style agents."""
----> 3 from langchain.evaluation.agents.trajectory_eval_chain import TrajectoryEvalChain
      5 __all__ = ["TrajectoryEvalChain"]

File /opt/conda/lib/python3.10/site-packages/langchain/evaluation/agents/trajectory_eval_chain.py:22
      9 from typing import (
     10     Any,
     11     Dict,
   (...)
     18     cast,
     19 )
     21 from langchain_core.agents import AgentAction
---> 22 from langchain_core.callbacks.manager import (
     23     AsyncCallbackManagerForChainRun,
     24     CallbackManagerForChainRun,
     25     Callbacks,
     26 )
     27 from langchain_core.exceptions import OutputParserException
     28 from langchain_core.language_models import BaseLanguageModel

File /opt/conda/lib/python3.10/site-packages/langchain_core/callbacks/__init__.py:23
     10 from langchain_core.callbacks.base import (
     11     AsyncCallbackHandler,
     12     BaseCallbackHandler,
   (...)
     20     ToolManagerMixin,
     21 )
     22 from langchain_core.callbacks.file import FileCallbackHandler
---> 23 from langchain_core.callbacks.manager import (
     24     AsyncCallbackManager,
     25     AsyncCallbackManagerForChainGroup,
     26     AsyncCallbackManagerForChainRun,
     27     AsyncCallbackManagerForLLMRun,
     28     AsyncCallbackManagerForRetrieverRun,
     29     AsyncCallbackManagerForToolRun,
     30     AsyncParentRunManager,
     31     AsyncRunManager,
     32     BaseRunManager,
     33     CallbackManager,
     34     CallbackManagerForChainGroup,
     35     CallbackManagerForChainRun,
     36     CallbackManagerForLLMRun,
     37     CallbackManagerForRetrieverRun,
     38     CallbackManagerForToolRun,
     39     ParentRunManager,
     40     RunManager,
     41     adispatch_custom_event,
     42     dispatch_custom_event,
     43 )
     44 from langchain_core.callbacks.stdout import StdOutCallbackHandler
     45 from langchain_core.callbacks.streaming_stdout import StreamingStdOutCallbackHandler

File /opt/conda/lib/python3.10/site-packages/langchain_core/callbacks/manager.py:29
     11 from typing import (
     12     TYPE_CHECKING,
     13     Any,
   (...)
     25     cast,
     26 )
     27 from uuid import UUID
---> 29 from langsmith.run_helpers import get_run_tree_context
     30 from tenacity import RetryCallState
     32 from langchain_core.callbacks.base import (
     33     BaseCallbackHandler,
     34     BaseCallbackManager,
   (...)
     40     ToolManagerMixin,
     41 )

File /opt/conda/lib/python3.10/site-packages/langsmith/run_helpers.py:198
    193 R = TypeVar("R", covariant=True)
    194 P = ParamSpec("P")
    197 @runtime_checkable
--> 198 class SupportsLangsmithExtra(Protocol, Generic[P, R]):
    199     """Implementations of this Protoc accept an optional langsmith_extra parameter.
    200 
    201     Args:
   (...)
    208         R: The return type of the callable.
    209     """
    211     def __call__(
    212         self,
    213         *args: P.args,
    214         langsmith_extra: Optional[LangSmithExtra] = None,
    215         **kwargs: P.kwargs,
    216     ) -> R:

File /opt/conda/lib/python3.10/typing.py:312, in _tp_cache.<locals>.decorator.<locals>.inner(*args, **kwds)
    310 except TypeError:
    311     pass  # All real errors (not unhashable args) are raised below.
--> 312 return func(*args, **kwds)

File /opt/conda/lib/python3.10/typing.py:1346, in Generic.__class_getitem__(cls, params)
   1344     else:
   1345         _check_generic(cls, params, len(cls.__parameters__))
-> 1346 return _GenericAlias(cls, params,
   1347                      _typevar_types=(TypeVar, ParamSpec),
   1348                      _paramspec_tvars=True)

File /opt/conda/lib/python3.10/typing.py:1025, in _GenericAlias.__init__(self, origin, params, inst, name, _typevar_types, _paramspec_tvars)
   1021     params = (params,)
   1022 self.__args__ = tuple(... if a is _TypingEllipsis else
   1023                       () if a is _TypingEmpty else
   1024                       a for a in params)
-> 1025 self.__parameters__ = _collect_type_vars(params, typevar_types=_typevar_types)
   1026 self._typevar_types = _typevar_types
   1027 self._paramspec_tvars = _paramspec_tvars

File /opt/conda/lib/python3.10/site-packages/pip/_vendor/typing_extensions.py:3019, in _collect_type_vars(types, typevar_types)
   3017             default_encountered = True
   3018         elif default_encountered:
-> 3019             raise TypeError(f'Type parameter {t!r} without a default'
   3020                             ' follows type parameter with a default')
   3022     tvars.append(t)
   3023 if _should_collect_from_parameters(t):

TypeError: Type parameter +R without a default follows type parameter with a default

**Environment:**

- OS: Windows
- Python Version (3.10.13 | packaged by conda-forge | (main, Dec 23 2023, 15:36:39) [GCC 12.3.0])
- TruLens version (0.33.0)


**Additional context**
This error seems to be related to type hinting in the langsmith library, which is a dependency of trulens_eval. The error suggests there might be an incompatibility between the installed versions of these libraries.


Hi @benuehlinger - there is an issue with pip==24.2. Please downgrade your pip version:

`pip install -U pip==24.0`

Hey @benuehlinger 

We've fixed this issue in 0.33.1, 0.32.1, and 0.31.1 so you can now use TruLens-Eval with the latest pip version.

`pip install -U trulens_eval && pip install -U pip`