Skip to content

Commit 4c62911

Browse files
committed
Возвращение embeddings
1 parent 3415af2 commit 4c62911

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

backend.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,21 @@
1010
from flask import Flask, request, jsonify, Response, stream_with_context
1111
from flask_cors import CORS
1212
from threading import Thread
13+
import logging
14+
from embedding_processing import embedding_processing
1315

1416
import g4f
1517
from g4f import ChatCompletion, Provider, BaseProvider, models
1618
from g4f.models import ModelUtils
1719

1820
app = Flask(__name__)
19-
2021
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()
2624

2725
@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'])
2928
def chat_completions():
3029
request_data = request.get_json()
3130
model = request_data.get('model', 'gpt-3.5-turbo').replace("neuro-", "")
@@ -96,6 +95,20 @@ def stream():
9695
time.sleep(0.02)
9796
print('===Start Streaming===')
9897
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')
99112

100113
@app.route("/v1/dashboard/billing/subscription", methods=['GET'])
101114
@app.route("/dashboard/billing/subscription", methods=['GET'])
@@ -219,3 +232,5 @@ def providers():
219232
except:
220233
pass
221234
return jsonify(providers_data)
235+
236+

0 commit comments

Comments
 (0)