basic.py 600 B

1234567891011121314151617181920212223
  1. from applications.config import MODEL_CONFIG
  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:
  9. """
  10. cfg = MODEL_CONFIG[model]
  11. async with AsyncHttpClient(timeout=20) as client:
  12. response = await client.post(
  13. url=cfg["url"],
  14. json={"input": text, "model": model},
  15. headers={"Content-Type": "application/json"},
  16. )
  17. return response['data'][0]["embedding"]
  18. __all__ = [
  19. "get_basic_embedding"
  20. ]