From 83cd6f8e2c91a1e916e799c0c02310b6b38deb75 Mon Sep 17 00:00:00 2001 From: Shroominic Date: Sun, 10 Mar 2024 13:18:10 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20Update=20dependencies=20and=20re?= =?UTF-8?q?factor=20code=20to=20use=20new=20langchain=20libraries?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 31 ++- requirements-dev.lock | 370 +++++++++++++++++++++++++++++--- requirements.lock | 76 +++++-- src/funcchain/model/defaults.py | 24 ++- 4 files changed, 434 insertions(+), 67 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 24ea58d..e2d527e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,12 +4,11 @@ version = "0.3.1" description = "🔖 write prompts as python functions" authors = [{ name = "Shroominic", email = "contact@shroominic.com" }] dependencies = [ - "langchain_core>=0.1", + "langchain-core>=0.1", "pydantic-settings>=2", "docstring-parser>=0.15", "jinja2>=3", - "openai>=1.12", - "tiktoken>=0.6", + "langchain-openai>=0.0.8", ] license = "MIT" readme = "README.md" @@ -56,18 +55,28 @@ dev-dependencies = [ ] [project.optional-dependencies] -openai = ["langchain_openai"] -ollama = ["langchain_community"] -llamacpp = ["llama-cpp-python>=0.2.32", "huggingface_hub>=0.20"] -pillow = ["pillow"] -example-extras = ["langchain>=0.1", "faiss-cpu>=1.7.4", "beautifulsoup4>=4.12"] +openai = ["langchain-openai"] +ollama = ["langchain-community"] +anthropic = ["langchain-anthropic"] +google = ["langchain-google-genai"] +llamacpp = ["llama-cpp-python>=0.2.32", "huggingface-hub>=0.20"] +image = ["pillow"] +extras = [ + "langchain>=0.1", + "faiss-cpu>=1.7.4", + "beautifulsoup4>=4.12", + "unstructured>=0.12.5", + "pdf2image>=1.17.0", + "pdfminer>=20191125", +] all = [ - "funcchain[pillow]", + "funcchain[image]", "funcchain[openai]", + "funcchain[google]", "funcchain[ollama]", "funcchain[llamacpp]", - "funcchain[example-extras]", - "langchain", + "funcchain[anthropic]", + "funcchain[extras]", ] [tool.hatch.metadata] diff --git a/requirements-dev.lock b/requirements-dev.lock index ccccfc1..3d71d8e 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -9,110 +9,414 @@ -e file:. aiohttp==3.9.3 + # via langchain + # via langchain-community aiosignal==1.3.1 + # via aiohttp annotated-types==0.6.0 -anyio==4.2.0 + # via pydantic +anthropic==0.19.1 + # via langchain-anthropic +anyio==4.3.0 + # via anthropic + # via httpx + # via langchain-core + # via openai asttokens==2.4.1 -async-timeout==4.0.3 + # via stack-data attrs==23.2.0 + # via aiohttp babel==2.14.0 + # via mkdocs-material +backoff==2.2.1 + # via unstructured beautifulsoup4==4.12.3 + # via funcchain + # via unstructured +cachetools==5.3.3 + # via google-auth certifi==2024.2.2 + # via httpcore + # via httpx + # via requests + # via unstructured + # via unstructured-client cfgv==3.4.0 + # via pre-commit +chardet==5.2.0 + # via unstructured charset-normalizer==3.3.2 + # via requests + # via unstructured + # via unstructured-client click==8.1.7 + # via mkdocs + # via nltk + # via unstructured colorama==0.4.6 + # via mkdocs-material dataclasses-json==0.6.4 + # via langchain + # via langchain-community + # via unstructured +dataclasses-json-speakeasy==0.5.11 + # via unstructured + # via unstructured-client decorator==5.1.1 + # via ipython +defusedxml==0.7.1 + # via langchain-anthropic diskcache==5.6.3 + # via llama-cpp-python distlib==0.3.8 + # via virtualenv distro==1.9.0 + # via anthropic + # via openai docstring-parser==0.15 -exceptiongroup==1.2.0 + # via funcchain +emoji==2.10.1 + # via unstructured executing==2.0.1 -faiss-cpu==1.7.4 + # via stack-data +faiss-cpu==1.8.0 + # via funcchain filelock==3.13.1 + # via huggingface-hub + # via virtualenv +filetype==1.2.0 + # via unstructured frozenlist==1.4.1 + # via aiohttp + # via aiosignal fsspec==2024.2.0 + # via huggingface-hub ghp-import==2.1.0 + # via mkdocs +google-ai-generativelanguage==0.4.0 + # via google-generativeai +google-api-core==2.17.1 + # via google-ai-generativelanguage + # via google-generativeai +google-auth==2.28.2 + # via google-api-core + # via google-generativeai +google-generativeai==0.3.2 + # via langchain-google-genai +googleapis-common-protos==1.62.0 + # via google-api-core + # via grpcio-status +grpcio==1.62.1 + # via google-api-core + # via grpcio-status +grpcio-status==1.62.1 + # via google-api-core h11==0.14.0 -httpcore==1.0.3 -httpx==0.26.0 -huggingface-hub==0.20.3 -identify==2.5.34 + # via httpcore +httpcore==1.0.4 + # via httpx +httpx==0.27.0 + # via anthropic + # via openai +huggingface-hub==0.21.4 + # via funcchain + # via tokenizers +identify==2.5.35 + # via pre-commit idna==3.6 + # via anyio + # via httpx + # via requests + # via unstructured + # via unstructured-client + # via yarl iniconfig==2.0.0 -ipython==8.21.0 + # via pytest +ipython==8.22.2 isort==5.13.2 jedi==0.19.1 + # via ipython jinja2==3.1.3 + # via funcchain + # via llama-cpp-python + # via mkdocs + # via mkdocs-material +joblib==1.3.2 + # via nltk + # via unstructured jsonpatch==1.33 + # via langchain + # via langchain-core +jsonpath-python==1.0.6 + # via unstructured + # via unstructured-client jsonpointer==2.4 -langchain==0.1.7 -langchain-community==0.0.20 -langchain-core==0.1.23 -langchain-openai==0.0.6 -langsmith==0.0.87 -llama-cpp-python==0.2.44 + # via jsonpatch +langchain==0.1.11 + # via funcchain +langchain-anthropic==0.1.4 + # via funcchain +langchain-community==0.0.27 + # via funcchain + # via langchain +langchain-core==0.1.30 + # via funcchain + # via langchain + # via langchain-anthropic + # via langchain-community + # via langchain-google-genai + # via langchain-openai + # via langchain-text-splitters +langchain-google-genai==0.0.9 + # via funcchain +langchain-openai==0.0.8 + # via funcchain +langchain-text-splitters==0.0.1 + # via langchain +langdetect==1.0.9 + # via unstructured +langsmith==0.1.23 + # via langchain + # via langchain-community + # via langchain-core +llama-cpp-python==0.2.55 + # via funcchain +lxml==5.1.0 + # via unstructured markdown==3.5.2 + # via mkdocs + # via mkdocs-material + # via pymdown-extensions markdown-it-py==3.0.0 + # via rich markupsafe==2.1.5 + # via jinja2 + # via mkdocs marshmallow==3.20.2 + # via dataclasses-json + # via dataclasses-json-speakeasy + # via unstructured + # via unstructured-client matplotlib-inline==0.1.6 + # via ipython mdurl==0.1.2 + # via markdown-it-py mergedeep==1.3.4 + # via mkdocs mkdocs==1.5.3 -mkdocs-material==9.5.9 + # via mkdocs-material +mkdocs-material==9.5.13 mkdocs-material-extensions==1.3.1 + # via mkdocs-material multidict==6.0.5 -mypy==1.8.0 + # via aiohttp + # via yarl +mypy==1.9.0 mypy-extensions==1.0.0 + # via mypy + # via typing-inspect + # via unstructured + # via unstructured-client +nltk==3.8.1 + # via unstructured nodeenv==1.8.0 + # via pre-commit numpy==1.26.4 -openai==1.12.0 + # via faiss-cpu + # via langchain + # via langchain-community + # via llama-cpp-python + # via unstructured +openai==1.13.3 + # via langchain-openai +orjson==3.9.15 + # via langsmith packaging==23.2 + # via huggingface-hub + # via langchain-core + # via marshmallow + # via mkdocs + # via pytest + # via unstructured + # via unstructured-client paginate==0.5.6 + # via mkdocs-material parso==0.8.3 + # via jedi pathspec==0.12.1 + # via mkdocs +pdf2image==1.17.0 + # via funcchain +pdfminer==20191125 + # via funcchain pexpect==4.9.0 + # via ipython pillow==10.2.0 + # via funcchain + # via pdf2image platformdirs==4.2.0 + # via mkdocs + # via virtualenv pluggy==1.4.0 -pre-commit==3.6.1 + # via pytest +pre-commit==3.6.2 prompt-toolkit==3.0.43 + # via ipython +proto-plus==1.23.0 + # via google-ai-generativelanguage +protobuf==4.25.3 + # via google-ai-generativelanguage + # via google-api-core + # via google-generativeai + # via googleapis-common-protos + # via grpcio-status + # via proto-plus ptyprocess==0.7.0 + # via pexpect pure-eval==0.2.2 -pydantic==2.6.1 -pydantic-core==2.16.2 -pydantic-settings==2.2.0 + # via stack-data +pyasn1==0.5.1 + # via pyasn1-modules + # via rsa +pyasn1-modules==0.3.0 + # via google-auth +pycryptodome==3.20.0 + # via pdfminer +pydantic==2.6.3 + # via anthropic + # via langchain + # via langchain-core + # via langsmith + # via openai + # via pydantic-settings +pydantic-core==2.16.3 + # via pydantic +pydantic-settings==2.2.1 + # via funcchain pygments==2.17.2 -pymdown-extensions==10.7 -pytest==8.0.1 + # via ipython + # via mkdocs-material + # via rich +pymdown-extensions==10.7.1 + # via mkdocs-material +pytest==8.0.2 python-dateutil==2.8.2 + # via ghp-import + # via unstructured + # via unstructured-client python-dotenv==1.0.1 + # via pydantic-settings +python-iso639==2024.2.7 + # via unstructured +python-magic==0.4.27 + # via unstructured pyyaml==6.0.1 + # via huggingface-hub + # via langchain + # via langchain-community + # via langchain-core + # via mkdocs + # via pre-commit + # via pymdown-extensions + # via pyyaml-env-tag pyyaml-env-tag==0.1 + # via mkdocs +rapidfuzz==3.6.1 + # via unstructured regex==2023.12.25 + # via mkdocs-material + # via nltk + # via tiktoken + # via unstructured requests==2.31.0 -rich==13.7.0 -ruff==0.2.1 + # via google-api-core + # via huggingface-hub + # via langchain + # via langchain-community + # via langchain-core + # via langsmith + # via mkdocs-material + # via tiktoken + # via unstructured + # via unstructured-client +rich==13.7.1 +rsa==4.9 + # via google-auth +ruff==0.3.2 +setuptools==69.1.1 + # via nodeenv six==1.16.0 -sniffio==1.3.0 + # via asttokens + # via langdetect + # via python-dateutil + # via unstructured + # via unstructured-client +sniffio==1.3.1 + # via anthropic + # via anyio + # via httpx + # via openai soupsieve==2.5 -sqlalchemy==2.0.27 + # via beautifulsoup4 + # via unstructured +sqlalchemy==2.0.28 + # via langchain + # via langchain-community stack-data==0.6.3 + # via ipython +tabulate==0.9.0 + # via unstructured tenacity==8.2.3 + # via langchain + # via langchain-community + # via langchain-core tiktoken==0.6.0 -tomli==2.0.1 + # via langchain-openai +tokenizers==0.15.2 + # via anthropic tqdm==4.66.2 + # via google-generativeai + # via huggingface-hub + # via nltk + # via openai + # via unstructured traitlets==5.14.1 + # via ipython + # via matplotlib-inline types-pyyaml==6.0.12.12 typing-extensions==4.9.0 + # via anthropic + # via google-generativeai + # via huggingface-hub + # via llama-cpp-python + # via mypy + # via openai + # via pydantic + # via pydantic-core + # via sqlalchemy + # via typing-inspect + # via unstructured + # via unstructured-client typing-inspect==0.9.0 -urllib3==2.2.0 -virtualenv==20.25.0 + # via dataclasses-json + # via dataclasses-json-speakeasy + # via unstructured + # via unstructured-client +unstructured==0.12.6 + # via funcchain +unstructured-client==0.18.0 + # via unstructured +urllib3==1.26.18 + # via requests + # via unstructured + # via unstructured-client +virtualenv==20.25.1 + # via pre-commit watchdog==4.0.0 + # via mkdocs wcwidth==0.2.13 + # via prompt-toolkit +wrapt==1.16.0 + # via unstructured yarl==1.9.4 -# The following packages are considered to be unsafe in a requirements file: -setuptools==69.1.0 + # via aiohttp diff --git a/requirements.lock b/requirements.lock index 277c731..ec819bd 100644 --- a/requirements.lock +++ b/requirements.lock @@ -9,34 +9,84 @@ -e file:. annotated-types==0.6.0 -anyio==4.2.0 + # via pydantic +anyio==4.3.0 + # via httpx + # via langchain-core + # via openai certifi==2024.2.2 + # via httpcore + # via httpx + # via requests charset-normalizer==3.3.2 + # via requests distro==1.9.0 + # via openai docstring-parser==0.15 -exceptiongroup==1.2.0 + # via funcchain h11==0.14.0 -httpcore==1.0.3 -httpx==0.26.0 + # via httpcore +httpcore==1.0.4 + # via httpx +httpx==0.27.0 + # via openai idna==3.6 + # via anyio + # via httpx + # via requests jinja2==3.1.3 + # via funcchain jsonpatch==1.33 + # via langchain-core jsonpointer==2.4 -langchain-core==0.1.23 -langsmith==0.0.87 + # via jsonpatch +langchain-core==0.1.30 + # via funcchain + # via langchain-openai +langchain-openai==0.0.8 + # via funcchain +langsmith==0.1.23 + # via langchain-core markupsafe==2.1.5 -openai==1.12.0 + # via jinja2 +openai==1.13.3 + # via langchain-openai +orjson==3.9.15 + # via langsmith packaging==23.2 -pydantic==2.6.1 -pydantic-core==2.16.2 -pydantic-settings==2.2.0 + # via langchain-core +pydantic==2.6.3 + # via langchain-core + # via langsmith + # via openai + # via pydantic-settings +pydantic-core==2.16.3 + # via pydantic +pydantic-settings==2.2.1 + # via funcchain python-dotenv==1.0.1 + # via pydantic-settings pyyaml==6.0.1 + # via langchain-core regex==2023.12.25 + # via tiktoken requests==2.31.0 -sniffio==1.3.0 + # via langchain-core + # via langsmith + # via tiktoken +sniffio==1.3.1 + # via anyio + # via httpx + # via openai tenacity==8.2.3 + # via langchain-core tiktoken==0.6.0 + # via langchain-openai tqdm==4.66.2 -typing-extensions==4.9.0 -urllib3==2.2.0 + # via openai +typing-extensions==4.10.0 + # via openai + # via pydantic + # via pydantic-core +urllib3==2.2.1 + # via requests diff --git a/src/funcchain/model/defaults.py b/src/funcchain/model/defaults.py index 9f19475..9b981bc 100644 --- a/src/funcchain/model/defaults.py +++ b/src/funcchain/model/defaults.py @@ -110,20 +110,22 @@ def univeral_model_selector( try: match mtype: case "openai": - from .patches import ChatOpenAI + from langchain_openai import ChatOpenAI model_kwargs.update(settings.openai_kwargs()) return ChatOpenAI(**model_kwargs) case "anthropic": - from langchain_community.chat_models import ChatAnthropic + from langchain_anthropic import ChatAnthropic + + model_kwargs.pop("streaming", None) return ChatAnthropic(**model_kwargs) case "google": - from langchain_community.chat_models import ChatGooglePalm + from langchain_google_genai import ChatGoogleGenerativeAI - return ChatGooglePalm(**model_kwargs) + return ChatGoogleGenerativeAI(**model_kwargs) case "ollama": from .patches.ollama import ChatOllama @@ -151,7 +153,7 @@ def univeral_model_selector( try: if "gpt-4" in name or "gpt-3.5" in name: - from .patches import ChatOpenAI + from langchain_openai.chat_models import ChatOpenAI model_kwargs.update(settings.openai_kwargs()) return ChatOpenAI(**model_kwargs) @@ -162,25 +164,27 @@ def univeral_model_selector( model_kwargs.pop("model_name", None) if settings.openai_api_key: - from .patches import ChatOpenAI + from langchain_openai import ChatOpenAI model_kwargs.update(settings.openai_kwargs()) return ChatOpenAI(**model_kwargs) if settings.azure_api_key: - from .patches import AzureChatOpenAI + from langchain_openai import AzureChatOpenAI return AzureChatOpenAI(**model_kwargs) if settings.anthropic_api_key: - from langchain_community.chat_models import ChatAnthropic + from langchain_anthropic import ChatAnthropic + + model_kwargs.pop("streaming", None) return ChatAnthropic(**model_kwargs) if settings.google_api_key: - from langchain_community.chat_models import ChatGooglePalm + from langchain_google_genai import ChatGoogleGenerativeAI - return ChatGooglePalm(**model_kwargs) + return ChatGoogleGenerativeAI(**model_kwargs) raise ValueError( "Could not read llm selector string. Please check "