Spaces:
Runtime error
Runtime error
| 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_google_genai import ChatGoogleGenerativeAI | |
| 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 who ship stuff to India. Assistant should use the tool when the user is looking for a product recommendation or trying to find a specific product. | |
| The user is from India and may specify the number of results, minimum price, and maximum price for which they want to see results. You also need to explain the reasoning for the | |
| selection of the results - why did you choose these results out of all the different products that can be purchased. | |
| 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 Indian rupees (INR is the currency) | |
| - maximum price in Indian rupees | |
| For 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] -- link | |
| 2. Product 2: [Price] -- link | |
| 3. Product 3: [Price] -- link | |
| 4. Product 4: [Price] -- link | |
| Reasoning for the selection of these results: | |
| """ | |
| ) | |
| tools = [ionic_tool] | |
| agent = initialize_agent( | |
| tools=tools, | |
| llm = ChatGoogleGenerativeAI(model="gemini-pro", | |
| google_api_key=os.getenv('gemini_ai'), | |
| convert_system_message_to_human = True, | |
| verbose = True), | |
| agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION, | |
| handle_parsing_errors=True, | |
| verbose=True, | |
| ) | |
| import gradio as gr | |
| def generate_recommendations(text): | |
| try: | |
| output = agent.run(input=text) | |
| except: | |
| output = "Athena's abilities are still emerging and your search query was a bit complicated. Can you make it a bit simpler?" | |
| return output | |
| gr.Interface(generate_recommendations,theme=gr.themes.Soft(),inputs=[gr.Textbox(label="What do you want to buy?")], | |
| outputs=[gr.Markdown(label="Product Recommendations") ], title="Athena: Product Recommender", | |
| description='''Looking for the perfect product but overwhelmed by choices? Look no further! Just let Athena know what you're in the market for, whether it's a gadget, a fashion item, or something else entirely. Share your budget, any must-have features, or preferences you have in mind, and she'll curate a personalized list of recommendations tailored just for you. Let's make your shopping experience a breeze!''', | |
| article="Powered by Ionic", examples=[["I am looking for a mystery book written by Agatha Christie"],["A beginner-friendly digital camera for capturing family memories."],["Best noise-canceling headphones for immersive music listening"]]).launch() |