Skip to content

Instantly share code, notes, and snippets.

View madhurprash's full-sized avatar

Madhur Prashant madhurprash

View GitHub Profile
@madhurprash
madhurprash / asyncio_bedrock_RESTapi.py
Last active November 1, 2024 05:29
Call multiple Amazon Bedrock model offerings using Python asyncio and the Bedrock REST API
## Note: This is for titan-express, but for any model you use, you will bring your own payloads and simply run this code.
import json
import time
import asyncio
import requests as req
import botocore.session
from itertools import groupby
from operator import itemgetter
from botocore.auth import SigV4Auth
@madhurprash
madhurprash / gist:19558e9a947e15584a63e49b206bc0fd
Created January 12, 2024 13:59
Call Bedrock Models via REST API
import json
import botocore.session
import requests as req
from botocore.auth import SigV4Auth
from botocore.awsrequest import AWSRequest
# Configuration and payload
region = "us-east-1"
model_id = 'cohere.command-text-v14'
endpoint = f"https://bedrock-runtime.{region}.amazonaws.com/model/{model_id}/invoke"
@madhurprash
madhurprash / retrieve_modelconfig_jumpstart.py
Last active February 16, 2024 17:11
Retrieve SageMaker JumpStart Models' Configurations
"""
Get information about models in Amazon SageMaker JumpStart.
Tested with sagemaker SDK version 2.203.0.
"""
## View the full list of models available through JumpStart here: https://sagemaker.readthedocs.io/en/stable/doc_utils/pretrainedmodels.html
import pandas as pd
from typing import Dict, List
from sagemaker import get_execution_role
@madhurprash
madhurprash / claude_3_metadata_tagger.txt
Last active June 7, 2024 19:59
Claude 3 metadata tagger
Human: you are a metadata tagger, see the following schema and tag the data that follows to extract the metadata fields listed in the schema:
<schema>
schema = {
"properties": {
"movie_title": { "type": "string" },
"critic": { "type": "string" },
"tone": {
"type": "string",
"enum": ["positive", "negative"]
@madhurprash
madhurprash / deploy_and_predict_hf_model_djl.ipynb
Last active August 8, 2024 01:58
Deploys a model from HuggingFace on Amazon SageMaker using the DJL DeepSpeed LMI (https://github.com/deepjavalibrary/djl-serving).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@madhurprash
madhurprash / github_issues_in_csv.py
Created September 17, 2024 18:41
This gist converts github issues into csv that can be imported into Asana for sprint planning
import os
import csv
import logging
import requests
from datetime import datetime
from typing import Optional, List
logging.basicConfig(format='[%(asctime)s] p%(process)s {%(filename)s:%(lineno)d} %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
@madhurprash
madhurprash / sagemaker_mlflow_simple_example.ipynb
Created November 13, 2024 17:37
In this gist, we do the following: Set up `mlflow` tracking with the SageMaker tracking server, create a simple classification experiment and use MLFlow to input logs, metrics, parameters and model with simple API calls.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@madhurprash
madhurprash / qrcode_generator.py
Created December 11, 2024 15:33
This gist takes in a list of links and generates QRCodes for those links.
import qrcode
import logging
import re
import os
# Install the following package before running the script: pip install qrcode
# set a logger
logging.basicConfig(
format='[%(asctime)s] p%(process)s {%(filename)s:%(lineno)d} %(levelname)s - %(message)s',
@madhurprash
madhurprash / move_folders_within_s3
Created April 2, 2025 16:15
This gist moves folders from within the same s3 bucket to another using pythons asyncio functionality
import os
import shutil
import concurrent.futures
import boto3
from pathlib import Path
import logging
import time
def move_folders_to_combined(bucket_name, folders_to_move=["SSE", "FPA", "Hypershield"], log_level=logging.INFO):
"""
@madhurprash
madhurprash / list_s3_uris_in_kb
Created April 2, 2025 17:15
This gist helps get insights into s3 uri's that the knowledge base has ingested as a part of its data s
import boto3
import json
from typing import Dict, List, Optional
import re
def get_detailed_s3_uris(
knowledge_base_id: str,
data_source_id: str
) -> Dict:
"""