From e6896d84ff70ace17d90b10bbe263bafc4585906 Mon Sep 17 00:00:00 2001 From: Dana Engebretson Date: Fri, 17 Mar 2023 01:01:13 -0700 Subject: [PATCH] working code to make requests to openai gpt-3.5-turbo api --- .gitignore | 3 ++ Dockerfile | 10 ++++++ chatgpt.py | 36 +++++++++++++++++++ docker-compose.yml | 11 ++++++ .../More_SOTA_Deep_Learning_Models.ipynb | 0 NLP_intro.ipynb => notebooks/NLP_intro.ipynb | 0 .../Poetry_w_BERT.ipynb | 0 ..._distilbert_glue_text_classification.ipynb | 0 .../fine_tuning_bert.ipynb | 0 .../hugging_face_poetry_datasets.ipynb | 0 10 files changed, 60 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 chatgpt.py create mode 100644 docker-compose.yml rename More_SOTA_Deep_Learning_Models.ipynb => notebooks/More_SOTA_Deep_Learning_Models.ipynb (100%) rename NLP_intro.ipynb => notebooks/NLP_intro.ipynb (100%) rename Poetry_w_BERT.ipynb => notebooks/Poetry_w_BERT.ipynb (100%) rename fine_tune_distilbert_glue_text_classification.ipynb => notebooks/fine_tune_distilbert_glue_text_classification.ipynb (100%) rename fine_tuning_bert.ipynb => notebooks/fine_tuning_bert.ipynb (100%) rename hugging_face_poetry_datasets.ipynb => notebooks/hugging_face_poetry_datasets.ipynb (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..053c276 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +openai.env +*.json +*.csv \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..104c3ae --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.8-slim-buster + +RUN pip install openai + +COPY . /mnt/nlp/ + +WORKDIR /mnt/nlp/ + +# CMD python hello.py +# CMD python chatgpt.py \ No newline at end of file diff --git a/chatgpt.py b/chatgpt.py new file mode 100644 index 0000000..265c3bb --- /dev/null +++ b/chatgpt.py @@ -0,0 +1,36 @@ +import os +import json + +import requests + +import openai + +openai.organization = "org-pyHC73IrTntMeKFF1ogHPSb4" +openai.api_key = os.getenv("OPENAI_API_KEY") +openai.Model.list() + + +URL = "https://api.openai.com/v1/chat/completions" + +payload = { +"model": "gpt-3.5-turbo", +"messages": [{"role": "user", "content": f"Write 10 haikus about cats"}], +"temperature" : 1.0, +"top_p":1.0, +"n" : 1, +"stream": False, +"presence_penalty":0, +"frequency_penalty":0, +} + +headers = { +"Content-Type": "application/json", +"Authorization": f"Bearer {openai.api_key}" +} + +response = requests.post(URL, headers=headers, json=payload, stream=False) + +print(response.content) + +with open("haikus_10.json", "w+") as f: + json.dump(response.json(), f) \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7bd1903 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.8' +services: + openai: + build: + context: . + env_file: + - openai.env + image: openai + volumes: + - ./:/mnt/nlp + command: tail -F anything \ No newline at end of file diff --git a/More_SOTA_Deep_Learning_Models.ipynb b/notebooks/More_SOTA_Deep_Learning_Models.ipynb similarity index 100% rename from More_SOTA_Deep_Learning_Models.ipynb rename to notebooks/More_SOTA_Deep_Learning_Models.ipynb diff --git a/NLP_intro.ipynb b/notebooks/NLP_intro.ipynb similarity index 100% rename from NLP_intro.ipynb rename to notebooks/NLP_intro.ipynb diff --git a/Poetry_w_BERT.ipynb b/notebooks/Poetry_w_BERT.ipynb similarity index 100% rename from Poetry_w_BERT.ipynb rename to notebooks/Poetry_w_BERT.ipynb diff --git a/fine_tune_distilbert_glue_text_classification.ipynb b/notebooks/fine_tune_distilbert_glue_text_classification.ipynb similarity index 100% rename from fine_tune_distilbert_glue_text_classification.ipynb rename to notebooks/fine_tune_distilbert_glue_text_classification.ipynb diff --git a/fine_tuning_bert.ipynb b/notebooks/fine_tuning_bert.ipynb similarity index 100% rename from fine_tuning_bert.ipynb rename to notebooks/fine_tuning_bert.ipynb diff --git a/hugging_face_poetry_datasets.ipynb b/notebooks/hugging_face_poetry_datasets.ipynb similarity index 100% rename from hugging_face_poetry_datasets.ipynb rename to notebooks/hugging_face_poetry_datasets.ipynb