admin管理员组文章数量:1026989
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)
版权声明:本文标题:ChatGPT使用api_key本地部署 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/jiaocheng/1726314214a608488.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论