Spaces:
Running
Running
#%% | |
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}") | |
#%% |