我目前正在尝试使用 OpenAI 的最新模型: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?']
Run Code Online (Sandbox Code Playgroud)
我定义了一个函数来执行此操作:
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, …Run Code Online (Sandbox Code Playgroud)