from fastapi import FastAPI from sentence_transformers import SentenceTransformer app = FastAPI() all_MiniLM_L6_V2_model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2') @app.get("/") def greet_json(): return {"Hello": "World!"} @app.post("/generate-embeddings/sentence-transformers-all-MiniLM-L6-v2/") def generate_embeddings_model1(sentences: list, all_MiniLM_L6_V2_model): sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium.", ] embeddings = all_MiniLM_L6_V2_model.encode(sentences) return {"embeddings": embeddings.tolist()} # Convert to list for JSON serialization