{ "cells": [ { "cell_type": "code", "execution_count": 3, "id": "95d56fde-3f1a-482f-aa25-40687d16e5dc", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\n", " \"books\": [\n", " {\n", " \"book_id\": 1,\n", " \"title\": \"The Enigma of Elysium\",\n", " \"author\": \"Aria Nightshade\",\n", " \"genre\": \"Fantasy\"\n", " },\n", " {\n", " \"book_id\": 2,\n", " \"title\": \"Shadows of Serendipity\",\n", " \"author\": \"Elijah Blackwood\",\n", " \"genre\": \"Mystery\"\n", " },\n", " {\n", " \"book_id\": 3,\n", " \"title\": \"Whispers in the Wind\",\n", " \"author\": \"Luna Silvermoon\",\n", " \"genre\": \"Romance\"\n", " }\n", " ]\n", "}\n" ] } ], "source": [ "\n", "import openai\n", "import os\n", "\n", "openai.api_key = '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'\n", "MODEL_NAME = 'gpt-3.5-turbo'\n", "\n", "# TEXT = f\"\"\"\n", "# You should express what you want a model to do by \\\n", "# providing instructions that are as clear and \\\n", "# specific as you can possibly make them. \\\n", "# This will guide the model towards the desired output, \\\n", "# and reduce the chances of receiving irrelevent \\\n", "# or incorrec5 responses. Don't confuse writing a \\\n", "# clear prompt with writing a short prompt. \\\n", "# In many case, longer prompts provide more clearity \\\n", "# and context for the model, which can lead to \\\n", "# more detailed and relevant outputs.\n", "# \"\"\"\n", "\n", "# PROMPT = f\"\"\"\n", "# summarize the text delimited by triple backticks\\\n", "# into a single sentence.\n", "# ```{TEXT}```\n", "# \"\"\"\n", "\n", "PROMPT = f\"\"\"\n", "Generate a list of three made-up book titles along \\\n", "with their authors and genres.\n", "Provide them in JSON format with the following keys:\n", "book_id, title, author, genre.\n", "\"\"\"\n", "\n", "class Assignment4:\n", " input_val = ''\n", " def __init__(self, model):\n", " self.model = model\n", " \n", " def get_input(self):\n", " self.input_val = input('Enter your message')\n", "\n", " def get_completion(self, prompt):\n", " messages = [{\n", " 'role': 'user',\n", " 'content': prompt\n", " }]\n", " response = openai.ChatCompletion.create(\n", " model=self.model,\n", " messages=messages,\n", " temperature=0\n", " )\n", " return response.choices[0].message['content']\n", "\n", " \n", "obj = Assignment4(MODEL_NAME)\n", "print(obj.get_completion(PROMPT))" ] }, { "cell_type": "code", "execution_count": null, "id": "fc90ad16-7a94-42ef-bdd4-9ec176da6210", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "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.11.4" } }, "nbformat": 4, "nbformat_minor": 5 }