Spaces:
Running
Running
File size: 1,364 Bytes
dc84669 |
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#%%
aws_access_key_id='AKIA2UC26WDCAFOF7X64'
aws_secret_access_key='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'
aws_region = "eu-central-1"
#%%
import boto3
import json
from botocore.exceptions import ClientError
bedrock_runtime = session.client(service_name='bedrock-runtime')
# π·οΈ Model ID for Pixtral
model_id = 'mistral.pixtral-large-2502-v1:0'
# βοΈ Define your prompt
prompt = "Describe the purpose of a 'hello world' program in one line."
# π§Ύ Format the request payload
native_request = {
"inputText": prompt,
"textGenerationConfig": {
"maxTokenCount": 512,
"temperature": 0.5,
"topP": 0.9
}
}
# π Convert to JSON
request = json.dumps(native_request)
try:
# π Invoke the model
response = bedrock_runtime.invoke_model(
modelId=model_id,
body=request,
contentType="application/json",
accept="application/json"
)
# π¦ Decode the response body
model_response = json.loads(response["body"].read())
# π¨οΈ Extract and print output text
response_text = model_response["results"][0]["outputText"]
print("β
Model response:")
print(response_text)
except ClientError as e:
print(f"β ClientError: {e.response['Error']['Message']}")
except Exception as e:
print(f"β ERROR: Can't invoke '{model_id}'. Reason: {e}")
#%% |