embedding.py 646 B

12345678910111213141516171819202122
  1. from applications.config import LOCAL_MODEL_CONFIG, VLLM_SERVER_URL
  2. from applications.utils import AsyncHttpClient
  3. async def get_basic_embedding(text: str, model: str):
  4. """
  5. embedding text into vectors
  6. :param text:
  7. :param model:
  8. :return:tong
  9. """
  10. model_path = LOCAL_MODEL_CONFIG[model]
  11. async with AsyncHttpClient(timeout=20) as client:
  12. response = await client.post(
  13. url=VLLM_SERVER_URL,
  14. json={"input": text, "model": model_path},
  15. headers={"Content-Type": "application/json"},
  16. )
  17. return response["data"][0]["embedding"]
  18. __all__ = ["get_basic_embedding"]