This project demonstrates the integration of LlamaIndex with Azure OpenAI and LangSmith for tracing and monitoring AI applications.
The project sets up a simple LlamaIndex application that:
- Uses Azure OpenAI for text generation and embeddings
- Integrates with LangSmith for tracing and monitoring
- Demonstrates basic document indexing and querying capabilities
- Python 3.11
- Azure OpenAI service with:
- GPT-4 deployment
- Embeddings model deployment
- LangSmith account and API key
- uv (Python package installer)
- Clone the repository:
git clone <repository-url>
cd langsmith-llamaindex
- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Install dependencies using uv:
# Install uv using the recommended script if you haven't already:
# On macOS and Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows (PowerShell):
# powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# Verify uv installation
uv --version
# Install project dependencies
uv pip install -r requirements.txt
- Create a
.env
file in the project root with the following variables:
# Azure OpenAI Configuration
AZURE_OPENAI_API_KEY=your_azure_openai_api_key
AZURE_OPENAI_ENDPOINT=your_azure_openai_endpoint
AZURE_OPENAI_API_VERSION=your_api_version
AZURE_OPENAI_GPT4o_MODEL=your_gpt4_model_name
AZURE_OPENAI_GPT4o_DEPLOYMENT=your_gpt4_deployment_name
AZURE_OPENAI_EMBEDDINGS_MODEL=your_embeddings_model_name
AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT=your_embeddings_deployment_name
AZURE_OPENAI_EMBEDDINGS_ENDPOINT=your_embeddings_endpoint
AZURE_OPENAI_EMBEDDINGS_API_VERSION=your_embeddings_api_version
# LangSmith Configuration
LANGSMITH_API_KEY=your_langsmith_api_key
LANGSMITH_PROJECT=your_project_name
Run the main application:
python app.py
The application will:
- Initialize the Traceloop SDK with LangSmith configuration
- Set up LlamaIndex with Azure OpenAI
- Create a test index with an example document
- Run a sample query and print the response
app.py
: Main application file containing the LlamaIndex and LangSmith integrationconfig.py
: Configuration management using Pydanticrequirements.txt
: Project dependencies.env
: Environment variables (not tracked in git)
- llama-index >= 0.9.0
- traceloop >= 0.0.1
- pydantic >= 2.0.0
- pydantic-settings >= 2.0.0
- python-dotenv >= 1.0.0