最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ChatGPT使用api_key本地部署

网站源码admin38浏览0评论

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)
发布评论

评论列表(0)

  1. 暂无评论