import util

Authenticate and get the OpenAI module

openai = util.openai()

Define the prompt

prompt = 'Once upon an AI'

Set the maximum number of tokens to generate

max_tokens = 5

Create a completion object

completion = openai.Completion.create(prompt=prompt, max_tokens=max_tokens, echo=False)

Extract the generated text

generated_text = completion.choices[0].text

Print the generated text

print(generated_text)

OpenAI Completion API Usage Example - Generate Text from a Prompt

原文地址: https://www.cveoy.top/t/topic/m3Gh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录