Skip to content

Commit

Permalink
minor cleanup: sorted imports, doc string
Browse files Browse the repository at this point in the history
  • Loading branch information
danasaur committed Mar 26, 2023
1 parent 265f4bf commit ee5daa9
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions chatgpt.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import os
import json
import os
from pathlib import Path

import requests

import openai
import requests

openai.organization = "org-pyHC73IrTntMeKFF1ogHPSb4"
openai.organization = os.getenv("OPENAI_ORGANIZATION")
openai.api_key = os.getenv("OPENAI_API_KEY")
openai.Model.list()
# openai.Model.list()


URL = "https://api.openai.com/v1/chat/completions"


def ask_gpt(prompt, n_calls, save_path_base_filename):
def ask_gpt(prompt, model, n_calls, save_path_base_filename):
"""make a request to the openai api with a prompt for a given model
Args:
prompt (str): prompt to pass to chatgpt
model (str): "gpt-3.5-turbo" or "gpt-4"
ref for latest options: https://platform.openai.com/docs/models/gpt-4
n_calls (int): number of times to call the openai api
save_path_base_filename (str): where to save the output
"""

payload = {
"model": "gpt-3.5-turbo",
"model": model,
"messages": [{"role": "user", "content": prompt}],
"temperature" : 1.0,
"top_p":1.0,
Expand Down Expand Up @@ -45,10 +53,12 @@ def ask_gpt(prompt, n_calls, save_path_base_filename):

if __name__ == "__main__":

model = "gpt-3.5-turbo"
prompt = "Write 10 haikus about cats"
n_calls = 10
base_filename = "cat_haikus_10"
save_path = "./data/gpt_generated/cat_haikus"

Path(save_path).mkdir(parents=True, exist_ok=True)

save_path_base_filename = f"{save_path}/{base_filename}"
Expand Down

0 comments on commit ee5daa9

Please sign in to comment.