Spaces:
Running
Running
jonathanjordan21
commited on
Update apis/chat_api.py
Browse files- apis/chat_api.py +7 -7
apis/chat_api.py
CHANGED
@@ -48,10 +48,10 @@ class EmbeddingsAPIInference:
|
|
48 |
return requests.post(API_URL, headers=headers, json=payload).json()
|
49 |
|
50 |
|
51 |
-
class
|
52 |
def encode(self, **kwargs):
|
53 |
kwargs.pop("api_key", None)
|
54 |
-
return super().encode(**kwargs)
|
55 |
|
56 |
|
57 |
|
@@ -66,9 +66,9 @@ class ChatAPIApp:
|
|
66 |
)
|
67 |
self.setup_routes()
|
68 |
self.embeddings = {
|
69 |
-
"mxbai-embed-large":
|
70 |
-
"nomic-embed-text":
|
71 |
-
"multilingual-e5-large-instruct":
|
72 |
"intfloat/multilingual-e5-large-instruct":EmbeddingsAPIInference("intfloat/multilingual-e5-large-instruct"),
|
73 |
"mixedbread-ai/mxbai-embed-large-v1":EmbeddingsAPIInference("mixedbread-ai/mxbai-embed-large-v1")
|
74 |
}
|
@@ -360,7 +360,7 @@ class ChatAPIApp:
|
|
360 |
return {
|
361 |
"object":"list",
|
362 |
"data":[
|
363 |
-
{"object": "embedding", "index": i, "embedding": emb} for i,emb in enumerate(embeddings
|
364 |
],
|
365 |
"model": model,
|
366 |
"usage":{},
|
@@ -373,7 +373,7 @@ class ChatAPIApp:
|
|
373 |
model = request.model
|
374 |
model_kwargs = request.options
|
375 |
embeddings = self.embeddings[model].encode(request.prompt, api_key=api_key)#, **model_kwargs)
|
376 |
-
return {"embedding": embeddings
|
377 |
except ValueError as e:
|
378 |
raise HTTPException(status_code=400, detail=str(e))
|
379 |
|
|
|
48 |
return requests.post(API_URL, headers=headers, json=payload).json()
|
49 |
|
50 |
|
51 |
+
class SentenceTransformerLocal(SentenceTransformer):
|
52 |
def encode(self, **kwargs):
|
53 |
kwargs.pop("api_key", None)
|
54 |
+
return super().encode(**kwargs).tolist()
|
55 |
|
56 |
|
57 |
|
|
|
66 |
)
|
67 |
self.setup_routes()
|
68 |
self.embeddings = {
|
69 |
+
"mxbai-embed-large":SentenceTransformerLocal("mixedbread-ai/mxbai-embed-large-v1"),
|
70 |
+
"nomic-embed-text": SentenceTransformerLocal("nomic-ai/nomic-embed-text-v1.5", trust_remote_code=True),
|
71 |
+
"multilingual-e5-large-instruct":SentenceTransformerLocal("intfloat/multilingual-e5-large-instruct"),
|
72 |
"intfloat/multilingual-e5-large-instruct":EmbeddingsAPIInference("intfloat/multilingual-e5-large-instruct"),
|
73 |
"mixedbread-ai/mxbai-embed-large-v1":EmbeddingsAPIInference("mixedbread-ai/mxbai-embed-large-v1")
|
74 |
}
|
|
|
360 |
return {
|
361 |
"object":"list",
|
362 |
"data":[
|
363 |
+
{"object": "embedding", "index": i, "embedding": emb} for i,emb in enumerate(embeddings)#.tolist())
|
364 |
],
|
365 |
"model": model,
|
366 |
"usage":{},
|
|
|
373 |
model = request.model
|
374 |
model_kwargs = request.options
|
375 |
embeddings = self.embeddings[model].encode(request.prompt, api_key=api_key)#, **model_kwargs)
|
376 |
+
return {"embedding": embeddings}#.tolist()}
|
377 |
except ValueError as e:
|
378 |
raise HTTPException(status_code=400, detail=str(e))
|
379 |
|