Skip to content

TruLens dashboard not showing token usage and cost with Ollama provider #2208

@RockybhaiRakesh

Description

@RockybhaiRakesh

Bug Description
When using TruLens + Ollama (local LLM via LiteLLM provider), the TruLens dashboard always shows 0 for Total Tokens (#) and Total Cost (App), even though queries and responses are being logged successfully.

Latency is shown correctly, but token usage and cost remain 0.

To Reproduce
Steps to reproduce the behavior:

Install and run Ollama locally (ollama run llama2, ollama run nomic-embed-text).

Install dependencies:

pip install trulens trulens-apps-langchain trulens-providers-litellm langchain-community chromadb requests

Run the following minimal script:

import requests, chromadb
from langchain_community.llms import Ollama
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate, ChatPromptTemplate, HumanMessagePromptTemplate
from trulens.core import Feedback, TruSession
from trulens.apps.langchain import TruChain
from trulens.providers.litellm import LiteLLM

ollama = Ollama(base_url="http://localhost:11434", model="llama2")

full_prompt = HumanMessagePromptTemplate(
prompt=PromptTemplate(
template="Context: {context}\n\nQuestion: {prompt}\nAnswer:",
input_variables=["context", "prompt"],
)
)
chat_prompt_template = ChatPromptTemplate.from_messages([full_prompt])
chain = LLMChain(llm=ollama, prompt=chat_prompt_template, verbose=True)

session = TruSession()
session.reset_database()

ollama_provider = LiteLLM(model_engine="ollama/llama2", api_base="http://localhost:11434")
relevance = Feedback(ollama_provider.relevance_with_cot_reasons).on_input_output()

tru_recorder = TruChain(chain, app_name="Llama2_Chroma_RAG", feedbacks=[relevance])

with tru_recorder as recording:
response = chain.invoke({"context": "Ollama is a local LLM runtime.", "prompt": "What is Ollama?"})
print(response["text"])

from trulens.dashboard import run_dashboard
run_dashboard(session)

Open the dashboard (http://localhost:8501).

Expected Behavior
The dashboard should display Total Tokens (#) and ideally allow either:

integration with Ollama’s internal token counters (if available), or

a clear warning that token/cost metrics are not supported for local models.

Relevant Logs/Tracebacks
No error logs. Application runs successfully.
Dashboard shows 0 for tokens and cost:

Image

Environment:

OS: Windows 11

Python Version: 3.12.4

TruLens Version: (e.g. 2.3.0)

LangChain Version: 0.2.x

LiteLLM Version: 1.11.1

Ollama Version: latest (running ollama serve)

Models Installed:

ollama list
llama2:latest
nomic-embed-text:latest

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions