forked from PradipNichite/Youtube-Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d97224
commit b7c4cd1
Showing
1 changed file
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
{ | ||
"nbformat": 4, | ||
"nbformat_minor": 0, | ||
"metadata": { | ||
"colab": { | ||
"provenance": [], | ||
"authorship_tag": "ABX9TyM1oXVoZ9ziah/2FOj0PnmD", | ||
"include_colab_link": true | ||
}, | ||
"kernelspec": { | ||
"name": "python3", | ||
"display_name": "Python 3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "view-in-github", | ||
"colab_type": "text" | ||
}, | ||
"source": [ | ||
"<a href=\"https://colab.research.google.com/github/PradipNichite/Youtube-Tutorials/blob/main/AWS_Lambda_GPT_3.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"!pip install openai" | ||
], | ||
"metadata": { | ||
"id": "IBlElKWDcovS" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"python -m venv venv\n", | ||
"\n", | ||
"mkdir python\n", | ||
"\n", | ||
"pip install openai -t python\n", | ||
"\n", | ||
"Finally Zip python directory and Upload it to layers" | ||
], | ||
"metadata": { | ||
"id": "ApBfuzsbcwH0" | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 16, | ||
"metadata": { | ||
"id": "FqyUG10JbXQ6" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import openai\n", | ||
"openai.api_key=\"key\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"notes = \"\"\"Name: Smart Car Cover\n", | ||
"properties: Robust, Affordable\"\"\"" | ||
], | ||
"metadata": { | ||
"id": "i2DFFZtaeDqh" | ||
}, | ||
"execution_count": 8, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"response = openai.Completion.create(\n", | ||
" model=\"text-davinci-003\",\n", | ||
" prompt=f\"Write a product description based on the below information.\\n\\n{notes}\\n\\nDescription:\",\n", | ||
" temperature=0.7,\n", | ||
" max_tokens=256,\n", | ||
" top_p=1,\n", | ||
" frequency_penalty=0,\n", | ||
" presence_penalty=0\n", | ||
")\n", | ||
"response['choices'][0]['text']" | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/", | ||
"height": 87 | ||
}, | ||
"id": "7B0szbJGjkUU", | ||
"outputId": "0bb8cb67-483e-43ff-fb1e-cff1bb0eadf6" | ||
}, | ||
"execution_count": 15, | ||
"outputs": [ | ||
{ | ||
"output_type": "execute_result", | ||
"data": { | ||
"text/plain": [ | ||
"'\\n\\nIntroducing the Smart Car Cover! This robust and affordable car cover is perfect for protecting your vehicle from the elements. Constructed from durable materials, it provides a reliable safeguard against dust, dirt and scratches. Its lightweight design makes it easy to store, and its affordable price makes it a great value. Protect your car from the elements with the Smart Car Cover!'" | ||
], | ||
"application/vnd.google.colaboratory.intrinsic+json": { | ||
"type": "string" | ||
} | ||
}, | ||
"metadata": {}, | ||
"execution_count": 15 | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"import json\n", | ||
"import openai\n", | ||
"openai.api_key=\"key\"\n", | ||
"def lambda_handler(event, context):\n", | ||
" \n", | ||
" body = json.loads(event['body'])\n", | ||
"\n", | ||
" response = openai.Completion.create(\n", | ||
" model=\"text-davinci-003\",\n", | ||
" prompt=f\"Write a product description based on the below information.\\n\\n{notes}\\n\\nDescription:\",\n", | ||
" temperature=0.7,\n", | ||
" max_tokens=256,\n", | ||
" top_p=1,\n", | ||
" frequency_penalty=0,\n", | ||
" presence_penalty=0\n", | ||
" )\n", | ||
" \n", | ||
" return {\n", | ||
" 'statusCode': 200,\n", | ||
" 'headers': {\n", | ||
" 'Content-Type': 'application/json'\n", | ||
" },\n", | ||
" 'body': json.dumps(response['choices'][0]['text'])\n", | ||
" }" | ||
], | ||
"metadata": { | ||
"id": "855qjiLEjuhr" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
} | ||
] | ||
} |