Web playgrounds ಡೆಮೋಗಳಿಗೆ ಉತ್ತಮವಾಗಿವೆ. ನೀವು ಒಂದು ಪಠ್ಯದ ಭಾಗವನ್ನು ಪೇಸ್ಟ್ ಮಾಡುತ್ತೀರಿ, ಮಾಡೆಲ್ ಒಂದು ಸುಂದರವಾದ ಸಾರಾಂಶವನ್ನು ಸಿದ್ಧಪಡಿಸುವುದನ್ನು ನೋಡುತ್ತೀರಿ ಮತ್ತು ಟ್ಯಾಬ್ ಅನ್ನು ಮುಚ್ಚುತ್ತೀರಿ. ಆದರೆ ಅದು ಎಂಜಿನಿಯರಿಂಗ್ ಅಲ್ಲ. ಪ್ರೊಡಕ್ಷನ್ ಕೆಲಸ ಎಂದರೆ APIs, error handling, ಮತ್ತು ನೀವು ಮಲಗಿದ್ದಾಗಲೂ ಚಾಲನೆಯಲ್ಲಿರುವ ಕೋಡ್. ನೀವು ಮೀಟಿಂಗ್ ಟ್ರಾನ್ಸ್ಕ್ರಿಪ್ಟ್ಗಳು, ಸಪೋರ್ಟ್ ಟಿಕೆಟ್ಗಳು ಅಥವಾ ಸಂಶೋಧನಾ ಪ್ರಬಂಧಗಳನ್ನು ನಿಗದಿತ ವೇಳಾಪಟ್ಟಿಯಂತೆ ಪ್ರಕ್ರಿಯೆಗೊಳಿಸಬೇಕಿದ್ದರೆ, ನಿಮಗೆ ಒಂದು ಪೈಪ್ಲೈನ್ ಅಗತ್ಯವಿದೆ.
ಈ ಮಾರ್ಗದರ್ಶಿಯು ಇದನ್ನು ನಿರ್ಮಿಸುವುದನ್ನು ವಿವರಿಸುತ್ತದೆ: Python, AWS SDK for Python (boto3), ಮತ್ತು Amazon Bedrock ಅನ್ನು ಬಳಸಿಕೊಂಡು ಲಘುವಾದ, ಸ್ವಯಂಚಾಲಿತ ಡಾಕ್ಯುಮೆಂಟ್ ಸಾರಾಂಶ ಸ್ಕ್ರಿಪ್ಟ್ (automated document summarization script). ಪಠ್ಯ ಸಾರಾಂಶದ ಕಾರ್ಯಗಳಿಗಾಗಿ ವೇಗ ಮತ್ತು ವೆಚ್ಚದ ನಡುವೆ ಸಮತೋಲನವನ್ನು ಕಾಯ್ದುಕೊಳ್ಳುವ Anthropic ನ Claude 3 Haiku ಮಾದರಿಯನ್ನು ನಾವು ಬಳಸುತ್ತೇವೆ.
Why Bedrock and Claude 3 Haiku?
Amazon Bedrock ಎಂಬುದು ಒಂದೇ ರೀತಿಯ AWS APIs ಮೂಲಕ ಫೌಂಡೇಶನ್ ಮಾಡೆಲ್ಗಳನ್ನು ಒದಗಿಸುವ ಒಂದು managed service ಆಗಿದೆ. ಬಾಹ್ಯ ಎಂಡ್ಪಾಯಿಂಟ್ಗಳನ್ನು ಜೋಡಿಸುವ ಮತ್ತು ಪ್ರತ್ಯೇಕ ಬಿಲ್ಲಿಂಗ್ ಮತ್ತು ಸೆಕ್ಯೂರಿಟಿ ಮಾಡೆಲ್ಗಳೊಂದಿಗೆ ಹೋರಾಡುವ ಬದಲು, ನೀವು ಪ್ರಮಾಣಿತ IAM ನಿಯಂತ್ರಣಗಳೊಂದಿಗೆ AWS ಎಂಡ್ಪಾಯಿಂಟ್ಗೆ ಕರೆ ಮಾಡಬಹುದು. ನಿಮ್ಮ ಡೇಟಾ ನಿಮ್ಮ AWS ಪರಿಸರದಲ್ಲಿಯೇ ಇರುತ್ತದೆ.
Claude 3 Haiku ಎಂಬುದು Anthropic ನ Claude 3 ಕುಟುಂಬದ ಅತ್ಯಂತ ಲಘು ಮಾದರಿಯಾಗಿದೆ. ಇದು ಸ್ಪಂದಿಸುವಿಕೆ ಮತ್ತು ಕಡಿಮೆ ವೆಚ್ಚಕ್ಕಾಗಿ ನಿರ್ಮಿಸಲಾಗಿದೆ, ಇದು ಹೆಚ್ಚಿನ ಪ್ರಮಾಣದ ಸಾರಾಂಶ ಕಾರ್ಯಗಳಿಗೆ ಸೂಕ್ತವಾಗಿದೆ. ಇಲ್ಲಿ ನೀವು ದೊಡ್ಡ ಮಾದರಿಗಳ ಹೆಚ್ಚಿನ ಸಾಮರ್ಥ್ಯಕ್ಕಾಗಿ ಹಣ ಪಾವತಿಸದೆ, ಸರಳ ಓದುವ ಕಾರ್ಯಗಳಿಗೆ ನಿರೀಕ್ಷಿತ ಫಲಿತಾಂಶವನ್ನು ಪಡೆಯಬಹುದು.
What You Need
ಯಾವುದೇ ಕೋಡ್ ಬರೆಯುವ ಮೊದಲು, ಈ ಕೆಳಗಿನವುಗಳು ಸಿದ್ಧವಾಗಿವೆ ಎಂದು ಖಚಿತಪಡಿಸಿಕೊಳ್ಳಿ:
- ಒಂದು ಸಕ್ರಿಯ AWS ಖಾತೆ.
- ಸ್ಥಳೀಯವಾಗಿ (locally) ಇನ್ಸ್ಟಾಲ್ ಮಾಡಲಾದ Python 3.9 ಅಥವಾ ಅದಕ್ಕಿಂತ ಹೆಚ್ಚಿನ ಆವೃತ್ತಿ.
- Bedrock ಮಾದರಿಗಳನ್ನು ಕರೆಯಲು ಅನುಮತಿ ಹೊಂದಿರುವ ಕ್ರೆಡೆನ್ಶಿಯಲ್ಗಳೊಂದಿಗೆ ಕಾನ್ಫಿಗರ್ ಮಾಡಲಾದ AWS CLI. ನೀವು ಇನ್ನೂ
aws configureಅನ್ನು ರನ್ ಮಾಡದಿದ್ದರೆ, ಈಗಲೇ ಮಾಡಿ. ನಂತರ ನೀವು ಅನುಮತಿ ದೋಷಗಳನ್ನು (permission errors) ಎದುರಿಸಿದರೆ, ನಿಮ್ಮ IAM ಬಳಕೆದಾರ ಅಥವಾ ರೋಲ್ಗೆ ಸೂಕ್ತವಾದ Bedrock invocation ಅನುಮತಿಗಳನ್ನು ಜೋಡಿಸಬೇಕಾಗಬಹುದು. - AWS Bedrock ಕನ್ಸೋಲ್ನಲ್ಲಿ Anthropic Claude 3 Haiku ಗಾಗಿ ನಿರ್ದಿಷ್ಟವಾಗಿ ಮಾಡೆಲ್ ಪ್ರವೇಶವನ್ನು (Model access) ಸಕ್ರಿಯಗೊಳಿಸಿ. ನೀವು ಯಾವುದೇ ಮಾಡೆಲ್ ಪ್ರೊವೈಡರ್ ಅನ್ನು ಕರೆಯುವ ಮೊದಲು AWS ನೀವು ಪ್ರತಿಯೊಂದಕ್ಕೂ ಸ್ಪಷ್ಟವಾಗಿ ಒಪ್ಪಿಗೆ ನೀಡಬೇಕಾಗುತ್ತದೆ.
Step 1: Enable Model Access
Bedrock ತಕ್ಷಣವೇ ಮಾದರಿಗಳನ್ನು ಬಳಸಲು ಬಿಡುವುದಿಲ್ಲ. ನೀವು ಮೊದಲು ಕನ್ಸೋಲ್ನಲ್ಲಿ ಸ್ವಿಚ್ ಅನ್ನು ಆನ್ ಮಾಡಬೇಕು.
- AWS Management Console ಗೆ ಲಾಗ್ ಇನ್ ಮಾಡಿ.
- Amazon Bedrock ಅನ್ನು ಹುಡುಕಲು ಸರ್ಚ್ ಬಾರ್ ಬಳಸಿ.
- ಎಡದ ನ್ಯಾವಿಗೇಷನ್ ಪ್ಯಾನಲ್ನಲ್ಲಿ, Model access ಅನ್ನು ಆಯ್ಕೆ ಮಾಡಿ.
- Modify model access ಮೇಲೆ ಕ್ಲಿಕ್ ಮಾಡಿ.
- Anthropic (Claude 3 Haiku) ಬಾಕ್ಸ್ ಅನ್ನು ಟಿಕ್ ಮಾಡಿ ಮತ್ತು ನಿಮ್ಮ ವಿನಂತಿಯನ್ನು ಸಲ್ಲಿಸಿ.
ಸ್ಥಿತಿಯು "Access granted" ಎಂದು ಬದಲಾದ ನಂತರ, ನೀವು ಕೋಡ್ನಿಂದ ಮಾದರಿಯನ್ನು ಕರೆಯಬಹುದು.
Step 2: Set Up Your Environment
ಸ್ವಚ್ಛವಾದ Python ಪರಿಸರವು ಅವಲಂಬನೆಗಳನ್ನು (dependencies) ಪ್ರತ್ಯೇಕವಾಗಿ ಮತ್ತು ಪುನರಾವರ್ತಿತವಾಗಿರಿಸುತ್ತದೆ. ನಿಮ್ಮ ಟರ್ಮಿನಲ್ ತೆರೆಯಿರಿ ಮತ್ತು ಈ ಕಮಾಂಡ್ಗಳನ್ನು ರನ್ ಮಾಡಿ:
mkdir bedrock-summarizer && cd bedrock-summarizer
python3 -m venv venv
source venv/bin/activate
pip install boto3
Windows ಬಳಕೆದಾರರು ಆಕ್ಟಿವೇಷನ್ ಕಮಾಂಡ್ ಅನ್ನು venv\Scripts\activate ಮೂಲಕ ಬದಲಾಯಿಸಬೇಕು. pip install boto3 ಮುಗಿದ ನಂತರ, AWS APIs ಗಳೊಂದಿಗೆ ಸಂವಹನ ನಡೆಸಲು ನಿಮಗೆ ಬೇಕಾದ ಎಲ್ಲವೂ ಲಭ್ಯವಿರುತ್ತದೆ.
Step 3: Write the Script
summarize.py ಎಂಬ ಹೆಸರಿನ ಫೈಲ್ ಅನ್ನು ರಚಿಸಿ. ಡಿಸ್ಕ್ನಿಂದ ಡಾಕ್ಯುಮೆಂಟ್ ಅನ್ನು ಓದುವುದು, ಅದನ್ನು Bedrock Converse API ಗೆ ನೀಡುವುದು ಮತ್ತು ಸಂಕ್ಷಿಪ್ತ ಸಾರಾಂಶವನ್ನು ಪ್ರಿಂಟ್ ಮಾಡುವುದು ಇದರ ಗುರಿಯಾಗಿದೆ.
ಕೆಳಗೆ ಸಂಪೂರ್ಣವಾಗಿ ಕೆಲಸ ಮಾಡುವ ಅನುಷ್ಠಾನವಿದೆ (implementation). ನಾವು Converse API ಅನ್ನು ಬಳಸುತ್ತೇವೆ ಏಕೆಂದರೆ ಇದು ವಿವಿಧ ಮಾಡೆಲ್ ಪ್ರೊವೈಡರ್ಗಳು ನಿರೀಕ್ಷಿಸುವ ರ ಕೇ (raw) JSON ಫಾರ್ಮ್ಯಾಟಿಂಗ್ ಅನ್ನು ಸರಳಗೊಳಿಸುತ್ತದೆ. ನೀವು ಕೇವಲ ಸಂದೇಶಗಳ ಪಟ್ಟಿ ಮತ್ತು ಇನ್ಫರೆನ್ಸ್ ಸೆಟ್ಟಿಂಗ್ಗಳನ್ನು ನೀಡಿದರೆ ಸಾಕು.
import boto3
def summarize_document(text: str) -> str:
client = boto3.client("bedrock-runtime")
model_id = "anthropic.claude-3-haiku-20240307-v1:0"
messages = [
{
"role": "user",
"content": [
{
"text": (
"Provide a concise summary of the following document. "
"Focus on the main points and avoid unnecessary detail:\n\n"
f"{text}"
)
}
]
}
]
response = client.converse(
modelId=model_id,
messages=messages,
inferenceConfig={
"temperature": 0.3,
"maxTokens": 512
}
)
summary = response["output"]["message"]["content"][0]["text"]
return summary.strip()
if __name__ == "__main__":
with open("document.txt", "r", encoding="utf-8") as f:
document_text = f.read()
result = summarize_document(document_text)
print("\n--- Summary ---\n")
print(result)
ಇಲ್ಲಿ ಗಮನಿಸಬೇಕಾದ ಕೆಲವು ಪ್ರಾಯೋಗಿಕ ವಿವರಗಳು:
- boto3.client("bedrock-runtime") ಇನ್ಫರೆನ್ಸ್ ಅನ್ನು ನಿರ್ವಹಿಸುವ ರನ್ಟೈಮ್ ಎಂಡ್ಪಾಯಿಂಟ್ಗೆ ಗುರಿ ಮಾಡುತ್ತದೆ. ನಿಮ್ಮ
~/.aws/configನಲ್ಲಿರುವ AWS ರೀಜನ್ Bedrock ಅನ್ನು ಬೆಂಬಲಿಸುತ್ತದೆ ಮತ್ತು ನೀವು ಅದೇ ರೀಜನ್ನಲ್ಲಿ Haiku ಅನ್ನು ಸಕ್ರಿಯಗೊಳಿಸಿದ್ದೀರಿ ಎಂದು ಖಚಿತಪಡಿಸಿಕೊಳ್ಳಿ. - Model ID
anthropic.claude-3-haiku-20240307-v1:0ಎಂಬುದು Bedrock ನಿರೀಕ್ಷಿಸುವ ನಿಖರವಾದ ಐಡೆಂಟಿಫೈಯರ್ ಆಗಿದೆ. ಇದನ್ನು ನಿಖರವಾಗಿ ಕಾಪಿ ಮಾಡಿ. - Temperature 0.3 ಗೆ ಸೆಟ್ ಮಾಡುವುದು ಔಟ್ಪುಟ್ ಅನ್ನು ಸ್ಥಿರವಾಗಿರಿಸುತ್ತದೆ. ಸಾರಾಂಶಕ್ಕಾಗಿ, ನೀವು ಮೂಲ ಪಠ್ಯಕ್ಕೆ ನಿಲುವಿಕೆ ಮತ್ತು ನಿಖರತೆಯನ್ನು ಬಯಸುತ್ತೀರಿ, ಸೃಜನಾತ್ಮಕ ಅಲಂಕಾರವನ್ನಲ್ಲ. ನೀವು ತಾಪಮಾನವನ್ನು (temperature) 1.0 ಕ್ಕೆ ಏರಿಸಿದರೆ, ಮಾದರಿಯು ಪದಬಳಕೆಯಲ್ಲಿ ಸ್ವತಂತ್ರವಾಗಿ ವರ್ತಿಸಲು ಪ್ರಾರಂಭಿಸುತ್ತದೆ ಮತ್ತು ಸಾಂದರ್ಭಿಕವಾಗಿ ವಿವರಗಳನ್ನು ಕಲ್ಪಿಸಿಕೊಳ್ಳಬಹುದು.
- ಪ್ರಾಂಪ್ಟ್ (prompt) ಅತ್ಯಂತ ನಿರ್ದಿಷ್ಟವಾಗಿದೆ. ಮಾದರಿಗೆ ಕೇವಲ "ಇದನ್ನು ಸಾರಾಂಶಗೊಳಿಸಿ" ಎಂಬ ಅಸ್ಪಷ್ಟವಾದ ಪಠ್ಯವನ್ನು ನೀಡುವ ಬದಲು, ನಾವು ಮುಖ್ಯ ಅಂಶಗಳನ್ನು ಕೇಳುತ್ತೇವೆ ಮತ್ತು ಅನಗತ್ಯ ವಿಷಯಗಳನ್ನು ಬಿಡಲು ಸೂಚಿಸುತ್ತೇವೆ. ಅಂತಹ ಸ್ಪಷ್ಟತೆಯು ಬಳಕೆಗೆ ಯೋಗ್ಯವಲ್ಲದ ಔಟ್ಪುಟ್ ಮತ್ತು ನೀವು ನಿಜವಾಗಿಯೂ ಬಳಸಬಹುದಾದ ಔಟ್ಪುಟ್ ನಡುವಿನ ವ್ಯತ್ಯಾಸವನ್ನು ಮಾಡುತ್ತದೆ.
ನೀವು ಸಾರಾಂಶಗೊಳಿಸಲು ಬಯಸುವ ಯಾವುದೇ ಪಠ್ಯ ಫೈಲ್ ಅನ್ನು ಅದೇ ಡೈರೆಕ್ಟರಿಯಲ್ಲಿರಿಸಿ ಮತ್ತು ಅದಕ್ಕೆ document.txt ಎಂದು ಹೆಸರಿಸಿ.
Step 4: Run It
ನಿಮ್ಮ ವರ್ಚುವಲ್ ಎನ್ವಿರಾನ್ಮೆಂಟ್ ಸಕ್ರಿಯವಾಗಿದ್ದಾಗ, ಇದನ್ನು ರನ್ ಮಾಡಿ:
python summarize.py
ನಿಮ್ಮ ಕ್ರೆಡೆನ್ಶಿಯಲ್ಗಳು ಮತ್ತು ಮಾಡೆಲ್ ಪ್ರವೇಶ ಸರಿಯಾಗಿದ್ದರೆ, ಕೆಲವು ಸೆಕೆಂಡುಗಳ ಒಳಗೆ ನಿಮ್ಮ ಟರ್ಮಿನಲ್ನಲ್ಲಿ ಸುಂದರವಾದ ಸಾರಾಂಶವು ಪ್ರಿಂಟ್ ಆಗುವುದನ್ನು ನೀವು ನೋಡಬಹುದು. ನಿಮಗೆ ಪ್ರವೇಶ ದೋಷ (access error) ಕಂಡುಬಂದರೆ, ನಿಮ್ಮ IAM ಅನುಮತಿಗಳನ್ನು ಮತ್ತೊಮ್ಮೆ ಪರಿಶೀಲಿಸಿ ಮತ್ತು ನೀವು ಕನ್ಸೋಲ್ನಲ್ಲಿ Claude 3 Haiku ಅನ್ನು ಸಕ್ರಿಯಗೊಳಿಸಿದ್ದೀರಾ ಎಂದು ಖಚಿತಪಡಿಸಿಕೊಳ್ಳಿ.
Pushing Beyond the Script
This pipeline is intentionally simple, but it is the foundation for real automation. Here is how you can extend it without adding bloat.
Batch processing. Swap the single file read for a loop over a directory. Drop fifty PDFs or text files into an input folder, iterate through them, and write the summaries to an output folder. If you want to ingest PDFs directly, you will need a preprocessing step with a library like PyPDF2 or pdfplumber to extract raw text before it hits Bedrock.
Chunking strategy. Very long documents may exceed the model’s context limit. When that happens, split the text into logical chunks by paragraph or section, summarize each chunk individually, and then pass the intermediate summaries back through the model for a final synthesis. This two-stage approach keeps you under token limits while preserving coverage of the full document.
Error handling. Production code should catch boto3.exceptions.ClientError specifically. AWS may throttle your requests if you call the API too aggressively. Wrap your converse call in a retry loop with exponential backoff, or use a library like tenacity to handle rate limits gracefully.
Prompt engineering. The difference between a mediocre summary and a useful one often comes down to the prompt. Ask for bullet points if you need scanability. Ask for a one-paragraph executive summary if the audience is senior leadership. You can even pass formatting constraints, such as "Limit the summary to three sentences" or "Return the output as JSON with keys for topic, key_points, and action_items."
The Real Takeaway
Moving from a chat playground to a working script is the inflection point where AI becomes infrastructure. Once this pipeline runs locally, you can lift it into an AWS Lambda function triggered by S3 uploads, schedule it on ECS Fargate, or hook it into an existing data workflow. The API call is the easy part. The engineering value comes from wrapping that call in logic that handles files, errors, and formatting so you never have to copy and paste text into a browser again.
For additional context and variations on this setup, see the original walkthrough on Dev.to. If you want to discuss AWS architectures, LLM pipelines, or prompt engineering with a community of builders, join the conversation over at [GyaanSetu AI on Telegram](https://t.me/GyaanSet
