Skip to content

Commit

Permalink
Idk what
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpan-206 committed Apr 30, 2024
1 parent 1c5de4a commit 58b13e8
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion open_ai_token/main.py
Expand Up @@ -6,7 +6,7 @@
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from fastapi.middleware.cors import CORSMiddleware
from starlette.responses import StreamingResponse
from open_ai_token.openai import chat_completions
from open_ai_token.openai import *

load_dotenv()

Expand Down Expand Up @@ -129,3 +129,28 @@ async def post_chat_completions(prompt: schemas.Prompt, db: Session = Depends(ge

except ValueError as e:
return {"Error": str(e)}

# Embedding routes

@app.post("/embeddings", include_in_schema=True)
async def post_embeddings(prompt: schemas.Prompt, db: Session = Depends(get_db), credentials: HTTPAuthorizationCredentials = Depends(security)):
"""
This route is used to get embeddings for a prompt.
"""

try:
authenticate(credentials)
token = credentials.credentials
db_token = crud.get_token(db, token)
if db_token is None:
raise ValueError("Token not found")
db_token.uses_left -= 1
db.commit()
try:
return StreamingResponse(embeddings(prompt.text, db_token.api_key), media_type="application/json")

except ValueError as e:
return {"Error": str(e)}

except ValueError as e:
return {"Error": str(e)}

0 comments on commit 58b13e8

Please sign in to comment.