File tree Expand file tree Collapse file tree 4 files changed +48
-3
lines changed
examples/awsbedrock_examples Expand file tree Collapse file tree 4 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ classifiers = [
1818 " Operating System :: OS Independent" ,
1919]
2020dependencies = [
21- ' trace-attributes==7.0.4 ' ,
21+ ' trace-attributes==7.1.0 ' ,
2222 ' opentelemetry-api>=1.25.0' ,
2323 ' opentelemetry-sdk>=1.25.0' ,
2424 ' opentelemetry-instrumentation>=0.47b0' ,
@@ -57,7 +57,8 @@ dev = [
5757 " google-generativeai" ,
5858 " google-cloud-aiplatform" ,
5959 " mistralai" ,
60- " embedchain"
60+ " boto3" ,
61+ " embedchain" ,
6162]
6263
6364test = [" pytest" , " pytest-vcr" , " pytest-asyncio" ]
Original file line number Diff line number Diff line change 1+ from examples .awsbedrock_examples .converse import use_converse
2+ from langtrace_python_sdk import langtrace , with_langtrace_root_span
3+
4+ langtrace .init ()
5+
6+
7+ class AWSBedrockRunner :
8+ @with_langtrace_root_span ("AWS_Bedrock" )
9+ def run (self ):
10+ use_converse ()
Original file line number Diff line number Diff line change 1+ import os
2+ import boto3
3+ from langtrace_python_sdk import langtrace
4+
5+ langtrace .init (api_key = os .environ ["LANGTRACE_API_KEY" ])
6+
7+ def use_converse ():
8+ model_id = "anthropic.claude-3-haiku-20240307-v1:0"
9+ client = boto3 .client (
10+ "bedrock-runtime" ,
11+ region_name = "us-east-1" ,
12+ aws_access_key_id = os .environ ["AWS_ACCESS_KEY_ID" ],
13+ aws_secret_access_key = os .environ ["AWS_SECRET_ACCESS_KEY" ],
14+ )
15+ conversation = [
16+ {
17+ "role" : "user" ,
18+ "content" : [{"text" : "Write a story about a magic backpack." }],
19+ }
20+ ]
21+
22+ try :
23+ response = client .converse (
24+ modelId = model_id ,
25+ messages = conversation ,
26+ inferenceConfig = {"maxTokens" :4096 ,"temperature" :0 },
27+ additionalModelRequestFields = {"top_k" :250 }
28+ )
29+ response_text = response ["output" ]["message" ]["content" ][0 ]["text" ]
30+ print (response_text )
31+
32+ except (Exception ) as e :
33+ print (f"ERROR: Can't invoke '{ model_id } '. Reason: { e } " )
34+ exit (1 )
Original file line number Diff line number Diff line change 1- __version__ = "3.1.3 "
1+ __version__ = "3.2.0 "
You can’t perform that action at this time.
0 commit comments