gordonchan commited on
Commit
265959d
1 Parent(s): 5e6213c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -27
app.py CHANGED
@@ -83,6 +83,7 @@ def expand_features(embedding, target_length):
83
 
84
 
85
  @app.post("/api/v1/embeddings", response_model=EmbeddingResponse)
 
86
  async def get_embeddings(request: EmbeddingRequest, credentials: HTTPAuthorizationCredentials = Depends(security)):
87
  if credentials.credentials != sk_key:
88
  raise HTTPException(
@@ -115,34 +116,7 @@ async def get_embeddings(request: EmbeddingRequest, credentials: HTTPAuthorizati
115
 
116
  return response
117
 
118
- @app.post("/v1/embeddings", response_model=EmbeddingResponse)
119
- async def get_embeddings(request: EmbeddingRequest, credentials: HTTPAuthorizationCredentials = Depends(security)):
120
- if credentials.credentials != sk_key:
121
- raise HTTPException(
122
- status_code=status.HTTP_401_UNAUTHORIZED,
123
- detail="Invalid authorization code",
124
- )
125
-
126
- prompt_tokens = sum(len(text.split()) for text in request.input)
127
- total_tokens = sum(num_tokens_from_string(text) for text in request.input)
128
-
129
- response = {
130
- "data": [
131
- {
132
- "embedding": embedding,
133
- "index": index,
134
- "object": "embedding"
135
- } for index, embedding in enumerate(embeddings)
136
- ],
137
- "model": request.model,
138
- "object": "list",
139
- "usage": {
140
- "prompt_tokens": prompt_tokens,
141
- "total_tokens": total_tokens,
142
- }
143
- }
144
 
145
- return response
146
 
147
  if __name__ == "__main__":
148
  uvicorn.run("app:app", host='0.0.0.0', port=7860, workers=2)
 
83
 
84
 
85
  @app.post("/api/v1/embeddings", response_model=EmbeddingResponse)
86
+ @app.post("/v1/embeddings", response_model=EmbeddingResponse)
87
  async def get_embeddings(request: EmbeddingRequest, credentials: HTTPAuthorizationCredentials = Depends(security)):
88
  if credentials.credentials != sk_key:
89
  raise HTTPException(
 
116
 
117
  return response
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
 
120
 
121
  if __name__ == "__main__":
122
  uvicorn.run("app:app", host='0.0.0.0', port=7860, workers=2)