toypdf / api /routes /embeddings.py
Janar Ramalingam
first cut working version
51a7f02
raw
history blame
450 Bytes
from fastapi import APIRouter, UploadFile, File
import openai
import io
import os
from pypdf import PdfReader
router = APIRouter()
openai.api_key = os.getenv("OPENAI_API_KEY")
@router.post("/v1/embeddings")
async def embed_doc(file: UploadFile = File(...)):
#for now just truncate based on length of words
content = await file.read()
return openai.Embedding.create(input = content.decode("utf-8"), model = "text-embedding-ada-002")