Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use poetry for optional deps #12

Merged
merged 6 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/publish_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.x"
- uses: Gr1N/setup-poetry@v8
- uses: actions/cache@v2
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
run: make install

- name: Setup Node.js
uses: actions/setup-node@v2
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,21 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: "3.x"
- uses: Gr1N/setup-poetry@v8
- uses: actions/cache@v2
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
run: make install

- name: Build package
run: python -m build

- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.x"
- uses: Gr1N/setup-poetry@v8
- uses: actions/cache@v2
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
run: make install

- name: Run tests
run: make doctest && make test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ build/
langstream.egg-info/
.chroma
litellm_uuid.txt
/dist

# Generated markdown files from jupyter notebooks
docs/docs/examples/*.md
!docs/docs/examples/index.md
!docs/docs/examples/index.md

1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
.PHONY: test doctest test-integration docs install

test:
PYTHONPATH=$$PYTHONPATH:. pytest -s -m "not integration" $(filter-out $@,$(MAKECMDGOALS))
PYTHONPATH=$$PYTHONPATH:. poetry run pytest -s -m "not integration" $(filter-out $@,$(MAKECMDGOALS))

test-integration:
PYTHONPATH=$$PYTHONPATH:. pytest -s -m integration $(filter-out $@,$(MAKECMDGOALS))
PYTHONPATH=$$PYTHONPATH:. poetry run pytest -s -m integration $(filter-out $@,$(MAKECMDGOALS))

doctest:
PYTHONPATH=$$PYTHONPATH:. pytest --doctest-modules langstream/utils && PYTHONPATH=$PYTHONPATH:. pytest --doctest-modules langstream/core && PYTHONPATH=$PYTHONPATH:. pytest --doctest-modules langstream/contrib/llms
PYTHONPATH=$$PYTHONPATH:. poetry run pytest --doctest-modules langstream/utils && PYTHONPATH=$PYTHONPATH:. poetry run pytest --doctest-modules langstream/core && PYTHONPATH=$PYTHONPATH:. poetry run pytest --doctest-modules langstream/contrib/llms

nbtest:
nbdoc_test --fname docs/docs/
poetry run nbdoc_test --fname docs/docs/

docs:
make pdocs && make nbdocs && cd docs && npm run build

pdocs:
pdoc --html -o ./docs/static/reference --template-dir ./docs/pdoc_template langstream --force
poetry run pdoc --html -o ./docs/static/reference --template-dir ./docs/pdoc_template langstream --force

nbdocs:
nbdoc_build --srcdir docs/docs
poetry run nbdoc_build --srcdir docs/docs

docs-dev-server:
cd docs && npm start

install:
pip install -r requirements.txt
@if ! command -v poetry &> /dev/null; then \
curl -sSL https://install.python-poetry.org | python3 -; \
fi
poetry install --all-extras

%:
@:
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ LangStream is a lighter alternative to LangChain for building LLMs application,
# Quick Install

```
pip install langstream
pip install langstream openai
```

# 🔗 The Stream building block
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ LangStream also puts emphasis on "explicit is better than implicit", which means

## Getting Started

You can install it with pip:
You can install langstream with pip + a model provider (like openai, gpt4all or litellm):

```
pip install langstream
pip install langstream openai
```

## Your First Stream
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/llms/gpt4all.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ sidebar_position: 4

LLMs require a lot of GPU to run properly make it hard for the common folk to set one up locally. Fortunately, the folks at [GPT4All](https://gpt4all.io/index.html) are doing an excellent job in really reducing those models with various techniques, and speeding them up to run on CPUs everywhere with no issues. LangStream also provides a thin wrapper for them, and since it's local, no API keys are required.

Make sure you have GPT4All installed:

```
pip install gpt4all
```

# GPT4AllStream

You can use a [`GPT4AllStream`](pathname:///reference/langstream/contrib/index.html#langstream.contrib.GPT4AllStream) like this:
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/llms/lite_llm.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export ANTHROPIC_API_KEY=<your key here>
export HUGGINGFACE_API_KEY=<your key here>
```

Make sure you have LiteLLM installed:

```
pip install litellm
```

Then, you should be able to use the [`LiteLLMChatStream`](pathname:///reference/langstream/contrib/index.html#langstream.contrib.LiteLLMChatStream), which has basically the same interface as as the [`OpenAIChatStream`](pathname:///reference/langstream/contrib/index.html#langstream.contrib.OpenAIChatStream), check it out:

## Chat Completion
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/llms/open_ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ OpenAI took the world by storm with the launch of ChatGPT and GPT-4, at the poin
export OPENAI_API_KEY=<your key here>
```

Make sure you have OpenAI library installed:

```
pip install openai
```

Then, LangStream provides two thin wrapper layers for their APIs:

## Text Completion
Expand Down
3 changes: 2 additions & 1 deletion langstream/contrib/llms/gpt4all_stream.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
from typing import AsyncGenerator, Callable, Iterable, Optional, TypeVar, cast

from gpt4all import GPT4All
import importlib

from langstream.core.stream import Stream

Expand Down Expand Up @@ -65,6 +65,7 @@ def __init__(
n_batch=8,
n_threads: Optional[int] = None,
) -> None:
GPT4All = importlib.import_module("gpt4all").GPT4All
gpt4all = GPT4All(model, n_threads=n_threads)

async def generate(prompt: str) -> AsyncGenerator[U, None]:
Expand Down
4 changes: 2 additions & 2 deletions langstream/contrib/llms/lite_llm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
from dataclasses import dataclass
import itertools
from types import GeneratorType
from typing import (
Any,
Expand All @@ -15,7 +14,7 @@
cast,
)

import litellm
import importlib
from colorama import Fore
from retry import retry

Expand Down Expand Up @@ -232,6 +231,7 @@ def get_completions():
if function_call is not None:
function_kwargs["function_call"] = function_call

litellm = importlib.import_module("litellm")
return litellm.completion(
request_timeout=timeout,
model=model,
Expand Down
4 changes: 3 additions & 1 deletion langstream/contrib/llms/open_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
cast,
)

import openai
import importlib
from colorama import Fore
from retry import retry

Expand Down Expand Up @@ -73,6 +73,7 @@ async def completion(prompt: str) -> AsyncGenerator[U, None]:

@retry(tries=retries)
def get_completions():
openai = importlib.import_module("openai")
return openai.Completion.create(
model=model,
prompt=prompt,
Expand Down Expand Up @@ -294,6 +295,7 @@ def get_completions():
if function_call is not None:
function_kwargs["function_call"] = function_call

openai = importlib.import_module("openai")
return openai.ChatCompletion.create(
timeout=timeout,
request_timeout=timeout,
Expand Down
Loading
Loading