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) text= response.text.replace('本内容由https://www.cveoy.com/独家提供!', '').replace('如果你觉得好用请将此网站/截图分享到微信/QQ群,帮助更多人!','').replace('你当前使用的模型为gpt-3.5-turbo!','').replace('chatgpt:','').replace('赞助接口作者浏览器打开:https://upload-bbs.miyoushe.com/upload/2023/02/28/283684029/9b58bc87cf914ca57429efb22c0da351_746776194442819643.jpg','').replace('本站开源地址https://github.com/cveoy/chatgpt-web','').replace('AI:', '').replace('站长合作邮箱:wxgpt@qq.com','') new_text = re.sub(r' ', '', text, count=2)

return new_text

#flask app = flask.Flask(name)

@app.route('/', methods=['POST']) def returnchat(): content = flask.request.get_data(as_text=True) return chat(content)

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

Python Flask 流式接收数据并调用 OpenAI API 获取响应

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

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