शुरू करेंमुफ़्त में शुरू करें

Foundation मॉडल रिपोर्ट श्रेणीकरण

आप अब ऐसे AI फीचर पर काम कर रहे हैं जो मौसम की स्थिति को जल्दी समझने में मदद करता है. लंबे रिपोर्ट पढ़ने के बजाय, यूज़र अपनी SkyCast Assistant ऐप में एक साधारण, एक-शब्द का सारांश देखना चाहते हैं. Proof of concept के तौर पर, आप Amazon Bedrock का उपयोग करके एक मौसम रिपोर्ट को पहले से तय सूची में से एक शब्द में संक्षेपित करते हैं.

boto3 और json लाइब्रेरी पहले से लोड हैं. एक नमूना मौसम रिपोर्ट report के रूप में सेव है और मान्य categories की एक सूची भी पहले से लोड है.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Amazon Bedrock परिचय

पाठ्यक्रम देखें

अभ्यास निर्देश

  • ऐसा prompt बनाएँ जो categories सूची में दी गई अनुमत categories का ज़िक्र करे और report को शामिल करे.
  • मॉडल invoke करते समय इस prompt को request body में जोड़ें.
  • Bedrock से मिले response में से summary निकालें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

def summarize_weather(report):
    bedrock = boto3.client("bedrock-runtime", region_name="us-east-1")
    # Create prompt with allowed categories and pass in the report
    prompt = f"""Summarize the following weather report as one word from: {', '.join(____)}. Report: {____}"""
	# Pass the prompt to the body
    body = {"messages": [{"role": "user", "content": [{"text": ____}]}]}

    response = bedrock.invoke_model(modelId="us.amazon.nova-2-lite-v1:0", body=json.dumps(body))
    # Extract the summary from the response
    data = json.loads(response.get("body").read()____)
    return data["output"]["message"]["content"][0]["text"]

print(f"Weather Summary: {summarize_weather(report)}")
कोड संपादित करें और चलाएँ