Azure / Azure/MachineLearningNotebooks

Please add more context on the AMLRequest and AMLResponse classes

未關閉
#1,905 0 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Jupyter Notebook
星號
4.4k
分支
2.6k
PR 合併指標
30 天內沒有已合併 PR

描述

I am testing the sample https://github.com/Azure/azureml-examples/blob/main/sdk/python/endpoints/online/managed/online-endpoints-binary-payloads.ipynb
As per the documentation, the [AMLRequest](https://learn.microsoft.com/en-us/python/api/azureml-contrib-services/azureml.contrib.services.aml_request.amlrequest?view=azure-ml-py) and [AMLResponse](https://learn.microsoft.com/en-us/python/api/azureml-contrib-services/azureml.contrib.services.aml_response.amlresponse?view=azure-ml-py) classes were inherited from flask.wrappers. However, please also add the parameters and attributes and sample usage of these classes.

If I am sending a JSON object to the MOE (Managed Online Endpoint) along with the binary image file, the request object will hold these values passed as raw httprequest.

```
payload = {"file-metadata": {
"filename": "my-image.jpg",
"file-size": "150kb",
...
}}
res = requests.post(
url=scoring_uri,
headers={"Authorization": f"Bearer {key}"},
json=payload, **attempt to pass the payload to the request**
files=[
("file", open("my-image.jpg", "rb"))
],
)
```

How to pass a JSON payload to this request and access that from within the scoring script? I tried to configure the json parameter to assign a sample JSON payload as above sample. However, when viewing the value through req.get_json() in the scoring script, this function returns empty.

```
@rawhttp
def run(req : AMLRequest):
print(req.get_json()) **nothing gets printed out**
```

I found a workaround to assign the payload to the headers parameter as follows. However, it would be appreciated if you may also include the correct approach/sample usage of the above class(es).

```
payload = {"file-metadata": {
"filename": "my-image.jpg",
"file-size": "150kb",
...
}}

headers_ = {"Authorization": f"Bearer {key}", "File-Metadata": json.dumps(payload)}

res = requests.post(
url=scoring_uri,
headers=headers_
...)
```

---
#### Document Details

⚠ *Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.*

* ID: 024b6cd8-a404-ede4-0425-8f538550493d
* Version Independent ID: 5b5490ce-34df-acdc-fbce-49e6f9374acc
* Content: [azureml.contrib.services.aml_request.AMLRequest class - Azure Machine Learning Python](https://learn.microsoft.com/en-us/python/api/azureml-contrib-services/azureml.contrib.services.aml_request.amlrequest?view=azure-ml-py)
* Content Source: [AzureML-Docset/stable/docs-ref-autogen/azureml-contrib-services/azureml.contrib.services.aml_request.AMLRequest.yml](https://github.com/MicrosoftDocs/MachineLearning-Python-pr/blob/live/AzureML-Docset/stable/docs-ref-autogen/azureml-contrib-services/azureml.contrib.services.aml_request.AMLRequest.yml)
* Service: **machine-learning**
* Sub-service: **core**
* GitHub Login: @DebFro
* Microsoft Alias: **debfro**

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

從 AMLRequest 和 AMLResponse 參考頁面以及來源檔案 AzureML-Docset/stable/docs-ref-autogen/azureml.contrib.services.aml_request.AMLRequest.yml 開始;將它們與連結的 online-endpoints-binary-payloads.ipynb 範例進行比較。記錄傳遞 JSON 和二進位檔案並在評分指令碼中存取該檔案時涉及的相關參數、屬性和範例用法。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
documentation, machine-learning
Issue 類型
文件
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。