File size: 3,517 Bytes
339fa5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import json, asyncio
import requests
from requests_auth_aws_sigv4 import AWSSigV4

# lib by drago
async def bedrock_model_available(session, key_id="", secret_key="", region="us-east-1", model="anthropic.claude-3-sonnet-20240229-v1%3A"):
    try:
        model = model.replace(":","%3A") # issue with urlencode just this so should be fine just doint it with replace 
    except Exception as e:
        pass
    endpoint = f'https://bedrock.{region}.amazonaws.com/foundation-model-availability/'+model
    
    headers = {
    'authority': 'bedrock.us-east-1.amazonaws.com',
    'accept': '*/*',
    'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8,pl;q=0.7',
    'amz-sdk-invocation-id': '17a6e1df-4d2a-41c8-87fd-991da34b2a92',
    'amz-sdk-request': 'attempt=1; max=3',
    'origin': 'https://us-east-1.console.aws.amazon.com',
    'referer': 'https://us-east-1.console.aws.amazon.com/',
    'sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'cross-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
    }
    aws_auth = AWSSigV4("bedrock",
        aws_access_key_id=key_id,
        aws_secret_access_key=secret_key,
        region=region
    )
    
    loop = asyncio.get_event_loop()
    req = requests.Request('GET', endpoint,  headers=headers)
    prepared_req = req.prepare()
    signed_req = await loop.run_in_executor(None, aws_auth, prepared_req)

    async with session.get(endpoint, headers=signed_req.headers, data=signed_req.body) as response:
        if response.status != 200:
            response_data = await response.text()
            return json.loads(response_data)
            
        return await response.json() 
        
async def bedrock_send_fake_form(session, key_id="", secret_key="", region="us-east-1", form_data=""):
    endpoint = f'https://bedrock.{region}.amazonaws.com/use-case-for-model-access'
    
    headers = {
    'authority': 'bedrock.us-east-1.amazonaws.com',
    'accept': '*/*',
    'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8,pl;q=0.7',
    'amz-sdk-invocation-id': '17a6e1df-4d2a-41c8-87fd-991da34b2a92',
    'amz-sdk-request': 'attempt=1; max=3',
    'origin': 'https://us-east-1.console.aws.amazon.com',
    'referer': 'https://us-east-1.console.aws.amazon.com/',
    'sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'cross-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
    }
    

    aws_auth = AWSSigV4("bedrock",
        aws_access_key_id=key_id,
        aws_secret_access_key=secret_key,
        region=region
    )
    
    loop = asyncio.get_event_loop()
    req = requests.Request('POST', endpoint, headers=headers)
    prepared_req = req.prepare()
    signed_req = await loop.run_in_executor(None, aws_auth, prepared_req)

    async with session.post(endpoint, headers=signed_req.headers, data=signed_req.body) as response:
        if response.status != 200:
            response_data = await response.text()
            return json.loads(response_data)
            
        return await response.json()