LangChain components for Dartmouth-hosted models.
Project description
Dartmouth LangChain
LangChain components for Dartmouth-hosted models.
Getting started
- Install the package:
pip install langchain_dartmouth
- Obtain a Dartmouth API key from developer.dartmouth.edu
- Store the API key as an environment variable called
DARTMOUTH_API_KEY
:
export DARTMOUTH_API_KEY=<your_key_here>
What is this?
This library provides an integration of Darmouth-hosted generative AI resources with the LangChain framework.
There are three main components currently implemented:
- Large Language Models
- Embedding models
- Reranking models
All of these components are based on corresponding LangChain base classes and can be used seamlessly wherever the corresponding LangChain objects can be used.
Using the library
Large Language Models
There are two kinds of Large Language Models (LLMs) hosted by Dartmouth:
- Base models without instruction tuning (require no special prompt format)
- Instruction-tuned models (also known as Chat models) requiring specific prompt formats
Using a Dartmouth-hosted base language model:
from langchain_dartmouth.llms import DartmouthLLM
llm = DartmouthLLM(model_name="codellama-13b-hf")
response = llm.invoke("Write a Python script to swap two variables.")
print(response)
Using a Dartmouth-hosted chat model:
from langchain_dartmouth.llms import ChatDartmouth
llm = ChatDartmouth(model_name="llama-3-8b-instruct")
response = llm.invoke("Hi there!")
print(response.content)
Note: The required prompt format is enforced automatically when you are using
ChatDartmouth
.
Embeddings model
Using a Dartmouth-hosted embeddings model:
from langchain_dartmouth.embeddings import DartmouthEmbeddingsModel
embeddings = DartmouthEmbeddingsModel()
embeddings.embed_query("Hello? Is there anybody in there?")
print(response)
Reranking
Using a Dartmouth-hosted reranking model:
from langchain_dartmouth.retrievers.document_compressors import DartmouthReranker
from langchain.docstore.document import Document
docs = [
Document(page_content="Deep Learning is not..."),
Document(page_content="Deep learning is..."),
]
query = "What is Deep Learning?"
reranker = DartmouthReranker(model_name="bge-reranker-v2-m3")
ranked_docs = reranker.compress_documents(query=query, documents=docs)
print(ranked_docs)
Available models
For a list of available models, check the documentation of the RESTful Dartmouth AI API.
License
Created by Simon Stone for Dartmouth College Libraries under Creative Commons CC BY-NC 4.0 License. For questions, comments, or improvements, email Research Data Services. |
Except where otherwise noted, the example programs are made available under the OSI-approved MIT license.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file langchain_dartmouth-0.2.11.tar.gz
.
File metadata
- Download URL: langchain_dartmouth-0.2.11.tar.gz
- Upload date:
- Size: 127.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28eaaa24541f99b5c00857b4f6c497dccbfd230cb134c4ed20fc1bd92f12178c |
|
MD5 | dadbb7514e09ff3b194eb47fdf43529d |
|
BLAKE2b-256 | f52feeac1a1ee0a7d0789bd805e4134c7d05b11e8b94ddbb444c9aa68f41669e |
File details
Details for the file langchain_dartmouth-0.2.11-py3-none-any.whl
.
File metadata
- Download URL: langchain_dartmouth-0.2.11-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e7124cd81afb250240ab3096125aa94d4b36edcb72aa19e663abeb1a4feda37 |
|
MD5 | 5c1936237af06705f8ae9d4fae4a47d2 |
|
BLAKE2b-256 | b8f844ad04d49df394a603b50b86639aee476df05bed7fa0c4ad94804ded5c94 |