|
1 | 1 | from asyncio import run
|
| 2 | +from os import environ |
2 | 3 |
|
3 | 4 | from algoliasearch.recommend import __version__
|
4 | 5 | from algoliasearch.recommend.client import RecommendClient
|
| 6 | +from algoliasearch.recommend.models.get_recommendations_params import ( |
| 7 | + GetRecommendationsParams, |
| 8 | +) |
| 9 | +from algoliasearch.recommend.models.related_query import RelatedQuery |
| 10 | +from algoliasearch.recommend.models.recommendations_request import ( |
| 11 | + RecommendationsRequest, |
| 12 | +) |
| 13 | +from algoliasearch.recommend.models.related_model import RelatedModel |
| 14 | + |
| 15 | +from dotenv import load_dotenv |
| 16 | + |
| 17 | +load_dotenv("../.env") |
5 | 18 |
|
6 | 19 |
|
7 | 20 | async def main():
|
8 | 21 | print("RecommendClient version", __version__)
|
9 | 22 |
|
10 |
| - client = RecommendClient("FOO", "BAR") |
| 23 | + client = RecommendClient( |
| 24 | + environ.get("ALGOLIA_APPLICATION_ID"), environ.get("ALGOLIA_ADMIN_KEY") |
| 25 | + ) |
11 | 26 |
|
12 | 27 | print("client initialized", client)
|
13 | 28 |
|
14 | 29 | try:
|
15 |
| - response = await client.delete_recommend_rule( |
16 |
| - index_name="nvim", model="test", object_id="objID" |
| 30 | + response = await client.get_recommendations( |
| 31 | + GetRecommendationsParams( |
| 32 | + requests=[ |
| 33 | + RecommendationsRequest( |
| 34 | + RelatedQuery( |
| 35 | + index_name="cts_e2e_browse", |
| 36 | + object_id="Æon Flux", |
| 37 | + model=RelatedModel.RELATED_PRODUCTS, |
| 38 | + threshold=30, |
| 39 | + max_recommendations=2, |
| 40 | + ) |
| 41 | + ) |
| 42 | + ] |
| 43 | + ) |
17 | 44 | )
|
18 | 45 |
|
19 |
| - print(response) |
| 46 | + print(len(response.results[0].hits), "recommendations found") |
20 | 47 | finally:
|
21 | 48 | await client.close()
|
22 | 49 |
|
|
0 commit comments