|
10 | 10 | from flask import Flask, request, jsonify, Response, stream_with_context |
11 | 11 | from flask_cors import CORS |
12 | 12 | from threading import Thread |
| 13 | +import logging |
| 14 | +from embedding_processing import embedding_processing |
13 | 15 |
|
14 | 16 | import g4f |
15 | 17 | from g4f import ChatCompletion, Provider, BaseProvider, models |
16 | 18 | from g4f.models import ModelUtils |
17 | 19 |
|
18 | 20 | app = Flask(__name__) |
19 | | - |
20 | 21 | CORS(app) |
21 | | - |
22 | | -@app.route('/', methods=['GET']) |
23 | | -def root(): |
24 | | - return {'message': 'Subscribe Telegram: https://t.me/neurogen_news'} |
25 | | - |
| 22 | +LOG = logging.getLogger(__name__) |
| 23 | +embedding_proc = embedding_processing() |
26 | 24 |
|
27 | 25 | @app.route("/chat/completions", methods=['POST']) |
28 | | -@app.route("/v1/chat/completions", methods=['POST', 'OPTIONS']) |
| 26 | +@app.route("/v1/chat/completions", methods=['POST']) |
| 27 | +@app.route("/", methods=['POST']) |
29 | 28 | def chat_completions(): |
30 | 29 | request_data = request.get_json() |
31 | 30 | model = request_data.get('model', 'gpt-3.5-turbo').replace("neuro-", "") |
@@ -96,6 +95,20 @@ def stream(): |
96 | 95 | time.sleep(0.02) |
97 | 96 | print('===Start Streaming===') |
98 | 97 | return app.response_class(stream(), mimetype='text/event-stream') |
| 98 | + |
| 99 | +@app.route('/v1/embeddings', methods=['POST']) |
| 100 | +@app.route('/embeddings', methods=['POST']) |
| 101 | +def create_embedding(): |
| 102 | + j_input = request.get_json() |
| 103 | + #model = embedding_processing() |
| 104 | + embedding = embedding_proc.embedding(text_list=j_input['input']) |
| 105 | + log_event() |
| 106 | + return jsonify( |
| 107 | + embedding |
| 108 | + ) |
| 109 | + |
| 110 | +def log_event(): |
| 111 | + LOG.info('served') |
99 | 112 |
|
100 | 113 | @app.route("/v1/dashboard/billing/subscription", methods=['GET']) |
101 | 114 | @app.route("/dashboard/billing/subscription", methods=['GET']) |
@@ -219,3 +232,5 @@ def providers(): |
219 | 232 | except: |
220 | 233 | pass |
221 | 234 | return jsonify(providers_data) |
| 235 | + |
| 236 | + |
0 commit comments