{ "cells": [ { "cell_type": "markdown", "id": "176b5dec-ac5e-4b5d-a01b-e451f7fd7b4f", "metadata": {}, "source": [ "## On the command line: `pip install openai==0.28`" ] }, { "cell_type": "code", "execution_count": 1, "id": "41d2403f-e083-4c08-a09b-a019b1d65a49", "metadata": { "tags": [] }, "outputs": [], "source": [ "import openai" ] }, { "cell_type": "code", "execution_count": 2, "id": "5247e85a-ef94-403c-ac3d-ad289474868c", "metadata": { "tags": [] }, "outputs": [], "source": [ "# Use your key.\n", "openai.api_key = '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'" ] }, { "cell_type": "code", "execution_count": 3, "id": "e7e6f45b-4a3c-443c-819c-88baff2e5df8", "metadata": { "tags": [] }, "outputs": [], "source": [ "prompt = (\n", " \"\"\"\n", " What is SQL code to query the 'students' table\n", " and return the 'id', 'name', and 'grade'\n", " of students whose 'level' is 'undergraduate'?\n", " \"\"\"\n", ")" ] }, { "cell_type": "code", "execution_count": 4, "id": "c4e517da-49c6-4d00-93bb-1a4f65f04d96", "metadata": { "tags": [] }, "outputs": [], "source": [ "response = openai.ChatCompletion.create(\n", " model = \"gpt-3.5-turbo\",\n", " messages = [ {\"role\": \"user\",\n", " \"content\": prompt}\n", " ],\n", " temperature = 0\n", ")" ] }, { "cell_type": "code", "execution_count": 5, "id": "3b7e6bcd-c4d1-46d4-bf44-0003677e3cd8", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The SQL code to query the 'students' table and return the 'id', 'name', and 'grade' of students whose 'level' is 'undergraduate' would be:\n", "\n", "```sql\n", "SELECT id, name, grade\n", "FROM students\n", "WHERE level = 'undergraduate';\n", "```\n" ] } ], "source": [ "print(response.choices[0].message[\"content\"])" ] }, { "cell_type": "code", "execution_count": null, "id": "a9b80b98-7347-48ca-9668-2fea0f51121d", "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.9.18" } }, "nbformat": 4, "nbformat_minor": 5 }