Sitemap

Building a Simple Chat UI with LlamaIndex Showing The Power of REPL

LlamaIndex has pioneered the concept of agentic RAG (Retrieval-Augmented Generation), recognising early on the importance of conversational interfaces for interacting with data.

3 min readMay 1, 2025

--

Taking a step back, one of the simplest yet most powerful implementations they offer is the REPL (Read-Eval-Print Loop) chat engine, which allows developers to create interactive chat interfaces with minimal code.

What is REPL?

REPL stands for Read-Eval-Print Loop, a concept borrowed from programming language environments:

  • Read: Take user input
  • Eval: Process that input
  • Print: Return the results
  • Loop: Continue the cycle

In LlamaIndex’s context, REPL provides a simple interactive loop where users can chat with their documents through a conversational interface.

The Power of Simplicity

The beauty of LlamaIndex’s REPL implementation is how it balances simplicity with functionality. With just a few lines of code, you can create a chat interface that:

  1. Accepts natural language queries
  2. Retrieves relevant information from your indexed documents
  3. Generates contextual responses
  4. Maintains conversation history for follow-up questions

Most Basic Notebook

%pip install llama-index-llms-openai
!pip install llama-index
import os
os.environ["OPENAI_API_KEY"] = "<Your OpenAI API Key>"
from llama_index.core.chat_engine import SimpleChatEngine

chat_engine = SimpleChatEngine.from_defaults()
chat_engine.chat_repl()

And the Output:

Model Selection

This example shows how a model can be selected…

!pip uninstall -y llama-index
!pip install llama-index --upgrade

import os
os.environ["OPENAI_API_KEY"] = "<Your OpenAI API Key>"

# The imports have changed. For newer versions of LlamaIndex, try:
from llama_index.llms.openai import OpenAI
# If that doesn't work, try this alternative:
# from llama_index.llms.openai import OpenAI

# Setting up the LLM
llm = OpenAI(temperature=0.0, model="gpt-3.5-turbo")

# Import and set up the chat engine
from llama_index.core.chat_engine import SimpleChatEngine
# If that doesn't work, try:
# from llama_index.chat_engine.simple import SimpleChatEngine

# Create a simple chat engine
chat_engine = SimpleChatEngine.from_defaults(llm=llm)

# Example usage
response = chat_engine.chat("Hello, how are you?")
print(response)

And the Output:

Hello! I'm just a computer program, so I don't have feelings,
but I'm here to help you. How can I assist you today?

Finally

The best way to build and understanding of a framework or technology is to build something, get it to work…and tinker and expand on it.

If you are looking for project to get started with LlamaIndex, this is it…all done in a notebook.

Chief Evangelist @ Kore.ai | I’m passionate about exploring the intersection of AI and language. From Language Models, AI Agents to Agentic Applications, Development Frameworks & Data-Centric Productivity Tools, I share insights and ideas on how these technologies are shaping the future.

--

--

Cobus Greyling
Cobus Greyling

Written by Cobus Greyling

I’m passionate about exploring the intersection of AI & language. www.cobusgreyling.com

Responses (1)