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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
76 changes: 35 additions & 41 deletions ionic_langchain/tool.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,54 @@
# Temp inlining of "SDK"
import requests
import dataclasses
from typing import Any

from langchain.tools import AIPluginTool, Tool
from ionic import Ionic as IonicSDK
from ionic.models.components import QueryAPIRequest, Query
from ionic.models.operations import QuerySecurity, QueryResponse
from langchain.tools import Tool

from ionic_langchain.prompt import TOOL_PROMPT


class Ionic:
PROD_SERVER = "https://api.ionicapi.com"

def __init__(self, base_url=None):
self.base_url = base_url or self.PROD_SERVER

def query(self, queries: str):
url = f"{self.base_url}/query"

query_list = [{"query": query} for query in queries.split(", ")]

payload = {"queries": query_list}
result = requests.post(url, json=payload)
_sdk: IonicSDK

def __init__(self):
self._sdk = IonicSDK()

def query(self, queries: str) -> dict[str, Any]:
"""
FIXME: handle non-200 responses
TODO: better typing in response
"""
request = QueryAPIRequest(
queries=[
Query(query=query)
for query in queries.split(", ")
],
)
response: QueryResponse = self._sdk.query(
request=request,
security=QuerySecurity(),
)

return result.json()
return dataclasses.asdict(response)


# TODO StructuredTool or BaseTool
# https://github.com/langchain-ai/langchain/issues/4197
# https://python.langchain.com/docs/modules/agents/tools/multi_input_tool
# https://github.com/langchain-ai/langchain/issues/4197
# https://python.langchain.com/docs/modules/agents/tools/multi_input_tool


class IonicTool():
def __init__(self, base_url=None):
self.ionic = Ionic()
class IonicTool:
_ionic: Ionic

if base_url:
self.ionic.base_url = base_url
def __init__(self):
self._ionic = Ionic()

def tool(self):
def tool(self) -> Tool:
return Tool(
func=self.ionic.query,
func=self._ionic.query,
name="Ionic Shopping",
description=TOOL_PROMPT,
verbose=True
)




class IonicPluginTool():
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@owensims1 is this still relevant? I see it commented out in the demobot

Copy link
Contributor

Choose a reason for hiding this comment

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

there's gonna be two ways to integrate a langchsin tool-- first is using the sdk which is how i had been using since the beginning.

this is the second, where after we built the openai plugin route, we noticed that langchsin has an integration solution for this, but i found it to not work anywhere near as well as advertised, and i lost interest in pursuing at the time.

so, feel free to remove entirely for now until we can bring it back in an official capacity. let's stick with the sdk connection that affords us a bit more control

def __init__(self, base_url="https://api.ionicapi.com"):
self.base_url = base_url

def tool(self):
# tool = AIPluginTool.from_plugin_url("https://www.klarna.com/.well-known/ai-plugin.json")
tool = AIPluginTool.from_plugin_url(f'{self.base_url}/.well-known/ai-plugin.json')
print(tool)

return tool


Loading