Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added aws bedrock test #186

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions aws/bedrock1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@


from dotenv import load_dotenv
load_dotenv()

import boto3
import json

from traceloop.sdk import Traceloop
from traceloop.sdk.decorators import task, workflow

Traceloop.init(app_name="joke_generation_service")
bedrock_runtime = boto3.client(service_name="bedrock-runtime", region_name="us-west-2")


@task(name="gyliu_joke_creation")
def create_joke():

express_prompt = "Tell me a joke"

body = json.dumps({
"inputText": express_prompt,
"textGenerationConfig":{
"maxTokenCount":128,
"stopSequences":[], #define phrases that signal the model to conclude text generation.
"temperature":0, #Temperature controls randomness; higher values increase diversity, lower values boost predictability.
"topP":0.9 # Top P is a text generation technique, sampling from the most probable tokens in a distribution.
}
})

response = bedrock_runtime.invoke_model(
body=body,
modelId="amazon.titan-text-express-v1",
accept="application/json",
contentType="application/json"
)

response_body = json.loads(response.get('body').read())
outputText = response_body.get('results')[0].get('outputText')

text = outputText[outputText.index('\n')+1:]
about_lambda = text.strip()
return about_lambda

@workflow(name="gyliu_joke_generator")
def joke_workflow():
print(create_joke())


joke_workflow()
Loading