class OpenaiClassifier():
def __init__(self, api_keys):
openai.api_key = api_keys['Openai']
def get_ratings(self, review):
prompt = f"Rate the following review as an integer from 1 to 5, where 1 is the worst and 5 is the best: \"{review}\""
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
n=1,
max_tokens=5,
temperature=0.5,
top_p=1
)
try:
rating = int(response.choices[0].text.strip())
return rating
except ValueError:
return None
I wonder what's the main difference between /v1/completions and /v1/chat/completions endpoints, and how I can do text classification using these models: gpt-4, gpt-4-0314, gpt-4-32k, gpt-4-32k-0314, gpt-3.5-turbo, gpt-3.5-turbo-0301
/completions
endpoint provides the completion for a single prompt and takes a single string as an input, whereas the /chat/completions
provides the responses for a given dialog and requires the input in a specific format corresponding to the message history.
If you want to use chat gpt models, you need to use /chat/completions
API, but your request has to be adjusted.
prompt = f"Rate the following review as an integer from 1 to 5, where 1 is the worst and 5 is the best: \"{review}\""
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": prompt}
]
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With