From dde647bea626cffec1b471aa9aacf85548c5c4ea Mon Sep 17 00:00:00 2001 From: Jason Park <93040528+JasonNotJson@users.noreply.github.com> Date: Mon, 23 Oct 2023 18:40:35 +0900 Subject: [PATCH] feat: legendary moment to test out bedrock (#369) --- src/lambda/inject-threads/index.py | 6 ++-- src/lambda/inject-threads/utils.py | 54 ++++++++++++++++-------------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/lambda/inject-threads/index.py b/src/lambda/inject-threads/index.py index 0a8436ac0..6b884c389 100644 --- a/src/lambda/inject-threads/index.py +++ b/src/lambda/inject-threads/index.py @@ -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) diff --git a/src/lambda/inject-threads/utils.py b/src/lambda/inject-threads/utils.py index 541fa2765..4faf6e90c 100644 --- a/src/lambda/inject-threads/utils.py +++ b/src/lambda/inject-threads/utils.py @@ -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()) @@ -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