Spaces:
Runtime error
Runtime error
Update api.py
Browse files
api.py
CHANGED
@@ -1,28 +1,28 @@
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
-
from app import
|
|
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
6 |
-
@app.route('/
|
7 |
-
def
|
8 |
data = request.json
|
9 |
-
|
|
|
|
|
10 |
|
11 |
-
if not
|
12 |
-
return jsonify({"error": "
|
13 |
|
14 |
try:
|
15 |
-
result =
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
)
|
20 |
-
return jsonify(
|
21 |
-
"generated_text": result,
|
22 |
-
"tokens_used": len(prompt.split()) + len(result.split())
|
23 |
-
})
|
24 |
except Exception as e:
|
25 |
return jsonify({"error": str(e)}), 500
|
26 |
|
27 |
if __name__ == '__main__':
|
28 |
-
app.run(host='0.0.0.0', port=
|
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
+
from app import generate_chat_completion
|
3 |
+
import time
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
|
7 |
+
@app.route('/v1/chat/completions', methods=['POST'])
|
8 |
+
def chat_completions():
|
9 |
data = request.json
|
10 |
+
messages = data.get('messages', [])
|
11 |
+
max_tokens = data.get('max_tokens', 560)
|
12 |
+
temperature = data.get('temperature', 0.7)
|
13 |
|
14 |
+
if not messages:
|
15 |
+
return jsonify({"error": "messages array is required"}), 400
|
16 |
|
17 |
try:
|
18 |
+
result = generate_chat_completion(
|
19 |
+
messages=messages,
|
20 |
+
max_tokens=max_tokens,
|
21 |
+
temperature=temperature
|
22 |
)
|
23 |
+
return jsonify(result)
|
|
|
|
|
|
|
24 |
except Exception as e:
|
25 |
return jsonify({"error": str(e)}), 500
|
26 |
|
27 |
if __name__ == '__main__':
|
28 |
+
app.run(host='0.0.0.0', port=8081) # Note port 8081
|