Repository: truera/trulens
Issue: Langchain request failed
Root cause: Environment Incompatibility

**Bug Description**
Hi! I'm trying to run a simple application using Langchain as provider and Ollama to fetch the model. I've been following the guide in the docs on how to run test on [outside logs](https://www.trulens.org/trulens/getting_started/quickstarts/existing_data_quickstart/).

Unfortunately I keep getting an error related to the Langchain endpoint.

**To Reproduce**
The following is my code:

from trulens.apps.virtual import VirtualApp, VirtualRecord, TruVirtual
from trulens.core import Select
from trulens.core import Feedback
from trulens.providers.langchain import Langchain
from trulens.providers.huggingface import Huggingface
from langchain_community.llms.ollama import Ollama


virtual_app = dict(
    llm=dict(modelname="some llm component model name"),
    template="information about the template I used in my app",
    debug="all of these fields are completely optional",
)

virtual_app = VirtualApp(virtual_app)  # can start with the prior dictionary
virtual_app[Select.RecordCalls.llm.maxtokens] = 1024

retriever = Select.RecordCalls.retriever
synthesizer = Select.RecordCalls.synthesizer

virtual_app[retriever] = "retriever"
virtual_app[synthesizer] = "synthesizer"

context_call = retriever.get_context
generation = synthesizer.generate

rec1 = VirtualRecord(
    main_input="Where is Germany?",
    main_output="Germany is in Europe",
    calls={
        context_call: dict(
            args=["Where is Germany?"],
            rets=["Germany is a country located in Europe."],
        ),
        generation: dict(
            args=[
                """
                    We have provided the below context: \n
                    ---------------------\n
                    Germany is a country located in Europe.
                    ---------------------\n
                    Given this information, please answer the question: 
                    Where is Germany?
                      """
            ],
            rets=["Germany is a country located in Europe."],
        ),
    },
)

rec1.cost.n_tokens = 234
rec1.cost.cost = 0.05

data = [rec1]

provider = Langchain(chain=Ollama(model="llama2"))

context = context_call.rets[:]

provider.context_relevance('Where is Germany?', 'Germany is a country located in Europe.')


**Expected behavior**
I started having issues after the major library update moving away from trulens_eval, when everything used to work fine.

**Relevant Logs/Tracebacks**

langchain request failed <class 'requests.exceptions.ConnectionError'>=HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x30a56fb80>: Failed to establish a new connection: [Errno 61] Connection refused')). Retries remaining=3.
langchain request failed <class 'requests.exceptions.ConnectionError'>=HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x30a5b4a00>: Failed to establish a new connection: [Errno 61] Connection refused')). Retries remaining=2.
langchain request failed <class 'requests.exceptions.ConnectionError'>=HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x30a5be820>: Failed to establish a new connection: [Errno 61] Connection refused')). Retries remaining=1.
langchain request failed <class 'requests.exceptions.ConnectionError'>=HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x16b45f640>: Failed to establish a new connection: [Errno 61] Connection refused')). Retries remaining=0.
Traceback (most recent call last):
  File "/Users/amirgheser/eloquid/rag-evaluator/RAG_eval/debug.py", line 61, in <module>
    provider.context_relevance('Where is Germany?', 'Germany is a country located in Europe.')
  File "/Users/amirgheser/miniconda3/envs/rag_eval3.9/lib/python3.9/site-packages/trulens/feedback/llm_provider.py", line 358, in context_relevance
    return self.generate_score(
  File "/Users/amirgheser/miniconda3/envs/rag_eval3.9/lib/python3.9/site-packages/trulens/feedback/llm_provider.py", line 105, in generate_score
    response = self.endpoint.run_in_pace(
  File "/Users/amirgheser/miniconda3/envs/rag_eval3.9/lib/python3.9/site-packages/trulens/core/feedback/endpoint.py", line 323, in run_in_pace
    raise RuntimeError(
RuntimeError: Endpoint langchain request failed 4 time(s): 
        HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x30a56fb80>: Failed to establish a new connection: [Errno 61] Connection refused'))
        HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x30a5b4a00>: Failed to establish a new connection: [Errno 61] Connection refused'))
        HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x30a5be820>: Failed to establish a new connection: [Errno 61] Connection refused'))
        HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x16b45f640>: Failed to establish a new connection: [Errno 61] Connection refused'))

**Environment:**

- OS: MacOS Sonoma 14.5
- Python 3.8 using Conda 24.7.1
- TruLens 1.0.1
- Other libraries:
langchain                 0.2.16                   pypi_0    pypi
langchain-community       0.2.16                   pypi_0    pypi
langchain-core            0.3.5                    pypi_0    pypi
langchain-ollama          0.2.0                    pypi_0    pypi
langchain-text-splitters  0.2.4                    pypi_0    pypi
langsmith                 0.1.128                  pypi_0    pypi
ollama                    0.3.3                    pypi_0    pypi


Hi; can you provide the configuration to Ollama that would make its use work outside of trulens like here:

```python
from langchain_community.llms.ollama import Ollama

model = Ollama()
model.generate(prompts=["Hello there."])
```

Thanks to your question I found the issue.
Used ChatOllama from langchain_ollama.chat_models and the problem was solved.

In case it might help the following is a simple example

`from langchain_community.llms.ollama import Ollama

model = Ollama(name='llama2',
               )
messages = [
    ("system", "You are a helpful assistant."),
    ("human", "Who is Maskesync?")
    ]

print(model.invoke(messages))
`