import requests import flask import re import openai

headers = { 'authority': 'free-api.cveoy.top', 'accept': '/', 'accept-language': 'zh-CN,zh;q=0.9', 'cache-control': 'no-cache', 'content-type': 'application/json', 'dnt': '1', 'origin': 'https://www.cveoy.com', 'pragma': 'no-cache', 'referer': 'https://www.cveoy.com/', 'sec-ch-ua': 'Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': 'Windows', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'cross-site', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36', }

json_data = { 'prompt': '测试', } openai.api_key='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'

def chat(content): json_data['prompt'] = content response = requests.post('https://free-api.cveoy.top/v3/completions', headers=headers, json=json_data, stream=True) for chunk in response.iter_content(chunk_size=1024): yield chunk

#flask app = flask.Flask(name) @app.route('/', methods=['GET']) def returnchat(): content = flask.request.args.get('content') return flask.Response(chat(content), mimetype='text/plain')

if name == 'main': app.run( host='0.0.0.0', port= 9000, debug=False )

Python Flask 流式接收并转发 ChatGPT API 响应

原文地址: https://www.cveoy.top/t/topic/nMrs 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录