Skip to content

Commit

Permalink
feat: legendary moment to test out bedrock (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonNotJson authored Oct 23, 2023
1 parent 0022ff7 commit dde647b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
6 changes: 4 additions & 2 deletions src/lambda/inject-threads/index.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from datetime import datetime, timedelta
from utils import JsonPayloadBuilder, resp_handler, generate_prompt
from utils import JsonPayloadBuilder, resp_handler, get_bedrock_response


def handler(event, context):
generate_prompt()
resp = get_bedrock_response()

print(resp)
54 changes: 28 additions & 26 deletions src/lambda/inject-threads/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,6 @@ def handle(*args, **kwargs):
return handle


def get_bedrock_response(input_text):
prompt = f'\n\nHuman: 200字以内で答えてください。答える際、200字以内と言わなくてよいです。{input_text}\n\nAssistant:'

modelId = 'anthropic.claude-instant-v1'
accept = 'application/json'
contentType = 'application/json'

body = json.dumps({
"prompt": prompt,
"max_tokens_to_sample": 1000
})

response = bedrock_client.invoke_model(
modelId=modelId,
accept=accept,
contentType=contentType,
body=body
)

response_body = json.loads(response.get('body').read())

return response_body.get('completion')


def build_thread_id():

unique_id = str(uuid.uuid4())
Expand Down Expand Up @@ -169,8 +145,34 @@ def generate_prompt():
- One forum post must be related to international student life in Japan.
- Posts use the group_id and board_id from the example threads.
Provide the forum posts in JSON format.
Assistant:
'''

print(prompt)

return prompt


def get_bedrock_response():

prompt = generate_prompt()

modelId = 'anthropic.claude-instant-v1'
accept = 'application/json'
contentType = 'application/json'

body = json.dumps({
"prompt": prompt,
"max_tokens_to_sample": 2000
})

response = bedrock_client.invoke_model(
modelId=modelId,
accept=accept,
contentType=contentType,
body=body
)

response_body = json.loads(response.get('body').read())

completion = response_body.get('completion')

return completion

0 comments on commit dde647b

Please sign in to comment.