我目前正在尝试使用OpenAI的最新模型:
我正在使用Google Collab笔记本进行工作。我必须为提示列表中的每个提示发送一个请求,为了简单起见,列表如下:
我定义了一个函数来实现这个功能:
然而,当我调用
有什么建议吗?
将
gpt-3.5-turbo
。我正在按照一个非常基础的教程进行操作。我正在使用Google Collab笔记本进行工作。我必须为提示列表中的每个提示发送一个请求,为了简单起见,列表如下:
prompts = ['What are your functionalities?', 'what is the best name for an ice-cream shop?', 'who won the premier league last year?']
我定义了一个函数来实现这个功能:
import openai
# Load your API key from an environment variable or secret management service
openai.api_key = 'my_API'
def get_response(prompts: list, model = "gpt-3.5-turbo"):
responses = []
restart_sequence = "\n"
for item in prompts:
response = openai.Completion.create(
model=model,
messages=[{"role": "user", "content": prompt}],
temperature=0,
max_tokens=20,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
responses.append(response['choices'][0]['message']['content'])
return responses
然而,当我调用
responses = get_response(prompts=prompts[0:3])
时,我会得到以下错误:InvalidRequestError: Unrecognized request argument supplied: messages
有什么建议吗?
将
messages
参数替换为prompt
会导致以下错误:InvalidRequestError: [{'role': 'user', 'content': 'What are your functionalities?'}] is valid under each of {'type': 'array', 'minItems': 1, 'items': {'oneOf': [{'type': 'integer'}, {'type': 'object', 'properties': {'buffer': {'type': 'string', 'description': 'A serialized numpy buffer'}, 'shape': {'type': 'array', 'items': {'type': 'integer'}, 'description': 'Array shape'}, 'dtype': {'type': 'string', 'description': 'Stringified dtype'}, 'token': {'type': 'string'}}}]}, 'example': '[1, 1313, 451, {"buffer": "abcdefgh", "shape": [1024], "dtype": "float16"}]'}, {'type': 'array', 'minItems': 1, 'maxItems': 2048, 'items': {'oneOf': [{'type': 'string'}, {'type': 'object', 'properties': {'buffer': {'type': 'string', 'description': 'A serialized numpy buffer'}, 'shape': {'type': 'array', 'items': {'type': 'integer'}, 'description': 'Array shape'}, 'dtype': {'type': 'string', 'description': 'Stringified dtype'}, 'token': {'type': 'string'}}}], 'default': '', 'example': 'This is a test.', 'nullable': False}} - 'prompt'
messages
不是正确的参数。猜测你需要使用prompt: []
。 - 0stone0提示:项目
- 0stone0openai
软件包吗? - 0stone0openai.NotFoundError: Error code: 404 - {'error': {'message': '这是一个聊天模型,不支持在v1/completions端点中使用。您是否想使用v1/chat/completions?', 'type': 'invalid_request_error', 'param': 'model', 'code': None}}
。 - undefined