-
Notifications
You must be signed in to change notification settings - Fork 0
📖 [ION-283] document langchain tool #5
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||
|
|
||
| ## 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. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,8 @@ packages = [{include = "ionic_langchain"}] | |
|
|
||
| [tool.poetry.dependencies] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] | ||
|
|
||
There was a problem hiding this comment.
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.