LangChain components for Dartmouth-hosted models.
Project description
Dartmouth LangChain
LangChain components for Dartmouth-hosted models.
Getting started
- Install the package:
pip install dartmouth-langchain
- 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 implemened:
- 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 dartmouth_langchain.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 dartmouth_langchain.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 dartmouth_langchain import DartmouthEmbeddingsModel
embeddings = DartmouthEmbeddingsModel()
embeddings.embed_query("Hello? Is there anybody in there?")
Reranking
Using a Dartmouth-hosted reranking model:
from dartmouth_langchain.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
Release history Release notifications | RSS feed
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 dartmouth_langchain-0.2.4.tar.gz
.
File metadata
- Download URL: dartmouth_langchain-0.2.4.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d369ce9c2391c6c3e847730502254e8323f792e1e266d2679f20388c843bf76a |
|
MD5 | 2e1cce69fa8199e331c5b4c83cbb87cb |
|
BLAKE2b-256 | 56a417142a8dc0101b2beb2fa5fe6479e8b5de79b5e348c0044c068c48f2a8ec |
File details
Details for the file dartmouth_langchain-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: dartmouth_langchain-0.2.4-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | adcd97c30400ff3eae069f91feb6151da5552c7d39ebfe84e6f6b3cad3428b0f |
|
MD5 | bc2bec07cd8f4a63f8ca74ffd9f59d0c |
|
BLAKE2b-256 | 190ffb76226bdd9b51a2b13275c0b687e9c1111de23b41a02aaec4575c0c080a |