{ "cells": [ { "cell_type": "markdown", "id": "80067b0c", "metadata": {}, "source": [ "# SageMaker Endpoint (Falcon FM)\n", "[chatbot-based-on-Falcon-FM](https://github.com/kyopark2014/chatbot-based-on-Falcon-FM)" ] }, { "cell_type": "code", "execution_count": 3, "id": "a523981a", "metadata": {}, "outputs": [], "source": [ "import json\n", "import boto3\n", "\n", "aws_region = boto3.Session().region_name" ] }, { "cell_type": "code", "execution_count": 2, "id": "e68cd468", "metadata": {}, "outputs": [], "source": [ "endpoint_name = 'jumpstart-dft-hf-llm-falcon-7b-instruct-bf16'" ] }, { "cell_type": "code", "execution_count": 11, "id": "aa05d14c", "metadata": {}, "outputs": [], "source": [ "text = 'Building a website can be done in 10 simple steps'" ] }, { "cell_type": "code", "execution_count": 12, "id": "1eac6daf", "metadata": {}, "outputs": [], "source": [ "payload = {\n", " \"inputs\": text,\n", " \"parameters\":{\n", " \"max_new_tokens\": 300,\n", " }\n", "}" ] }, { "cell_type": "code", "execution_count": 13, "id": "d10ad744", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "response: {'ResponseMetadata': {'RequestId': '6c2b0851-114a-4023-93b4-5260953cff6e', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': '6c2b0851-114a-4023-93b4-5260953cff6e', 'x-amzn-invoked-production-variant': 'AllTraffic', 'date': 'Thu, 13 Jul 2023 12:19:26 GMT', 'content-type': 'application/json', 'content-length': '458', 'connection': 'keep-alive'}, 'RetryAttempts': 0}, 'ContentType': 'application/json', 'InvokedProductionVariant': 'AllTraffic', 'Body': }\n" ] } ], "source": [ "client = boto3.client('runtime.sagemaker')\n", "response = client.invoke_endpoint(\n", " EndpointName=endpoint_name, \n", " ContentType='application/json', \n", " Body=json.dumps(payload).encode('utf-8')) \n", "print('response:', response)" ] }, { "cell_type": "code", "execution_count": 14, "id": "b275165a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ ".\n", "1. Choose a domain name\n", "2. Register a domain name\n", "3. Choose a web hosting provider\n", "4. Create a website design\n", "5. Add content to your website\n", "6. Add images and videos to your website\n", "7. Add a contact form\n", "8. Add a map to your website\n", "9. Add a search box to your website\n", "10. Test your website and make sure it is working properly.\n", "There are many other steps you can take to build a website, but these are the most important.\n" ] } ], "source": [ "statusCode = response['ResponseMetadata']['HTTPStatusCode'] \n", "if(statusCode==200):\n", " response_payload = json.loads(response['Body'].read())\n", " # print('response_payload:', response_payload)\n", "\n", "# print('len:', len(response_payload))\n", "outputText = \"\"\n", "if len(response_payload) == 1:\n", " outputText = response_payload[0]['generated_text']\n", "else:\n", " for resp in response_payload:\n", " outputText = outputText + resp['generated_text'] + '\\n' \n", "print(outputText)" ] } ], "metadata": { "kernelspec": { "display_name": "conda_python3", "language": "python", "name": "conda_python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.8" } }, "nbformat": 4, "nbformat_minor": 5 }