1234567891011121314151617181920212223242526272829303132333435363738 |
- from applications.config import MODEL_CONFIG, LOCAL_MODEL_CONFIG
- from applications.utils import AsyncHttpClient
- async def get_basic_embedding(text: str, model: str):
- """
- embedding text into vectors
- :param text:
- :param model:
- :return:tong
- """
- cfg = MODEL_CONFIG[model]
- async with AsyncHttpClient(timeout=20) as client:
- response = await client.post(
- url=cfg["url"],
- json={"input": text, "model": model},
- headers={"Content-Type": "application/json"},
- )
- return response['data'][0]["embedding"]
- async def get_local_embedding(text, model):
- """
- embedding text into vectors
- :param text:
- :param model:
- :return:
- """
- outputs = model.get_embedding([text])
- embedding = outputs[0]
- return embedding
- __all__ = [
- "get_basic_embedding",
- "get_local_embedding"
- ]
|