Skip to content

Commit

Permalink
init pkg (#1)
Browse files Browse the repository at this point in the history
* migrate Together

* x
  • Loading branch information
efriis authored Aug 29, 2024
1 parent 6d81e60 commit 96a9bd4
Show file tree
Hide file tree
Showing 31 changed files with 3,680 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/check_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
from typing import Dict

LIB_DIRS = ["libs/{lib}"]
LIB_DIRS = ["libs/together"]

if __name__ == "__main__":
files = sys.argv[1:]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
working-directory:
required: true
type: string
default: 'libs/'
default: 'libs/together'

env:
PYTHON_VERSION: "3.11"
Expand Down Expand Up @@ -159,7 +159,7 @@ jobs:

- name: Run integration tests
env:
PARTNER_API_KEY: ${{ secrets.PARTNER_API_KEY }}
TOGETHER_API_KEY: ${{ secrets.TOGETHER_API_KEY }}
run: make integration_tests
working-directory: ${{ inputs.working-directory }}

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 🦜️🔗 LangChain {partner}
# 🦜️🔗 LangChain Together

This repository contains 1 package with {partner} integrations with LangChain:
This repository contains 1 package with Together integrations with LangChain:

- [langchain-{package_lower}](https://pypi.org/project/langchain-{package_lower}/)

Expand Down Expand Up @@ -46,5 +46,5 @@ Slack
- [ ] Set up release alerting in Slack (ask Erick for help)

release:
/github subscribe langchain-ai/langchain-{partner_lower} releases workflows:{name:"release"}
/github unsubscribe langchain-ai/langchain-{partner_lower} issues pulls commits deployments
/github subscribe langchain-ai/langchain-together releases workflows:{name:"release"}
/github unsubscribe langchain-ai/langchain-together issues pulls commits deployments
1 change: 1 addition & 0 deletions libs/together/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
21 changes: 21 additions & 0 deletions libs/together/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 LangChain, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
56 changes: 56 additions & 0 deletions libs/together/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.PHONY: all format lint test tests integration_tests docker_tests help extended_tests

# Default target executed when no arguments are given to make.
all: help

# Define a variable for the test file path.
TEST_FILE ?= tests/unit_tests/

integration_test integration_tests: TEST_FILE=tests/integration_tests/

test tests integration_test integration_tests:
poetry run pytest $(TEST_FILE)

######################
# LINTING AND FORMATTING
######################

# Define a variable for Python and notebook files.
PYTHON_FILES=.
MYPY_CACHE=.mypy_cache
lint format: PYTHON_FILES=.
lint_diff format_diff: PYTHON_FILES=$(shell git diff --relative=libs/partners/together --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$')
lint_package: PYTHON_FILES=langchain_together
lint_tests: PYTHON_FILES=tests
lint_tests: MYPY_CACHE=.mypy_cache_test

lint lint_diff lint_package lint_tests:
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff check $(PYTHON_FILES)
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES) --diff
[ "$(PYTHON_FILES)" = "" ] || mkdir -p $(MYPY_CACHE) && poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)

format format_diff:
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES)
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff check --select I --fix $(PYTHON_FILES)

spell_check:
poetry run codespell --toml pyproject.toml

spell_fix:
poetry run codespell --toml pyproject.toml -w

check_imports: $(shell find langchain_together -name '*.py')
poetry run python ./scripts/check_imports.py $^

######################
# HELP
######################

help:
@echo '----'
@echo 'check_imports - check imports'
@echo 'format - run code formatters'
@echo 'lint - run linters'
@echo 'test - run unit tests'
@echo 'tests - run unit tests'
@echo 'test TEST_FILE=<test_file> - run all tests in file'
28 changes: 28 additions & 0 deletions libs/together/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# langchain-together

This package contains the LangChain integrations for [Together AI](https://www.together.ai/) through their [APIs](https://docs.together.ai/).

## Installation and Setup

- Install the LangChain partner package

```bash
pip install -U langchain-together
```

- Get your Together AI api key from the [Together Dashboard](https://api.together.ai/settings/api-keys) and set it as an environment variable (`TOGETHER_API_KEY`)

## Chat Completions

This package contains the `ChatTogether` class, which is the recommended way to interface with Together AI chat models.

ADD USAGE EXAMPLE HERE.
Can we add this in the langchain docs?

NEED to add image endpoint + completions endpoint as well

## Embeddings

See a [usage example](https://python.langchain.com/docs/integrations/text_embedding/together/)

Use `togethercomputer/m2-bert-80M-8k-retrieval` as the default model for embeddings.
7 changes: 7 additions & 0 deletions libs/together/langchain_together/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""This package provides the Together integration for LangChain."""

from langchain_together.chat_models import ChatTogether
from langchain_together.embeddings import TogetherEmbeddings
from langchain_together.llms import Together

__all__ = ["ChatTogether", "Together", "TogetherEmbeddings"]
Loading

0 comments on commit 96a9bd4

Please sign in to comment.