From c22318d808879a9400acd37f509a80c7c6acc801 Mon Sep 17 00:00:00 2001 From: Gregory Kohler Date: Thu, 21 Dec 2023 13:49:49 -0800 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=93=A6=20fleixble=20langchain=20depen?= =?UTF-8?q?dency;=20pinned=20sdk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Idea here being we control which SDK version is being used but allow developers to have higher patch versions of langchain. https://python-poetry.org/docs/dependency-specification/#tilde-requirements --- poetry.lock | 10 +++++----- pyproject.toml | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/poetry.lock b/poetry.lock index 0f4c314..41fb9cc 100644 --- a/poetry.lock +++ b/poetry.lock @@ -519,13 +519,13 @@ files = [ [[package]] name = "langchain" -version = "0.0.350" +version = "0.0.352" description = "Building applications with LLMs through composability" optional = false python-versions = ">=3.8.1,<4.0" files = [ - {file = "langchain-0.0.350-py3-none-any.whl", hash = "sha256:11b605f325a4271a7815baaec05bc7622e3ad1f10f26b05c752cafa27663ed38"}, - {file = "langchain-0.0.350.tar.gz", hash = "sha256:f0e68a92d200bb722586688ab7b411b2430bd98ad265ca03b264e7e7acbb6c01"}, + {file = "langchain-0.0.352-py3-none-any.whl", hash = "sha256:43ab580e1223e5d7c3495b3c0cb79e2f3a0ecb52caf8126271fb10d42cede2d0"}, + {file = "langchain-0.0.352.tar.gz", hash = "sha256:8928d7b63d73af9681fe1b2a2b99b84238efef61ed537de666160fd001f41efd"}, ] [package.dependencies] @@ -534,7 +534,7 @@ dataclasses-json = ">=0.5.7,<0.7" jsonpatch = ">=1.33,<2.0" langchain-community = ">=0.0.2,<0.1" langchain-core = ">=0.1,<0.2" -langsmith = ">=0.0.63,<0.1.0" +langsmith = ">=0.0.70,<0.1.0" numpy = ">=1,<2" pydantic = ">=1,<3" PyYAML = ">=5.3" @@ -1292,4 +1292,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "34ba224fd185ba84f4c6142a1924b934d6944d4713e6d298392f57c9ae7cd2a3" +content-hash = "57edf40b36d52151927170f79c7fa0e91a8c9d67c83c24de084340b23e93a098" diff --git a/pyproject.toml b/pyproject.toml index 814e31b..65b209d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,8 +8,8 @@ packages = [{include = "ionic_langchain"}] [tool.poetry.dependencies] python = "^3.11" -langchain = "0.0.350" -ionic-api-sdk = "^0.5.2" +langchain = "~0.0.352" +ionic-api-sdk = "0.5.2" [build-system] From 8e15d8886ab95cdd9ff182be18d0d9a8d77dba6a Mon Sep 17 00:00:00 2001 From: Gregory Kohler Date: Thu, 21 Dec 2023 15:06:53 -0800 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=96=20first=20pass=20at=20document?= =?UTF-8?q?ation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a24e0ac..2878214 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,74 @@ # Ionic Langchain -Pre-release. Do not use this. +Ionic Langchain provides a wrapper around the Ionic Commerce's SDK for use as a `Tool` in a custom Langchain agent. This tool will enable e-commerce for your agent, allowing your users to ask for product recommendations and purchase products through the agent chat interface. ## Installation -Pre-release. Do not use this. +This tool requires at least `langchain@0.0.350` and can work with any greater patch release the `0.0.x` series. + +You can install the package from GitHub using `pip`: + +```sh +pip install git+https://github.com/ioniccommerce/ionic_langchain.git#v0.1.2 +``` + +or `poetry`: + +```sh +poetry add git+https://github.com/ioniccommerce/ionic_langchain.git#v0.1.2 +``` ## Usage -Pre-release. Do not use this. +```python +import os +from typing import List + +from ionic_langchain.tool import IonicTool +from langchain.agents import AgentType, Tool +from langchain.agents import initialize_agent +from langchain.chat_models import ChatOpenAI +from langchain.memory import ConversationBufferWindowMemory, RedisChatMessageHistory + + +tools: List[Tool] = [ + IonicTool().tool(), + # others, +] +redis_memory = RedisChatMessageHistory(url=os.environ.get("REDIS_URL"),session_id="chatId"), +memory = ConversationBufferWindowMemory( + k=12, + return_messages=True, + chat_memory=redis_memory, + memory_key="chat_history", +) + +agent = initialize_agent( + tools=tools, + llm=ChatOpenAI(openai_api_key=os.environ.get("OPENAI_API_KEY"),temperature=0.5), + agent=AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION, + memory=memory, + handle_parsing_errors=True, + verbose=True, +) + +agent.run(input="Roadhouse VHS") +``` +### Customizing the SDK + +`ionic_langchain.tool.IonicTool`'s constructor accepts an instance of `ionic_langchain.tool.Ionic`, a wrapper around [our SDK](https://pypi.org/project/Ionic-API-SDK/). `ionic_langchain.tool.Ionic`, in turn accepts an instance of that SDK, so you can provide the tool with a custom configuration: + +```python +import os +from ionic.sdk import Ionic as IonicSDK +from ionic_langchain.tool import Ionic, IonicTool + + +sdk = IonicSDK(api_key_header=os.environ.get("IONIC_API_KEY")) +ionic = Ionic(sdk=sdk) +tool = IonicTool(ionic=ionic).tool() +``` ## Development -Pre-release. Do not use this. +Ionic Langchain is not currently accepting external contributions. Contact us via [this form](https://ionicapi.com/contact) if you would like to contribute. From cc84198ab2d071a905abf205ac1cae87fe8b5aa8 Mon Sep 17 00:00:00 2001 From: Gregory M Kohler Date: Thu, 21 Dec 2023 15:28:40 -0800 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2878214..82bacab 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This tool requires at least `langchain@0.0.350` and can work with any greater pa You can install the package from GitHub using `pip`: ```sh -pip install git+https://github.com/ioniccommerce/ionic_langchain.git#v0.1.2 +python3 -m pip install git+https://github.com/ioniccommerce/ionic_langchain.git#v0.1.2 ``` or `poetry`: