dayday98 commited on
Commit
f8cb404
·
verified ·
1 Parent(s): 35b1339

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -24
app.py CHANGED
@@ -16,10 +16,8 @@ def chat():
16
  if not token or not user_input:
17
  return jsonify({"error": "Hiányzó token vagy input"}), 400
18
 
19
- # Új Hugging Face API endpoint
20
  headers = {
21
- 'Authorization': f'Bearer {token}',
22
- 'Content-Type': 'application/json'
23
  }
24
 
25
  payload = {
@@ -27,49 +25,43 @@ def chat():
27
  'parameters': {
28
  'max_new_tokens': 500,
29
  'temperature': 0.7,
30
- 'top_p': 0.9,
31
  'return_full_text': False
 
 
 
32
  }
33
  }
34
 
35
- # Használjuk a router.huggingface.co API-t
36
  response = requests.post(
37
- 'https://router.huggingface.co/models/dphn/Dolphin3.0-Mistral-24B',
38
  json=payload,
39
  headers=headers,
40
- timeout=60
41
  )
42
 
43
- # Debug: nézzük meg mi jön vissza
44
  print(f"Status: {response.status_code}")
45
- print(f"Response: {response.text[:200]}")
 
 
 
46
 
47
- # Ellenőrizzük a status code-ot
48
  if response.status_code != 200:
49
  return jsonify({
50
- "error": f"API hiba: {response.status_code}",
51
- "details": response.text[:200]
52
  }), response.status_code
53
 
54
- return jsonify(response.json())
 
55
 
56
- except requests.exceptions.Timeout:
57
- return jsonify({"error": "Timeout - a modell nem válaszolt időben"}), 504
58
- except requests.exceptions.RequestException as e:
59
- return jsonify({"error": f"Hálózati hiba: {str(e)}"}), 500
60
- except ValueError as e:
61
- return jsonify({"error": f"JSON parse hiba: {str(e)}", "raw": response.text[:200]}), 500
62
  except Exception as e:
63
- return jsonify({"error": f"Váratlan hiba: {str(e)}"}), 500
64
 
65
  @app.route('/')
66
  def home():
67
  return "🐬 Dolphin Chat API működik! ✅"
68
 
69
- @app.route('/health')
70
- def health():
71
- return jsonify({"status": "healthy"})
72
-
73
  if __name__ == '__main__':
74
  port = int(os.environ.get("PORT", 7860))
75
  app.run(host='0.0.0.0', port=port)
 
16
  if not token or not user_input:
17
  return jsonify({"error": "Hiányzó token vagy input"}), 400
18
 
 
19
  headers = {
20
+ 'Authorization': f'Bearer {token}'
 
21
  }
22
 
23
  payload = {
 
25
  'parameters': {
26
  'max_new_tokens': 500,
27
  'temperature': 0.7,
 
28
  'return_full_text': False
29
+ },
30
+ 'options': {
31
+ 'wait_for_model': True
32
  }
33
  }
34
 
35
+ # Eredeti inference API
36
  response = requests.post(
37
+ 'https://api-inference.huggingface.co/models/dphn/Dolphin3.0-Mistral-24B',
38
  json=payload,
39
  headers=headers,
40
+ timeout=90
41
  )
42
 
 
43
  print(f"Status: {response.status_code}")
44
+ print(f"Response: {response.text[:500]}")
45
+
46
+ if response.status_code == 503:
47
+ return jsonify({"error": "A modell még töltődik. Próbáld 30 másodperc múlva."}), 503
48
 
 
49
  if response.status_code != 200:
50
  return jsonify({
51
+ "error": f"API hiba ({response.status_code})",
52
+ "message": response.text[:300]
53
  }), response.status_code
54
 
55
+ result = response.json()
56
+ return jsonify(result)
57
 
 
 
 
 
 
 
58
  except Exception as e:
59
+ return jsonify({"error": str(e)}), 500
60
 
61
  @app.route('/')
62
  def home():
63
  return "🐬 Dolphin Chat API működik! ✅"
64
 
 
 
 
 
65
  if __name__ == '__main__':
66
  port = int(os.environ.get("PORT", 7860))
67
  app.run(host='0.0.0.0', port=port)