AWS personalize get-recommendations bug

0

Hello everyone. I have a problem with the get-recommendations response. For example:

Input data (utf-8 encoding):

{'ItemId': '1', 'properties': '{'description': 'random string\\nnext line '}'}

Output data (using the get-recommendations method):

{'ItemId': 'next line', 'score': 0.1}

So, in my example, I get broken string instead ItemId.

  1. What is a problem can be? How can I fix it?
  2. Is it possible that \n or similar symbols can break the response of this method and return some broken string instead?
질문됨 2년 전323회 조회
1개 답변
0

The GetRecommendations API request and response payload you shared above does not match the API definition. Are you using a language SDK or calling the Personalize endpoint directly?

If making a REST call directly to the Personalize campaign/recommender endpoint, the request payload should be in the following format.

{
   "campaignArn": "string",
   "context": { 
      "string" : "string" 
   },
   "filterArn": "string",
   "filterValues": { 
      "string" : "string" 
   },
   "itemId": "string",
   "numResults": number,
   "recommenderArn": "string",
   "userId": "string"
}

If using a language SDK like the AWS SDK for Python, the request parameters are passed as arguments to a function that wraps the REST call.

import boto3

personalizeRt = boto3.client('personalize-runtime')

response = personalizeRt.get_recommendations(
    campaignArn = 'Campaign ARN',
    userId = 'User ID',
    numResults = 10
)

print("Recommended items")
for item in response['itemList']:
    print (item['itemId'])

See examples here.

AWS
James_J
답변함 2년 전
  • I use boto3 library. I don't have any error with putting item or getting them, but in special cases which I describe above, if putting item has \n or similiar in properties, I get wrong data - I expect to get {'ItemId': '1, 'score': 0.1}, but getting {'ItemId': 'next line', 'score': 0.1}. Example:

    personalize_events = boto3.client("personalize-events")
    stream = {'itemId': '1', 'properties': '{"creationTimestamp": 1654676112, "description": "random string\\nnext line ", "userId": "1"}'}
    personalize_events.put_items(items=[stream])
    

    I get response using next code, but instead of {'itemList': [{'ItemId': 'next line', 'score': 0.1}]}

    personalize_events = boto3.client("personalize-events")
    personalize_events.get_recommendations()
    

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠