Repository: truera/trulens
Issue: [BUG] Runtime error when calling LiteLLM constructor
Root cause: External Dependency Breakage

**Bug Description**
from trulens_eval import Feedback
from trulens.providers.litellm import LiteLLM 

ollama_provider = LiteLLM(
    model_engine="ollama/phi3:mini",          
    api_base="http://localhost:11434"     
)

Error: AttributeError: 'CallTypes' object has no attribute '__name__'

**To Reproduce**
I am seeing this error when invoking the LiteLLM constructor

**Expected Behavior**
Invoking the LiteLLM constructor should not lead to this error

**Relevant Logs/Tracebacks**
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[1], line 8
      2 from trulens.providers.litellm import LiteLLM  # provider that can route to Ollama
      4 # create the TrueLens feedback provider
      5 # This initializes a lightweight evaluator that can use ollama models
      6 # to score outputs, rather than generate them
      7 # Point the provider to your local Ollama server/model
----> 8 ollama_provider = LiteLLM(
      9     model_engine="ollama/phi3:mini",          
     10     api_base="http://localhost:11434"         # default Ollama endpoint
     11 )
     13 # setup the "Answer Relevance" metric
     14 # What does this do?
     15 # 1. Capture the input and output for that call
   (...)     21 # - openai.relevance_with_cot_reasons - Judge that scores how relevant an answer is to its question
     22 # - .on_input_output() - Apply this judge to both the input and output fields
     23 qa_relevance = (
     24     Feedback(ollama_provider.relevance_with_cot_reasons, name="Answer Relevance")
     25     .on_input()
     26     .on_output()
     27 )

File d:\github\truelens\.langchain_ollama\Lib\site-packages\trulens\providers\litellm\provider.py:87, in LiteLLM.__init__(self, model_engine, completion_kwargs, endpoint, **kwargs)
     85 # store completion kwargs dict on the provider
     86 self_kwargs["completion_args"] = dict(completion_kwargs)
---> 87 self_kwargs["endpoint"] = litellm_endpoint.LiteLLMEndpoint(
     88     litellm_provider=litellm_provider, **kwargs
     89 )
     91 super().__init__(
     92     **self_kwargs
     93 )

File d:\github\truelens\.langchain_ollama\Lib\site-packages\trulens\providers\litellm\endpoint.py:94, in LiteLLMEndpoint.__init__(self, litellm_provider, **kwargs)
     92 kwargs["callback_class"] = LiteLLMCallback
     93 super().__init__(litellm_provider=litellm_provider, **kwargs)
---> 94 self._instrument_module_members(litellm, "completion")

File d:\github\truelens\.langchain_ollama\Lib\site-packages\trulens\core\feedback\endpoint.py:477, in Endpoint._instrument_module_members(self, mod, method_name)
    474     obj = python_utils.safer_getattr(mod, m)
    475     if obj is not None and isinstance(obj, type):
    476         # Instrument only classes, not instances.
--> 477         self._instrument_class(obj, method_name=method_name)
    479 already_instrumented.add(method_name)

File d:\github\truelens\.langchain_ollama\Lib\site-packages\trulens\core\feedback\endpoint.py:381, in Endpoint._instrument_class(self, cls, method_name)
    374 logger.debug(
    375     "Instrumenting %s.%s for %s",
    376     python_utils.class_name(cls),
    377     method_name,
    378     self.name,
    379 )
    380 func = getattr(cls, method_name)
--> 381 w = self.wrap_function(func)
    383 setattr(cls, method_name, w)
    385 Endpoint.instrumented_methods[cls].append((func, w, type(self)))

File d:\github\truelens\.langchain_ollama\Lib\site-packages\trulens\core\feedback\endpoint.py:857, in Endpoint.wrap_function(self, func)
    852 # Set our tracking attribute to tell whether something is already
    853 # instrumented onto both the sync and async version since either one
    854 # could be returned from this method.
    855 setattr(tru_wrapper, INSTRUMENT, [self.callback_class])
--> 857 logger.debug("Instrumenting %s for %s.", func.__name__, self.name)
    859 return tru_wrapper

AttributeError: 'CallTypes' object has no attribute '__name__'

**Environment:**

- OS: Windows 11
- Python Version: 3.12.8
- TruLens version: 2.4.2
- Versions of other relevant installed libraries
Name: trulens-apps-langchain Version: 2.4.2
Name: trulens_eval Version: 2.4.2
Name: trulens-providers-litellm Version: 2.4.2
Name: langchain Version: 1.0.2
Name: langchain-community Version: 0.4.1
Name: langchain-core Version: 1.0.1
Name: langchain-ollama Version: 1.0.0

**Additional Context**
Add any other context about the problem here.


I moved TrueLens to the new API as per: https://www.trulens.org/component_guides/other/trulens_eval_migration/
I am still seeing this error. I urgently need help. Thanks!

<!-- Greeting -->
Hi @22sauravt! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the trulens team.

<!-- Answer -->
The error is likely caused by using outdated import paths and API signatures after migration. In the new TruLens API, you should import Feedback and session classes from trulens.core, and use the modular provider imports. For LiteLLM, make sure you are importing from the correct location and not from trulens_eval or trulens.providers.litellm, as these are deprecated and can cause runtime errors like the one you're seeing.

Here's how your imports and initialization should look in the new API:

```python
from trulens.core import Feedback, TruSession
from trulens.apps.langchain import TruChain
from trulens_providers_litellm import LiteLLM  # or the correct new provider import
# ... other necessary imports

provider = LiteLLM(
    model_engine="ollama/phi3:mini",
    api_base="http://localhost:11434"
)

relevance = Feedback(provider.relevance_with_cot_reasons).on_input_output()
```

Make sure all your imports match the new modular structure and avoid any deprecated paths. This should resolve the AttributeError you're encountering. For more details and a full example, see the [relevant discussion](https://github.com/truera/trulens/discussions/1927).


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*

---
<sup>How did I do? [Good](https://app.dosu.dev/response-feedback/fc3233c3-7019-42f5-a390-b3e6e9c3bee8?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/fc3233c3-7019-42f5-a390-b3e6e9c3bee8?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/fc3233c3-7019-42f5-a390-b3e6e9c3bee8?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/fc3233c3-7019-42f5-a390-b3e6e9c3bee8?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/fc3233c3-7019-42f5-a390-b3e6e9c3bee8?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/fc3233c3-7019-42f5-a390-b3e6e9c3bee8?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/fc3233c3-7019-42f5-a390-b3e6e9c3bee8?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/e16d1378-a540-46b6-bd0e-816c493d2aee/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/truera/trulens/issues/2274)

Thanks Dosu! Where should I import LiteLLM from? It is not mentioned in the new API migration document

<!-- Answer -->
You should import LiteLLM using:

```python
from trulens.providers.litellm import LiteLLM
```

This is the recommended import path in the new modular API, as shown in recent examples and discussions ([source](https://github.com/truera/trulens/issues/2208)). Make sure you have the `trulens-providers-litellm` package installed. Avoid importing from `trulens_eval` or any deprecated paths, as those can cause runtime errors. If you need a full example or run into further issues, let me know!


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*

---
<sup>How did I do? [Good](https://app.dosu.dev/response-feedback/391c69c6-d8af-4fdf-9f62-a651d41d0176?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/391c69c6-d8af-4fdf-9f62-a651d41d0176?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/391c69c6-d8af-4fdf-9f62-a651d41d0176?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/391c69c6-d8af-4fdf-9f62-a651d41d0176?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/391c69c6-d8af-4fdf-9f62-a651d41d0176?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/391c69c6-d8af-4fdf-9f62-a651d41d0176?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/391c69c6-d8af-4fdf-9f62-a651d41d0176?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/e16d1378-a540-46b6-bd0e-816c493d2aee/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/truera/trulens/issues/2274)

This is what I ended up doing. I did see incompatibility the TrueLens new API and the new LangChain release. I had to revert to older version of LangChain to make my code work. 

@22sauravt notwithstanding the langchain 1.0 compatibility (we're working on it!), did you get this resolved?

langchain 1.0 compatibility coming soon! https://github.com/truera/trulens/pulls

Langchain compatibility is released in trulens 2.5.0.

Please upgrade:

`pip install -U trulens-core trulens-feedback trulens-apps-langchain trulens-apps-langgraph`

Please re-open if the issue persists. thanks