Bedrock
Generates texts using AWS Bedrock APIs.
Note
Only supports AWS region US East 1!
BedrockClient
Bases: BatchClient
Source code in dactyl_generation/bedrock_generation.py
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
__init__(role_arn)
Constructor for BedrockClient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
role_arn
|
str
|
ARN of role to use. |
required |
Source code in dactyl_generation/bedrock_generation.py
20 21 22 23 24 25 26 27 28 | |
create_batch_job(prompts_df, s3_input_path, s3_output_path, model, job_name)
Creates batch job for Bedrock Llama models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompts_df
|
DataFrame
|
Dataframe of OpenAI-style prompts. |
required |
s3_input_path
|
str
|
Input data path. |
required |
s3_output_path
|
str
|
Output data path. |
required |
model
|
str
|
Bedrock model ID. |
required |
job_name
|
str
|
Name of job |
required |
Returns:
| Name | Type | Description |
|---|---|---|
jobArn |
dict
|
dictionary containing single string |
Source code in dactyl_generation/bedrock_generation.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
create_jsonl_input_for_llama(prompts_df, s3_path)
staticmethod
Creates a JSONL file to upload to S3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompts_df
|
DataFrame
|
prompt dataframe containing OpenAI style messages |
required |
s3_path
|
str
|
Path to S3 bucket to save file |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
None |
Source code in dactyl_generation/bedrock_generation.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
format_llama_prompt(messages)
staticmethod
Formats OpenAI style message to Llama 3.2 style.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
List[dict]
|
list of dictionaries containing OpenAI style messages |
required |
Returns:
| Name | Type | Description |
|---|---|---|
llama_prompt |
str
|
formatted llama prompt |
Source code in dactyl_generation/bedrock_generation.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
get_batch_job_output(file_path)
Fetches batch job results given JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
JSON file containing jobArn. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
output_df |
DataFrame
|
Dataframe containing generations. |
Source code in dactyl_generation/bedrock_generation.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
prompt(messages, model, temperature, top_p, max_completion_tokens=512)
staticmethod
Prompt AWS Bedrock model with few shot learning examples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
List[dict]
|
List of OpenAI messages |
required |
model
|
str
|
name of model |
required |
temperature
|
float
|
temperature parameter |
required |
top_p
|
float
|
top p parameter |
required |
max_completion_tokens
|
int
|
maximum number of tokens for completion |
512
|
Returns:
| Name | Type | Description |
|---|---|---|
response_content |
str
|
string containing message content |
Source code in dactyl_generation/bedrock_generation.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |