Skip to main content

LangChain components for Dartmouth-hosted models.

Project description

Dartmouth LangChain

documentation tests

LangChain components for Dartmouth-hosted models.

Getting started

  1. Install the package:
pip install langchain_dartmouth
  1. Obtain a Dartmouth API key from developer.dartmouth.edu
  2. 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 under Creative Commons CC BY-NC 4.0 License.
For questions, comments, or improvements, email Research Data Services.
Creative Commons License

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

langchain_dartmouth-0.2.12.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_dartmouth-0.2.12-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file langchain_dartmouth-0.2.12.tar.gz.

File metadata

  • Download URL: langchain_dartmouth-0.2.12.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for langchain_dartmouth-0.2.12.tar.gz
Algorithm Hash digest
SHA256 796b79f756140976ed758da1a46c6a6fb149be39cb2ad1ef014a1922426746b6
MD5 4a6c48669f5345f6b0aa7a6ad4d63486
BLAKE2b-256 b70a5df62a3981e2f0397bd0a2c88afc3c49ed77d4ba56a1718669b6e02abac5

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_dartmouth-0.2.12.tar.gz:

Publisher: pypi.yml on dartmouth/langchain-dartmouth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchain_dartmouth-0.2.12-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_dartmouth-0.2.12-py3-none-any.whl
Algorithm Hash digest
SHA256 225326d57fee72d0e9d3cd7186d03420239f7f807a193bb1f6ab2906522c59ba
MD5 135e9b452dbb90f79ca73569d1f2c64f
BLAKE2b-256 a98fc352b8ba7f5789d321f5a9bea77b3a0314cbf4f0f8f95d2858669d0607dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_dartmouth-0.2.12-py3-none-any.whl:

Publisher: pypi.yml on dartmouth/langchain-dartmouth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page