Lmarena.ai had a mode to ask questions about a github repo. How could i set something like tgat up locally using ollama, an llm tuned for code, and local git repos?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Yes, you can absolutely set up a local version of Lmarena.ai's GitHub repo Q&A feature using Ollama, a code-specialized LLM, and your local Git repositories. Here's a step-by-step guide to achieve this.
🔧 Goal
Enable natural language Q&A over your local Git repositories using a locally running LLM (e.g., via Ollama).
✅ Tools You'll Use
Ollama – Run LLMs locally.
Code-specialized LLM – e.g., codellama, deepseek-coder, starcoder, phi3:medium-128k-instruct, or qwen:code.
Git – To access your local repositories.
Python + RAG Pipeline – To index code and retrieve relevant snippets.
Optional: llama-index, langchain, or a custom script.
🛠️ Step-by-Step Setup
1. Install Ollama
# macOS
brew install ollama
# Linux
curl -fsSL https://ollama.com/install.sh | sh
# Windows: Download from https://ollama.com
Start Ollama:
ollama serve
2. Pull a Code-Specialized LLM
Choose one optimized for code understanding:
# Example models:
ollama pull codellama:70b-instruct # powerful, large
ollama pull deepseek-coder:6.7b # great for code
ollama pull phi3:medium-128k-instruct # small but fast, good for code
ollama pull qwen:7b-code # Alibaba's code model
💡 Tip: Use -instruct variants for better prompt following.
3. Set Up Your Local Git Repo
Ensure your repo is cloned locally:
git clone https://github.com/your-user/your-repo.git
cd your-repo
You’ll query this repo.
4. Index the Code (RAG Setup)
Use a Retrieval-Augmented Generation (RAG) system to:
Read and chunk code files.
Store embeddings (or just text if using simple keyword + semantic search).
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
from llama_index.llms.ollama import Ollama
from llama_index.readers.git import GitReader
# Set up LLM
Settings.llm = Ollama(model="deepseek-coder:6.7b", request_timeout=120.0)
# Load git repo (local or remote)
loader = GitReader(
git_url="/path/to/your/local/repo", # or a GitHub URL
use_parser=True,
verbose=True,
)
documents = loader.load_data(branch="main") # or your branch
# Create index
index = VectorStoreIndex.from_documents(documents)
# Query
query_engine = index.as_query_engine()
response = query_engine.query("How do I initialize the database in this project?")
print(response)
🔍 GitReader reads from a local path or Git URL and loads all tracked files.
Option B: Manual RAG (More control)
Traverse your repo:
import os
def read_repo(path):
code = ""
for root, _, files in os.walk(path):
for file in files:
if file.endswith((".py", ".js", ".ts", ".go", ".rs", ".java", ".cpp")):
filepath = os.path.join(root, file)
try:
with open(filepath, "r", encoding="utf-8") as f:
code += f"\n--- FILE: {filepath} ---\n{f.read()}\n"
except:
pass
return code
Chunk the code and store in memory or a vector DB.
On query, use semantic similarity (e.g., sentence-transformers) to find relevant chunks.
Send context + question to Ollama:
import requests
def query_ollama(prompt, model="deepseek-coder:6.7b"):
r = requests.post(
"http://localhost:11434/api/generate",
json={
"model": model,
"prompt": prompt,
"stream": False
}
)
return r.json()["response"]
context = "..." # retrieved code snippets
question = "How is authentication handled?"
prompt = f"Based on the following code, answer the question:\n\n{context}\n\nQuestion: {question}"
print(query_ollama(prompt))
5. Add CLI or Web Interface (Optional)
Make it user-friendly:
CLI Tool: Use argparse to take repo path and question.
Web UI: Use Gradio or Streamlit for a chat-like interface.
Example with Streamlit:
import streamlit as st
st.title("Local Repo QA")
question = st.text_input("Ask about your code:")
if question:
response = query_engine.query(question)
st.write(str(response))
Run with:
streamlit run app.py
✅ Example Workflow
Clone a repo: ~/projects/myapp
Run your script: python repo_qa.py
Ask: "Which function handles user login?"
System:
Finds auth.py
Sends context to deepseek-coder
Returns: "The login_user() function in auth.py validates credentials..."
🚀 Pro Tips
Use .gitignore: Skip node_modules, __pycache__, etc.
Limit file types: Only read .py, .js, .go, etc.
Use 128K context models: phi3:medium-128k-instruct can handle large codebases.
Cache embeddings: Speed up repeated queries.
Add repo metadata: Branch, last commit, etc.
🧩 Alternative: Use gpt4all or jan AI
If you want a GUI, tools like Jan or GPT4All allow local LLM + RAG with drag-and-drop.
Summary
Component
Tool/Example
LLM
deepseek-coder, codellama, phi3
Local Server
Ollama
Code Indexing
LlamaIndex + GitReader
Query Interface
Python script, CLI, or Streamlit
Retrieval
RAG with semantic search
Let me know if you want a ready-to-run GitHub repo template for this!
User
As the contents of the git repo change, how do i keep the database up to date? How do i handle multiple repos and branches?
Assistant
Great question! As your Git repositories evolve (new commits, branches, files), your local LLM Q&A system must stay in sync to give accurate answers. Here’s how to handle:
✅ Keeping the index/database up to date
✅ Supporting multiple repos
✅ Handling multiple branches
🔁 1. Keeping the Index Updated as Code Changes
You have a few strategies, depending on your needs:
✅ Option A: Re-index on Demand (Simple)
Run indexing only when you ask a question or manually trigger it.
Use a persistent vector store (like Chroma or FAISS on disk):
from llama_index.vector_stores.chroma import ChromaVectorStore
from llama_index.core import VectorStoreIndex, StorageContext
from llama_index.readers.git import GitReader
def update_index(repo_path, branch="main", db_dir="./vector_dbs"):
persist_dir = f"{db_dir}/{repo_path.strip('/').split('/')[-1]}_{branch}"
loader = GitReader(git_url=repo_path, branch=branch)
docs = loader.load_data()
# Load or create vector store
vector_store = ChromaVectorStore.from_persist_dir(persist_dir)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
# Rebuild index (or use upsert logic)
index = VectorStoreIndex.from_documents(
docs, storage_context=storage_context, show_progress=True
)
index.storage_context.persist(persist_dir)
User
Has someone packaged this all together already? Is there an open source project which does this?
Assistant
Yes! There are several open-source projects that are close to — or fully — solving the exact problem you're describing: Q&A over local Git repositories using locally running LLMs (like Ollama).
While nothing is exactly "Lmarena.ai but fully local and open," there are excellent tools that combine RAG over code, Git integration, and local LLM support. Here are the best ones as of 2025:
qa = get_query_engine("myapp", "main")
response = qa.query("How is the API rate limit configured?")
✅ B. Unified Index (Advanced)
Merge multiple repos into one index (e.g., microservices).
all_docs = []
for repo in repo_paths:
loader = GitReader(git_url=repo)
all_docs.extend(loader.load_data())
index = VectorStoreIndex.from_documents(all_docs)
⚠️ Risk: Confusion between similarly named files.
✅ Use only if repos are closely related.
Add metadata: {"repo": "auth-service", "branch": "dev"} to filter later.
🔀 3. Handling Multiple Branches
Each branch may have different code → must be indexed separately.