-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
botocore: add basic handling for bedrock invoke.model (#3200)
* Add basic handling for invoke.model * Add changelog a please pylint * Record converse cassettes against us-east-1 * Avoid double copy of streaming body --------- Co-authored-by: Adrian Cole <[email protected]>
- Loading branch information
1 parent
ec3c51d
commit 2756c1e
Showing
12 changed files
with
664 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...opentelemetry-instrumentation-botocore/examples/bedrock-runtime/zero-code/invoke_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import json | ||
import os | ||
|
||
import boto3 | ||
|
||
|
||
def main(): | ||
client = boto3.client("bedrock-runtime") | ||
response = client.invoke_model( | ||
modelId=os.getenv("CHAT_MODEL", "amazon.titan-text-lite-v1"), | ||
body=json.dumps( | ||
{ | ||
"inputText": "Write a short poem on OpenTelemetry.", | ||
"textGenerationConfig": {}, | ||
}, | ||
), | ||
) | ||
|
||
body = response["body"].read() | ||
response_data = json.loads(body.decode("utf-8")) | ||
print(response_data["results"][0]["outputText"]) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.