Spaces:
Running
Running
File size: 1,129 Bytes
14cd2f6 5f777da 14cd2f6 5f777da 14cd2f6 5f777da 14cd2f6 5f777da 14cd2f6 5f777da 08606b0 5f777da 5bf1b3e 5f777da 5bf1b3e 5f777da 14cd2f6 5f777da 14cd2f6 5f777da 14cd2f6 5f777da 14cd2f6 5f777da 14cd2f6 5f777da 745d3f1 5f777da |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import os
from g4f.client import Client
from flask import Flask, jsonify, request
from dotenv import load_dotenv
from flask_cors import CORS
load_dotenv()
app = Flask(__name__)
client = Client()
port = 7860
CORS(app)
@app.route('/', methods=['GET'])
def getMain():
return 'g4f-proxy is running'
@app.route('/', methods=['POST'])
def postG4F():
if not request.is_json:
return jsonify({"error": "Request must be JSON"}), 400
data = request.get_json()
# Required attributes
required_fields = ["system", "user"]
# Check for missing fields
missing_fields = [field for field in required_fields if field not in data]
if missing_fields:
return jsonify({"error": f"Missing fields: {', '.join(missing_fields)}"}), 400
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": data['system']},
{"role": "user", "content": data['user']}
],
web_search=False
)
return response.choices[0].message.content
if __name__ == '__main__':
app.run(debug=True, port=7860) |