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
我想知道 /v1/completions 和 /v1/chat/completions 端点之间的主要区别是什么,以及如何使用这些模型进行文本分类:gpt-4、gpt-4-0314、gpt-4-32k、gpt-4 -32k-0314,gpt-3.5-turbo,gpt-3.5-turbo-0301
/completions
端点提供了一个完成single prompt并接受单个字符串作为输入,而/chat/completions
提供给定的响应dialog并要求以与消息历史对应的特定格式输入。
如果你想使用聊天gpt模型,你需要使用/chat/completions
API,但您的请求必须调整。
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}
]
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)