1 Star 0 Fork 0

郭鸿凯/LiMi

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.py 2.22 KB
一键复制 编辑 原始数据 按行查看 历史
# -*- coding:utf-8 -*-
from voice import voice_fix
from voice import voice_get
from pic import pic_fix
from data import data_fix
import os
import requests
import warnings
from flask import Flask, request, jsonify
import json
warnings.filterwarnings("ignore")
app = Flask(__name__)
app.config.from_object(__name__)
app.config["JSON_AS_ASCII"] = False
@app.route('/welcome', methods=['GET'])
def welcome():
return 0
@app.route('/voice', methods=['POST'])
def voice():
if request.method == 'POST':
body = request.json
flag = body['flag']
user = body['user']
if flag == '1':
print('开始录音,小声时结束')
voice_get.listen()
text = voice_fix.fix()
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer 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"
}
url = 'https://open.aiproxy.xyz/v1/chat/completions'
data = {
"model": "gpt-3.5-turbo",
"messages": [{"role": user, "content": text}]
}
response = requests.post(url, json=data, headers=headers)
response = response.text
response = response.encode('utf-8')
response = json.loads(response)
print(response)
return response
else:
return {'error': 'log has something wrong'}
else:
return {'error': 'web connect wrong'}
# @app.route('/pic')
# def pic():
# return 0
# @app.route('/login', methods=['POST'])
# def test():
# if request.method == 'POST':
# text = request.json
# print(text)
# headers = {
# "Content-Type": "application/json",
# "Authorization": "Bearer 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"
# }
# url = 'https://open.aiproxy.xyz/v1/chat/completions'
# data = {
# "model": "gpt-3.5-turbo",
# "messages": [{"role": "user", "content": text['content']}]
# }
# response = requests.post(url, json=data, headers=headers)
# print(response.text)
# return response.json()
if __name__ == '__main__':
app.run()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/guo-honkai/LiMi.git
git@gitee.com:guo-honkai/LiMi.git
guo-honkai
LiMi
LiMi
master

搜索帮助