Ionic 购物
基类:EventBaseToolSpec
Ionic 购物工具规范。
该工具可用于通过大语言模型构建电子商务体验。
workflows/handler.py 中的源代码llama_index/tools/ionic_shopping/base.py
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
64
65
66
67
68 | class IonicShoppingToolSpec(BaseToolSpec):
"""
Ionic Shopping tool spec.
This tool can be used to build e-commerce experiences with LLMs.
"""
spec_functions = ["query"]
def __init__(self, api_key: Optional[str] = None) -> None:
"""
Ionic API Key.
Learn more about attribution with Ionic API Keys
https://docs.ioniccommerce.com/guides/attribution
"""
from ionic import Ionic as IonicSDK
if api_key:
self.client = IonicSDK(api_key_header=api_key)
else:
self.client = IonicSDK()
def query(
self,
query: str,
num_results: Optional[int] = 5,
min_price: Optional[int] = None,
max_price: Optional[int] = None,
) -> list[Product]:
"""
Use this function to search for products and to get product recommendations.
Args:
query (str): A precise query of a product name or product category
num_results (Optional[int]): Defaults to 5. The number of product results to return.
min_price (Option[int]): The minimum price in cents the requester is willing to pay
max_price (Option[int]): The maximum price in cents the requester is willing to pay
"""
request = QueryAPIRequest(
query=SDKQuery(
query=query,
num_results=num_results,
min_price=min_price,
max_price=max_price,
)
)
response: QueryResponse = self.client.query(
request=request,
security=QuerySecurity(),
)
return [
product
for result in response.query_api_response.results
for product in result.products
]
|
query(query: str, num_results: Optional[int] = 5, min_price: Optional[int] = None, max_price: Optional[int] = None) -> list[Product]
使用此函数来搜索产品并获取产品推荐。
参数:
| 名称 |
类型 |
描述 |
默认 |
query
|
str
|
|
required
|
num_results
|
Optional[int]
|
|
5
|
min_price
|
Option[int]
|
|
None
|
max_price
|
Option[int]
|
|
None
|
workflows/handler.py 中的源代码llama_index/tools/ionic_shopping/base.py
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
64
65
66
67
68 | def query(
self,
query: str,
num_results: Optional[int] = 5,
min_price: Optional[int] = None,
max_price: Optional[int] = None,
) -> list[Product]:
"""
Use this function to search for products and to get product recommendations.
Args:
query (str): A precise query of a product name or product category
num_results (Optional[int]): Defaults to 5. The number of product results to return.
min_price (Option[int]): The minimum price in cents the requester is willing to pay
max_price (Option[int]): The maximum price in cents the requester is willing to pay
"""
request = QueryAPIRequest(
query=SDKQuery(
query=query,
num_results=num_results,
min_price=min_price,
max_price=max_price,
)
)
response: QueryResponse = self.client.query(
request=request,
security=QuerySecurity(),
)
return [
product
for result in response.query_api_response.results
for product in result.products
]
|
选项:
成员:- IonicShoppingToolSpec