API_KEY获取
通过以下网址获取自己的api_key,然后替换程序中的your_api_key
https://platform.openai.com/account/api-keys
程序
import os
import openai
openai.api_key = your_api_key
def gpt(prompt):
response = openai.ChatCompletion.create(
model= 'gpt-3.5-turbo',
messages=[
{'role': 'user','content': prompt},
],
temperature=0,
)
print(response.choices[0].message.content)
answer = response.choices[0].message.content
# 使用换行符分割字符串,然后使用点号和空格连接元素
elements = answer.split('\n')
formatted_string = '. '.join(elements) + '. '
return formatted_string
if __name__ == "__main__":
prompt = "Who are you?"
result = gpt(prompt)
API_KEY获取
通过以下网址获取自己的api_key,然后替换程序中的your_api_key
https://platform.openai.com/account/api-keys
程序
import os
import openai
openai.api_key = your_api_key
def gpt(prompt):
response = openai.ChatCompletion.create(
model= 'gpt-3.5-turbo',
messages=[
{'role': 'user','content': prompt},
],
temperature=0,
)
print(response.choices[0].message.content)
answer = response.choices[0].message.content
# 使用换行符分割字符串,然后使用点号和空格连接元素
elements = answer.split('\n')
formatted_string = '. '.join(elements) + '. '
return formatted_string
if __name__ == "__main__":
prompt = "Who are you?"
result = gpt(prompt)