File size: 995 Bytes
cbee686
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import boto3, json, time

REGION = "us-east-1"
BUCKET = "medgemma-async-2026"
ENDPOINT = "medgemma-vllm-endpoint"

sagemaker = boto3.client("sagemaker-runtime", region_name=REGION)
s3 = boto3.client("s3", region_name=REGION)

payload = {
    "inputs": "What are the common symptoms of type 2 diabetes?",
    "parameters": {"max_new_tokens": 200, "temperature": 0.2}
}

input_key = f"input/test_{int(time.time())}.json"
s3.put_object(Bucket=BUCKET, Key=input_key, Body=json.dumps(payload).encode())

response = sagemaker.invoke_endpoint_async(
    EndpointName=ENDPOINT,
    InputLocation=f"s3://{BUCKET}/{input_key}",
    ContentType="application/json",
)
output_uri = response["OutputLocation"]
output_key = output_uri.replace(f"s3://{BUCKET}/", "")

for i in range(60):
    time.sleep(10)
    try:
        obj = s3.get_object(Bucket=BUCKET, Key=output_key)
        print(obj["Body"].read().decode())
        break
    except s3.exceptions.NoSuchKey:
        print(f"  waiting... {(i+1)*10}s")