from ionic_langchain.tool import IonicToolfrom langchain import hubfrom langchain.agents import AgentExecutor, create_openai_tools_agentfrom langchain_openai import ChatOpenAI# Based on OpenAI Tools Agent# https://python.langchain.com/docs/modules/agents/agent_types/openai_toolsmodel = "gpt-3.5-turbo-1106"temperature = 0.6# Choose the LLM that will drive the agent# Only certain models support thisllm = ChatOpenAI(model=model, temperature=temperature, openai_api_key=openai_api_key)ionic_tool = IonicTool().tool()# The tool comes with its own prompt,# but you may also update it directly via the description attribute:ionic_tool.description = str( """Ionic is an e-commerce shopping tool. Assistant uses the Ionic Commerce Shopping Tool to find, discover, and compare products from thousands of online retailers. Assistant should use the tool when the user is looking for a product recommendation or trying to find a specific product.The user may specify the number of results, minimum price, and maximum price for which they want to see results.Ionic Tool input is a comma-separated string of values: - query string (required, must not include commas) - number of results (default to 4, no more than 10) - minimum price in cents ($5 becomes 500) - maximum price in centsFor example, if looking for coffee beans between 5 and 10 dollars, the tool input would be `coffee beans, 5, 500, 1000`.Return them as a markdown formatted list with each recommendation from tool results, being sure to include the full PDP URL. For example:1. Product 1: [Price] -- link2. Product 2: [Price] -- link3. Product 3: [Price] -- link4. Product 4: [Price] -- link""")tools = [ionic_tool]# default prompt for openai tools agentprompt = hub.pull("hwchase17/openai-tools-agent")# Construct the OpenAI Tools agentagent = create_openai_tools_agent(llm, tools, prompt)agent_executor = AgentExecutor( agent=agent, tools=tools, handle_parsing_errors=True, verbose=True, max_iterations=5)
ionic_langchain.tool.IonicTool’s constructor accepts an instance of ionic_langchain.tool.Ionic, a wrapper around our SDK. ionic_langchain.tool.Ionic, in turn accepts an instance of that SDK, so you can provide the tool with a custom configuration: