Skip to content
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
67 changes: 63 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jdmccarty I opted to write my own copy here but please suggest improvements. As a developer the website copy doesn't tell me a lot in plain english about what the tool is doing.


## 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.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've never written a public package; not sure about python version compatibility or how we should be managing that. I figure we don't need that right away but IMO worth figuring out.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should only support the latest LTS for the start.

When someone pays us money and needs a specific version that's another story imo.


You can install the package from GitHub using `pip`:

```sh
python3 -m 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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

more or less adapting what we have written in our demobot; happy to make modifications.

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.
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ packages = [{include = "ionic_langchain"}]

[tool.poetry.dependencies]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we want to add more metadata here in the effort towards publishing on PyPI?

https://packaging.python.org/en/latest/tutorials/packaging-projects/#configuring-metadata

Copy link
Contributor

Choose a reason for hiding this comment

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

Eventually 💯

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]
Expand Down