File tree 2 files changed +28
-0
lines changed
instrumentation/opentelemetry-instrumentation-botocore/examples/bedrock-runtime/zero-code
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ Available examples
18
18
------------------
19
19
20
20
- `converse.py ` uses `bedrock-runtime ` `Converse API <https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html>_ `.
21
+ - `converse_stream.py ` uses `bedrock-runtime ` `ConverseStream API <https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html>_ `.
22
+ - `invoke_model.py ` uses `bedrock-runtime ` `InvokeModel API <https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html>_ `.
21
23
22
24
Setup
23
25
-----
Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+ import boto3
4
+
5
+
6
+ def main ():
7
+ client = boto3 .client ("bedrock-runtime" )
8
+ stream = client .converse_stream (
9
+ modelId = os .getenv ("CHAT_MODEL" , "amazon.titan-text-lite-v1" ),
10
+ messages = [
11
+ {
12
+ "role" : "user" ,
13
+ "content" : [{"text" : "Write a short poem on OpenTelemetry." }],
14
+ },
15
+ ],
16
+ )
17
+
18
+ response = ""
19
+ for s in stream ["stream" ]:
20
+ if "contentBlockDelta" in s :
21
+ response += s ["contentBlockDelta" ]["delta" ]["text" ]
22
+ print (response )
23
+
24
+
25
+ if __name__ == "__main__" :
26
+ main ()
You can’t perform that action at this time.
0 commit comments