This repository contains various scripts demonstrating the use of different language models and embedding models using the LangChain framework. Each script showcases a specific model or functionality, such as chat models, embeddings, and document similarity.
Before running any scripts, ensure you have the necessary dependencies installed. You can install them using:
pip install langchain-openai langchain-anthropic langchain-google-genai langchain-huggingface scikit-learn python-dotenvAdditionally, ensure you have API keys for the respective models and that they are set up in your environment variables using a .env file.
Set up your API keys by creating a .env file in the root directory:
OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key
GOOGLE_API_KEY=your_google_key
HUGGINGFACEHUB_API_KEY=your_huggingface_api_keyFile: 1_chatmodel_openai.py
Description: Demonstrates how to use OpenAI's GPT-4 chat model for text-based conversations.
File: 1_embedding_openai_query.py
Description: Uses OpenAI's text-embedding-3-large model to generate a 32-dimensional embedding for a given text query.
File: 1_llm_demo.py
Description: Invokes OpenAI's GPT-3.5-turbo-instruct model for text-based response generation.
File: 2_chatmodel_anthropic.py
Description: Uses Anthropic's GPT-4 equivalent model for chat-based interactions.
File: 2_embedding_openai_docs.py
Description: Generates embeddings for multiple documents using OpenAI's text-embedding-3-large model and returns their vector representation.
File: 3_chatmodel_google.py
Description: Uses Google's gemini-1.5-pro model for conversational AI interactions.
File: 3_embedding_hf_local.py
Description: Uses sentence-transformers/all-MiniLM-L6-v2 to generate embeddings locally for a set of documents.
File: 4_chatmodel_hf_api.py
Description: Uses Hugging Face's TinyLlama-1.1B-Chat-v1.0 model for generating text responses via API.
File: 4_document_similarity.py
Description: Uses Hugging Face's sentence-transformers/all-MiniLM-L6-v2 embeddings to compute similarity between a query and a set of documents using cosine similarity.
File: 5_chatmodel_hf_local.py
Description: Uses Hugging Face's TinyLlama-1.1B-Chat-v1.0 model locally via a pipeline for text generation.
To run any script, use the following command:
python <script_name>.pyEnsure that API keys and necessary credentials are correctly set up in your .env file before running the scripts.
This repository provides a hands-on demonstration of various language models and embedding techniques using LangChain. It covers OpenAI, Anthropic, Google, and Hugging Face models for chat, text generation, and document similarity tasks.