🌉
3-Week Building LLMs Bootcamp
  • Welcome to the Bootcamp
    • Course Structure
    • Course Syllabus and Timelines
    • Know your Educators
    • Action Items and Prerequisites
    • Kick Off Session at Tryst 2024
  • Basics of LLMs
    • What is Generative AI?
    • What is a Large Language Model?
    • Advantages and Applications of LLMs
    • Bonus Resource: Multimodal LLMs and Google Gemini
    • Group Session Recording
  • Word Vectors, Simplified
    • What is a Word Vector
    • Word Vector Relationships
    • Role of Context in LLMs
    • Transforming Vectors into LLM Responses
    • Bonus Section: Overview of the Transformers Architecture
      • Attention Mechanism
      • Multi-Head Attention and Transformers Architecture
      • Vision Transformers
    • Graded Quiz 1
    • Group Session Recording
  • Prompt Engineering and Token Limits
    • What is Prompt Engineering
    • Prompt Engineering and In-context Learning
    • For Starters: Best Practices to Follow
    • Navigating Token Limits
    • Hallucinations in LLMs
    • Prompt Engineering Excercise (Ungraded)
      • Story for the Excercise: The eSports Enigma
      • Your Task for the Module
    • Group Session Recording
  • RAG and LLM Architecture
    • What is Retrieval Augmented Generation (RAG)?
    • Primer to RAG: Pre-trained and Fine-Tuned LLMs
    • In-context Learning
    • High-level LLM Architecture Components for In-context Learning
    • Diving Deeper: LLM Architecture Components
    • Basic RAG Architecture with Key Components
    • RAG versus Fine-Tuning and Prompt Engineering
    • Versatility and Efficiency in RAG
    • Key Benefits of using RAG in an Enterprise/Production Setup
    • Hands-on Demo: Performing Similarity Search in Vectors (Bonus Module)
    • Using kNN and LSH to Enhance Similarity Search (Bonus Module)
    • Bonus Video: Implementing End-to-End RAG | 1-Hour Session
    • Group Session Recording
    • Graded Quiz 2
  • Hands-on Development
    • Prerequisites
    • 1 – Dropbox Retrieval App
      • Understanding Docker
      • Building the Dockerized App
      • Retrofitting your Dropbox app
    • 2 – Amazon Discounts App
      • How the Project Works
      • Building the App
    • 3 – RAG with Open Source and Running "Examples"
    • 4 (Bonus) – Realtime RAG with LlamaIndex/Langchain and Pathway
      • Understanding the Basics
      • Implementation with LlamaIndex and Langchain
    • Building LLM Apps with Open AI Alternatives using LiteLLM
  • Bonus Resource: Recorded Interactions from the Archives
  • Final Project + Giveaways
    • Prizes and Giveaways
    • Suggested Tracks for Ideation
    • Sample Projects and Additional Resources
    • Form for Submission
Powered by GitBook
On this page
  • Step 1: Update and Install LiteLLM
  • Step 2: Obtain and Set your API Key
  • Step 3: Implementing LiteLLM in Python
  • Integrating with Existing Applications

Was this helpful?

  1. Hands-on Development

Building LLM Apps with Open AI Alternatives using LiteLLM

PreviousImplementation with LlamaIndex and LangchainNextBonus Resource: Recorded Interactions from the Archives

Last updated 11 months ago

Was this helpful?

During the course of this bootcamp, many learners highlighted that OpenAI has now stopped giving free credits. As an easy option you can experiement by purchasing $5 credits. If that doesn't work, you don't need to worry as this sub-module helps you with options.

A great option to explore is the use of open source models or go for APIs offered by providers like Cohere, Replicate, Google, etc. This guide will show you how to integrate the LiteLLM connector with the Replicate API, providing a smooth transition.

Step 1: Update and Install LiteLLM

First, let's ensure you have the latest version of LiteLLM, which will help you access the most up-to-date features and improve compatibility:

# This command updates LiteLLM to the latest version.
!pip install -U litellm

# Alternatively, you can specify a minimum version like this: 
!pip install litellm>=1.37.20

Step 2: Obtain and Set your API Key

  • Obtaining your API key: Visit the to find your API key. It's typically located in the right sidebar on the documentation pages.

  • Setting your API key in Python:

import os 
os.environ["REPLICATE_API_KEY"] = "<YOUR_API_KEY>" 
# As a best practice, consider adding your API key to a `.env` file to keep it secure.
# Don't forget to load the env file with the `load_dotenv`!

Step 3: Implementing LiteLLM in Python

Here's how you can set up LiteLLM for a simple chat application using Pathway. This example uses the Llama 3 model provided by Replicate:

import pathway as pw 
from pathway.xpacks.llm.llms import LiteLLMChat, prompt_chat_single_qa 

# Initialize the LLM chat with the chosen model 
chat = LiteLLMChat(model="replicate/meta/meta-llama-3-8b")  # Example model 

# Prepare a query
query_table = pw.debug.table_from_markdown(''' 
txt 
Wazzup? 
''') 

# Generate a response from the LLM 
response = query_table.select(response=chat(prompt_chat_single_qa(query_table.query))) 

# Output the results to see the conversation in action 
print(response)

Integrating with Existing Applications

If you're already using OpenAI LLMs in your apps, switching to LiteLLM is straightforward. Simply replace the model initialization line in your existing code:

# Replace this for OpenAI: 
chat = OpenAIChat(model="gpt-4") 

# With this for Replicate:
chat = LiteLLMChat(model="replicate/meta/meta-llama-3-8b")

This change involves only a few lines, making it an efficient way to adapt to new LLM providers without overhauling your existing applications. If you have any questions or need further assistance, feel free to reach out via #iit-delhi-bootcamp channel on .

Replicate website
Pathway Discord server