-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt_helpers.py
More file actions
30 lines (27 loc) · 1.01 KB
/
Copy pathgpt_helpers.py
File metadata and controls
30 lines (27 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import openai
from dotenv import load_dotenv
load_dotenv(dotenv_path='.env')
openai.api_key = os.getenv("OPENAI_API_KEY")
def generate_review(prompt):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": prompt},],
temperature=1,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response.get("choices")[0].get("message").get("content")
def generate_rating(prompt):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": f"Rate the hotel from 1 to 5 based on the review. Only send back a number between 1 and 5. Do not send anything else. If you can't determine a number, send back 0.\nHere's the review: {prompt}"},],
temperature=1,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response.get("choices")[0].get("message").get("content")