forked from danasaur/nlp
-
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.
working code to make requests to openai gpt-3.5-turbo api
- Loading branch information
Showing
10 changed files
with
60 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,3 @@ | ||
openai.env | ||
*.json | ||
*.csv |
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,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 |
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,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) |
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,11 @@ | ||
version: '3.8' | ||
services: | ||
openai: | ||
build: | ||
context: . | ||
env_file: | ||
- openai.env | ||
image: openai | ||
volumes: | ||
- ./:/mnt/nlp | ||
command: tail -F anything |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.