用 Python 代码打造 ChantGPT: 生成循环吟唱文本
以下是一个使用 Python 代码编写的 ChantGPT:\n\npython\nimport openai\n\nopenai.api_key = 'YOUR_API_KEY' # 替换为你的 OpenAI API 密钥\n\ndef generate_chant(prompt):\n response = openai.Completion.create(\n engine='text-davinci-003',\n prompt=prompt,\n max_tokens=50,\n temperature=0.7,\n n=1,\n stop=None,\n temperature=0.7\n )\n return response.choices[0].text.strip()\n\ndef chant_gpt():\n prompt = "We are the champions" # 设置初始提示\n\n while True:\n chant = generate_chant(prompt)\n\n print(chant)\n\n prompt += ' ' + chant\n\nchant_gpt()\n\n\n请确保替换YOUR_API_KEY为你的 OpenAI API 密钥。运行这个代码将会生成一系列以"We are the champions"开头的 chant。可以根据需要修改prompt以及max_tokens、temperature等参数来调整生成的 chant 内容。
原文地址: https://www.cveoy.top/t/topic/pOnV 著作权归作者所有。请勿转载和采集!