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

IBM: added partners package langchain_ibm, added llm #16512

Merged
merged 31 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3371f08
add langchain_ibm package, add llm
MateuszOssGit Jan 24, 2024
8dec2a7
Merge branch 'master' into langchain-ibm-package-llm
MateuszOssGit Jan 24, 2024
8b36576
remove integration tests
MateuszOssGit Jan 24, 2024
ca8fa9d
fix python version in pyproject
MateuszOssGit Jan 24, 2024
b53b64a
fix
MateuszOssGit Jan 24, 2024
3e7f350
add init to integration tests
MateuszOssGit Jan 24, 2024
d142afa
add test dependencies
MateuszOssGit Jan 24, 2024
a7dd54c
add test_compile file
MateuszOssGit Jan 24, 2024
7b4db4c
add integration test path in makefile and update docstring in integra…
MateuszOssGit Jan 24, 2024
12530e5
Merge branch 'master' into langchain-ibm-package-llm
MateuszOssGit Jan 25, 2024
727f2be
Merge branch 'master' into langchain-ibm-package-llm
MateuszOssGit Jan 29, 2024
4371159
Merge branch 'master' into langchain-ibm-package-llm
MateuszOssGit Jan 31, 2024
c4a3578
Merge branch 'master' into langchain-ibm-package-llm
MateuszOssGit Feb 1, 2024
8ba77de
Merge branch 'master' into langchain-ibm-package-llm
MateuszOssGit Feb 4, 2024
984433a
Merge branch 'master' into langchain-ibm-package-llm
MateuszOssGit Feb 4, 2024
84b4db9
fix comments
MateuszOssGit Feb 4, 2024
b521062
make format and make lint
MateuszOssGit Feb 4, 2024
1516160
Merge branch 'master' into langchain-ibm-package-llm
MateuszOssGit Feb 5, 2024
599a581
Merge branch 'master' into langchain-ibm-package-llm
MateuszOssGit Feb 5, 2024
74b8408
add integration tests for generate stream and generate with multiple …
MateuszOssGit Feb 5, 2024
b0202ad
Merge branch 'langchain-ibm-package-llm' of https://github.com/Mateus…
MateuszOssGit Feb 5, 2024
86d260b
Merge branch 'master' into langchain-ibm-package-llm
MateuszOssGit Feb 5, 2024
a2853a8
Merge branch 'langchain-ai:master' into langchain-ibm-package-llm
MateuszOssGit Feb 5, 2024
e00918e
Merge branch 'master' into langchain-ibm-package-llm
MateuszOssGit Feb 6, 2024
cdb8ece
Merge branch 'master' into langchain-ibm-package-llm
efriis Feb 6, 2024
bd8f8ba
cr
efriis Feb 6, 2024
b1d44aa
Merge branch 'master' into langchain-ibm-package-llm
MateuszOssGit Feb 7, 2024
0c97462
Merge branch 'master' into langchain-ibm-package-llm
MateuszOssGit Feb 12, 2024
d946c3e
update langchain-core req
MateuszOssGit Feb 12, 2024
093b203
add project id
efriis Feb 14, 2024
b7d1788
Merge branch 'master' into langchain-ibm-package-llm
efriis Feb 14, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/_integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ jobs:
GOOGLE_CSE_ID: ${{ secrets.GOOGLE_CSE_ID }}
EXA_API_KEY: ${{ secrets.EXA_API_KEY }}
NOMIC_API_KEY: ${{ secrets.NOMIC_API_KEY }}
WATSONX_APIKEY: ${{ secrets.WATSONX_APIKEY }}
WATSONX_PROJECT_ID: ${{ secrets.WATSONX_PROJECT_ID }}
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
PINECONE_ENVIRONMENT: ${{ secrets.PINECONE_ENVIRONMENT }}
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ jobs:
GOOGLE_CSE_ID: ${{ secrets.GOOGLE_CSE_ID }}
EXA_API_KEY: ${{ secrets.EXA_API_KEY }}
NOMIC_API_KEY: ${{ secrets.NOMIC_API_KEY }}
WATSONX_APIKEY: ${{ secrets.WATSONX_APIKEY }}
WATSONX_PROJECT_ID: ${{ secrets.WATSONX_PROJECT_ID }}
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
PINECONE_ENVIRONMENT: ${{ secrets.PINECONE_ENVIRONMENT }}
run: make integration_tests
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/ibm_watsonx.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.llms import WatsonxLLM\n",
"from langchain_ibm import WatsonxLLM\n",
"\n",
"watsonx_llm = WatsonxLLM(\n",
" model_id=\"google/flan-ul2\",\n",
Expand Down
7 changes: 4 additions & 3 deletions libs/community/langchain_community/llms/watsonxllm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from typing import Any, Dict, Iterator, List, Mapping, Optional, Union

from langchain_core._api.deprecation import deprecated
from langchain_core.callbacks import CallbackManagerForLLMRun
from langchain_core.language_models.llms import BaseLLM
from langchain_core.outputs import Generation, GenerationChunk, LLMResult
Expand All @@ -11,6 +12,9 @@
logger = logging.getLogger(__name__)


@deprecated(
since="0.0.18", removal="0.2", alternative_import="langchain_ibm.WatsonxLLM"
)
class WatsonxLLM(BaseLLM):
"""
IBM watsonx.ai large language models.
Expand Down Expand Up @@ -293,9 +297,6 @@ def _stream_response_to_generation_chunk(
generation_info=dict(
finish_reason=stream_response["results"][0].get("stop_reason", None),
llm_output={
"generated_token_count": stream_response["results"][0].get(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this creating failures? Why is this removed?

Copy link
Contributor Author

@MateuszOssGit MateuszOssGit Feb 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@efriis I was getting error TypeError: Additional kwargs key generated_token_count already exists in left dict and value has unsupported type <class 'int'>. when i used stream method:

for a in watsonx_llm.stream("Write poem to sun"):
    print(a, end='')

or

for a in watsonx_llm.generate(prompts=["Write poem to sun"], stream=True):
    print(a)

The error is related with merge_dicts method in langchain_core.utils._merge

"generated_token_count", None
),
"model_id": self.model_id,
"deployment_id": self.deployment_id,
},
Expand Down
1 change: 1 addition & 0 deletions libs/partners/ibm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
21 changes: 21 additions & 0 deletions libs/partners/ibm/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 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.
58 changes: 58 additions & 0 deletions libs/partners/ibm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.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/ibm --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$')
lint_package: PYTHON_FILES=langchain_ibm
lint_tests: PYTHON_FILES=tests
lint_tests: MYPY_CACHE=.mypy_cache_test

lint lint_diff lint_package lint_tests:
poetry run ruff .
poetry run ruff format $(PYTHON_FILES) --diff
poetry run ruff --select I $(PYTHON_FILES)
mkdir $(MYPY_CACHE); poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)

format format_diff:
poetry run ruff format $(PYTHON_FILES)
poetry run ruff --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_ibm -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'
18 changes: 18 additions & 0 deletions libs/partners/ibm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# langchain-ibm

This package contains the LangChain integrations for IBM watsonx.ai through their `ibm-watsonx-ai` SDK.

## Installation and Setup

- Install the LangChain partner package
```bash
pip install langchain-ibm
```

## LLM

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

```python
from langchain_ibm import WatsonxLLM
```
3 changes: 3 additions & 0 deletions libs/partners/ibm/langchain_ibm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from langchain_ibm.llms import WatsonxLLM

__all__ = ["WatsonxLLM"]
Loading
Loading