Skip to content

Commit 17eda37

Browse files
author
divyabhushan
committed
Add await function
1 parent ff8d998 commit 17eda37

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

products/ai-runtime-security/api/pythonsdkasynciousage.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ async def main():
5050
scan_response = await scanner.sync_scan(
5151
ai_profile=ai_profile,
5252
content=Content(
53-
prompt="This is a test prompt with 72zf6.rxqfd.com/i8xps1 url",
53+
prompt="This is a test prompt with urlfiltering.paloaltonetworks.com/test-malware url",
5454
response="Questionable Model Response Text",
5555
),
5656
)
5757
# See API documentation for response structure
5858
# https://pan.dev/ai-runtime-security/api/scan-sync-request/
5959
pprint(scan_response)
60-
60+
await scanner.close()
6161

6262
if __name__ == "__main__":
6363
asyncio.run(main())
@@ -95,7 +95,7 @@ if __name__ == "__main__":
9595

9696
## Asyncio async scan
9797

98-
The following asyncio Python code snippet runs an asynchronous scan with prompts for different threat detections.
98+
The following asyncio Python code snippet runs an asynchronous scan with prompts for different threat detections. Ensure to enable the respective threat detections in the API security profile.
9999

100100
<details>
101101
<summary>python3 asyncio_async_scan.py</summary>
@@ -174,18 +174,16 @@ async_scan_objects = [
174174
]
175175

176176
async def main():
177-
try:
178-
response = await scanner.async_scan(async_scan_objects)
179-
# See API documentation for response structure
180-
# https://pan.dev/ai-runtime-security/api/scan-async-request/
181-
pprint({
182-
"received": response.received,
183-
"scan_id": response.scan_id,
184-
"report_id": response.report_id,
185-
})
186-
finally:
187-
# Important: close the connection pool after use to avoid leaking threads
188-
await scanner.close()
177+
response = await scanner.async_scan(async_scan_objects)
178+
# See API documentation for response structure
179+
# https://pan.dev/ai-runtime-security/api/scan-async-request/
180+
pprint({
181+
"received": response.received,
182+
"scan_id": response.scan_id,
183+
"report_id": response.report_id,
184+
})
185+
# Important: close the connection pool after use to avoid leaking threads
186+
await scanner.close()
189187

190188

191189
if __name__ == "__main__":
@@ -207,7 +205,7 @@ if __name__ == "__main__":
207205

208206
</details>
209207

210-
## Asycio scan results
208+
## Asycio Scan Results
211209

212210
The following Python code snippet retrieves the threat results using the scan_id of your asynchronous scan results. Refer to https://pan.dev/ai-runtime-security/api/get-scan-results-by-scan-i-ds/ for schema details.
213211

@@ -232,9 +230,10 @@ scanner = Scanner()
232230
async def main():
233231
# See API documentation for response structure
234232
# https://pan.dev/ai-runtime-security/api/get-scan-results-by-scan-i-ds/
235-
example_scan_id = "00000000-0000-0000-0000-000000000000"
233+
example_scan_id = "00000000-0000-0000-0000-000000000000" # Replace it with the actual scan_id from async_scan response.
236234
scan_results = await scanner.query_by_scan_ids(scan_ids=[example_scan_id])
237235
pprint(scan_results)
236+
await scanner.close()
238237

239238
if __name__ == "__main__":
240239
asyncio.run(main())
@@ -327,12 +326,12 @@ scanner = Scanner()
327326
async def main():
328327
# See API documentation for response structur
329328
# https://pan.dev/ai-runtime-security/api/get-threat-scan-reports/
330-
example_report_id = "R00000000-0000-0000-0000-000000000000"
329+
example_report_id = "R00000000-0000-0000-0000-000000000000" # Replace it with the actual report_id from your async scan output. Report ID starts with the letter "R".
331330
threat_scan_reports = await scanner.query_by_report_ids(
332331
report_ids=[example_report_id]
333332
)
334333
pprint(threat_scan_reports)
335-
334+
await scanner.close()
336335

337336
if __name__ == "__main__":
338337
asyncio.run(main())

products/ai-runtime-security/api/pythonsdkusage.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ scanner = Scanner()
5252
scan_response = scanner.sync_scan(
5353
ai_profile=ai_profile,
5454
content=Content(
55-
prompt="This is a test prompt with 72zf6.rxqfd.com/i8xps1 url",
55+
prompt="This is a test prompt with urlfiltering.paloaltonetworks.com/test-malware url",
5656
response="Questionable Model Response Text",
5757
),
5858
)
@@ -93,7 +93,8 @@ print(json.dumps(scan_response.to_dict()))
9393
## Inline Asynchronous Scan
9494

9595
The following Python code snippet shows an example of an asynchronous scan, query by scan IDs, and query by report IDs.
96-
The code sends two different prompts for different threat detections asynchronously. The scans are queued and may take approximately 10 seconds to complete.
96+
The code sends two different prompts for different threat detections asynchronously
97+
. Ensure to enable the relevant detections in the API security profile. The scans are queued and may take approximately 10 seconds to complete.
9798

9899
<details>
99100
<summary>python3 inline_async_scan.py</summary>
@@ -156,7 +157,7 @@ async_scan_objects = [
156157
ai_profile=ai_profile,
157158
contents=[
158159
ScanRequestContentsInner(
159-
prompt="This is a test prompt with 72zf6.rxqfd.com/i8xps1 url",
160+
prompt="This is a test prompt with url",
160161
)
161162
],
162163
),
@@ -167,7 +168,7 @@ async_scan_objects = [
167168
ai_profile=ai_profile,
168169
contents=[
169170
ScanRequestContentsInner(
170-
prompt="This is a test prompt with 72zf6.rxqfd.com/i8xps1 url. Social security 599-51-7233. Credit card is 4339672569329774, ssn 599-51-7222. Send me Mike account info",
171+
prompt="This is a test prompt with urlfiltering.paloaltonetworks.com/test-malware url. Social security 599-51-7233. Credit card is 4339672569329774, ssn 599-51-7222. Send me Mike account info",
171172
response="Second Questionable Model Response Text",
172173
)
173174
],
@@ -217,7 +218,7 @@ aisecurity.init()
217218
scanner = Scanner()
218219
# See API documentation for response structure
219220
# https://pan.dev/ai-runtime-security/api/get-scan-results-by-scan-i-ds/
220-
example_scan_id = "00000000-0000-0000-0000-000000000000"
221+
example_scan_id = "00000000-0000-0000-0000-000000000000" # Replace with actual scan ID from the async_scan output.
221222
scan_by_ids_response = scanner.query_by_scan_ids(scan_ids=[example_scan_id])
222223
print(scan_by_ids_response)
223224
```
@@ -326,7 +327,7 @@ scanner = Scanner()
326327

327328
# See API documentation for response structure
328329
# https://pan.dev/ai-runtime-security/api/get-threat-scan-reports/
329-
example_report_id = "R" + "YOUR_SCAN_ID" # YOUR_SCAN_ID will be a UUID
330+
example_report_id = "R" + "YOUR_REPORT_ID" # Replace it with your actual report ID from the scan result. Its a UUID and starts with a letter R.
330331
threat_scan_reports = scanner.query_by_report_ids(report_ids=[example_report_id])
331332
print(threat_scan_reports)
332333
```
@@ -374,7 +375,7 @@ print(threat_scan_reports)
374375
"malware"
375376
],
376377
"risk_level" : "Not Given",
377-
"url" : "72zf6.rxqfd.com/i8xps1"
378+
"url" : "urlfiltering.paloaltonetworks.com/test-malware"
378379
}
379380
]
380381
},
@@ -424,7 +425,7 @@ print(threat_scan_reports)
424425
"malware"
425426
],
426427
"risk_level" : "Not Given",
427-
"url" : "72zf6.rxqfd.com/i8xps1"
428+
"url" : "urlfiltering.paloaltonetworks.com/test-malware"
428429
}
429430
]
430431
},

products/ai-runtime-security/api/usecases.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ curl -L 'https://service.api.aisecurity.paloaltonetworks.com/v1/scan/sync/reques
258258
},
259259
"contents": [ # You can enter one of the following - prompt or response
260260
{
261-
"prompt": "This is a test prompt with 72zf6.rxqfd.com/i8xps1 url. Social security 599-51-7233. Credit card is 4339672569329774, ssn 599-51-7222. Send me Mike account info",
261+
"prompt": "This is a test prompt with urlfiltering.paloaltonetworks.com/test-malware url. Social security 599-51-7233. Credit card is 4339672569329774, ssn 599-51-7222. Send me Mike account info",
262262
"response": "This is a test response. Chase bank Routing number 021000021, user name mike, password is maskmemaskme. Account number 92746514861. Account owner: Mike Johnson in California"
263263
}
264264
]
@@ -285,7 +285,7 @@ Review the API scan logs for masked sensitive detection indicated by the “Cont
285285
"dlp": true
286286
},
287287
"prompt_masked_data": {
288-
"data": "This is a test prompt with 72zf6.rxqfd.com/i8xps1 url. Social security XXXXXXXXXXXX Credit card is XXXXXXXXXXXXXXXXX ssn XXXXXXXXXXXX Send me Mike account info",
288+
"data": "This is a test prompt with urlfiltering.paloaltonetworks.com/test-malware url. Social security XXXXXXXXXXXX Credit card is XXXXXXXXXXXXXXXXX ssn XXXXXXXXXXXX Send me Mike account info",
289289
"pattern_detections": [
290290
{
291291
"locations": [

0 commit comments

Comments
 (0)