File size: 1,900 Bytes
b2f3744
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f8cb404
b2f3744
 
 
 
 
 
 
 
f8cb404
 
 
b2f3744
 
 
f8cb404
35b1339
a8798d7
35b1339
 
f8cb404
35b1339
 
 
f8cb404
 
 
 
35b1339
 
 
f8cb404
 
35b1339
 
f8cb404
 
b2f3744
 
f8cb404
b2f3744
 
 
 
 
 
 
35b1339
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from flask import Flask, request, jsonify
from flask_cors import CORS
import requests
import os

app = Flask(__name__)
CORS(app)

@app.route('/api/chat', methods=['POST'])
def chat():
    try:
        data = request.json
        token = data.get('token')
        user_input = data.get('input')
        
        if not token or not user_input:
            return jsonify({"error": "Hiányzó token vagy input"}), 400
        
        headers = {
            'Authorization': f'Bearer {token}'
        }
        
        payload = {
            'inputs': user_input,
            'parameters': {
                'max_new_tokens': 500,
                'temperature': 0.7,
                'return_full_text': False
            },
            'options': {
                'wait_for_model': True
            }
        }
        
        # Eredeti inference API
        response = requests.post(
            HF_API_URL = "https://router.huggingface.co/models/dphn/Dolphin3.0-Mistral-24B"
            json=payload,
            headers=headers,
            timeout=90
        )
        
        print(f"Status: {response.status_code}")
        print(f"Response: {response.text[:500]}")
        
        if response.status_code == 503:
            return jsonify({"error": "A modell még töltődik. Próbáld 30 másodperc múlva."}), 503
        
        if response.status_code != 200:
            return jsonify({
                "error": f"API hiba ({response.status_code})",
                "message": response.text[:300]
            }), response.status_code
        
        result = response.json()
        return jsonify(result)
        
    except Exception as e:
        return jsonify({"error": str(e)}), 500

@app.route('/')
def home():
    return "🐬 Dolphin Chat API működik! ✅"

if __name__ == '__main__':
    port = int(os.environ.get("PORT", 7860))
    app.run(host='0.0.0.0', port=port)