File size: 3,255 Bytes
d64b746
 
 
 
 
 
 
df7bcd4
d64b746
 
 
 
 
 
 
 
 
fa4f9c7
 
d64b746
 
 
 
 
 
 
fa4f9c7
d64b746
 
 
 
 
8c7ca8a
 
d64b746
 
 
 
 
 
 
 
 
df7bcd4
d64b746
 
 
 
 
 
 
 
 
 
ba9f5c2
 
 
 
d64b746
f1b7388
 
 
ba9f5c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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()