[docs]classJavelinAIGatewayEmbeddings(Embeddings,BaseModel):"""Javelin AI Gateway embeddings. To use, you should have the ``javelin_sdk`` python package installed. For more information, see https://docs.getjavelin.io Example: .. code-block:: python from langchain_community.embeddings import JavelinAIGatewayEmbeddings embeddings = JavelinAIGatewayEmbeddings( gateway_uri="<javelin-ai-gateway-uri>", route="<your-javelin-gateway-embeddings-route>" ) """client:Any"""javelin client."""route:str"""The route to use for the Javelin AI Gateway API."""gateway_uri:Optional[str]=None"""The URI for the Javelin AI Gateway API."""javelin_api_key:Optional[str]=None"""The API key for the Javelin AI Gateway API."""def__init__(self,**kwargs:Any):try:fromjavelin_sdkimport(JavelinClient,UnauthorizedError,)exceptImportError:raiseImportError("Could not import javelin_sdk python package. ""Please install it with `pip install javelin_sdk`.")super().__init__(**kwargs)ifself.gateway_uri:try:self.client=JavelinClient(base_url=self.gateway_uri,api_key=self.javelin_api_key)exceptUnauthorizedErrorase:raiseValueError("Javelin: Incorrect API Key.")fromedef_query(self,texts:List[str])->List[List[float]]:embeddings=[]fortxtin_chunk(texts,20):try:resp=self.client.query_route(self.route,query_body={"input":txt})resp_dict=resp.dict()embeddings_chunk=resp_dict.get("llm_response",{}).get("data",[])foriteminembeddings_chunk:if"embedding"initem:embeddings.append(item["embedding"])exceptValueErrorase:print("Failed to query route: "+str(e))# noqa: T201returnembeddingsasyncdef_aquery(self,texts:List[str])->List[List[float]]:embeddings=[]fortxtin_chunk(texts,20):try:resp=awaitself.client.aquery_route(self.route,query_body={"input":txt})resp_dict=resp.dict()embeddings_chunk=resp_dict.get("llm_response",{}).get("data",[])foriteminembeddings_chunk:if"embedding"initem:embeddings.append(item["embedding"])exceptValueErrorase:print("Failed to query route: "+str(e))# noqa: T201returnembeddings