admin 管理员组

文章数量: 887021

一、开启服务

二、api接口代码

import openai
import time

# 设置OpenAI API密钥
openai.api_key = '自己API'

def chat_with_gpt3(prompt):
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": prompt}],
        max_tokens=1000,
        temperature=0.3,
        stop=None,
        timeout=15,
    )
..................
..................
仅展示部分代码 需要完整代码联系博主 

三、搭建网页端聊天界面

from flask import Flask, render_template, request
import openai

app = Flask(__name__)

# 设置OpenAI API密钥
openai.api_key = '自己API'

def chat_with_gpt3(prompt):
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": prompt}],
        max_tokens=1000,
        temperature=0.3,
        stop=None,
        timeout=15,
    )

   
@app.route('/', methods=['GET', 'POST'])
.................................
仅展示部分代码 需要完整代码联系博主
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)

本文标签: 接口 ChatGpt api