File size: 1,029 Bytes
1c8fde3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a310afa
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
from flask import Flask, request, jsonify
import requests
import json

app = Flask(__name__)

@app.route('/v1/chat/completions', methods=['POST'])
def chat_completions():
    try:
        response = requests.post(
            'https://text.pollinations.ai/openai',
            json=request.get_json(),
            headers={
                'Content-Type': 'application/json',
                'User-Agent': request.headers.get('User-Agent', 'Flask Proxy')
            }
        )

        response_data = response.json()

        if 'model' in response_data and response_data['model'] == 'gpt-5-nano':
            response_data['model'] = 'openai'

        return jsonify(response_data), response.status_code

    except requests.RequestException as e:
        return jsonify({'error': 'Proxy request failed', 'details': str(e)}), 500
    except json.JSONDecodeError:
        return jsonify({'error': 'Invalid JSON response from target server'}), 500

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=7860, debug=True)