jonathanjordan21 commited on
Commit
827aa76
·
verified ·
1 Parent(s): 844397e

Update apis/chat_api.py

Browse files
Files changed (1) hide show
  1. 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 SentenceTransformer(SentenceTransformer):
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":SentenceTransformer("mixedbread-ai/mxbai-embed-large-v1"),
70
- "nomic-embed-text": SentenceTransformer("nomic-ai/nomic-embed-text-v1.5", trust_remote_code=True),
71
- "multilingual-e5-large-instruct":SentenceTransformer("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,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.tolist())
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.tolist()}
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