[docs]classOctoAIEmbeddings(OpenAIEmbeddings):"""OctoAI Compute Service embedding models. See https://octo.ai/ for information about OctoAI. To use, you should have the ``openai`` python package installed and the environment variable ``OCTOAI_API_TOKEN`` set with your API token. Alternatively, you can use the octoai_api_token keyword argument. """octoai_api_token:SecretStr=Field(default=None)"""OctoAI Endpoints API keys."""endpoint_url:str=Field(default=DEFAULT_API_BASE)"""Base URL path for API requests."""model:str=Field(default=DEFAULT_MODEL)"""Model name to use."""tiktoken_enabled:bool=False"""Set this to False for non-OpenAI implementations of the embeddings API"""@propertydef_llm_type(self)->str:"""Return type of embeddings model."""return"octoai-embeddings"@propertydeflc_secrets(self)->Dict[str,str]:return{"octoai_api_token":"OCTOAI_API_TOKEN"}@pre_initdefvalidate_environment(cls,values:dict)->dict:"""Validate that api key and python package exists in environment."""values["endpoint_url"]=get_from_dict_or_env(values,"endpoint_url","ENDPOINT_URL",default=DEFAULT_API_BASE,)values["octoai_api_token"]=convert_to_secret_str(get_from_dict_or_env(values,"octoai_api_token","OCTOAI_API_TOKEN"))values["model"]=get_from_dict_or_env(values,"model","MODEL",default=DEFAULT_MODEL,)try:importopenaiifis_openai_v1():client_params={"api_key":values["octoai_api_token"].get_secret_value(),"base_url":values["endpoint_url"],}ifnotvalues.get("client"):values["client"]=openai.OpenAI(**client_params).embeddingsifnotvalues.get("async_client"):values["async_client"]=openai.AsyncOpenAI(**client_params).embeddingselse:values["openai_api_base"]=values["endpoint_url"]values["openai_api_key"]=values["octoai_api_token"].get_secret_value()values["client"]=openai.Embeddingvalues["async_client"]=openai.EmbeddingexceptImportError:raiseImportError("Could not import openai python package. ""Please install it with `pip install openai`.")returnvalues