Skip to content

Commit

Permalink
Fixed formats.
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-ohai committed Jan 14, 2025
1 parent 58bb9df commit c53ac9b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"source": [
"# OCI Data Science Model Deployment Endpoint\n",
"\n",
"## Overview\n",
"\n",
"[OCI Data Science](https://docs.oracle.com/en-us/iaas/data-science/using/home.htm) is a fully managed and serverless platform for data science teams to build, train, and manage machine learning models in the Oracle Cloud Infrastructure.\n",
"\n",
"This notebooks goes over how to use an embedding model hosted on a [OCI Data Science Model Deployment](https://docs.oracle.com/en-us/iaas/data-science/using/model-dep-about.htm).\n",
Expand All @@ -30,7 +32,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Prerequisite\n",
"### Instantiation\n",
"We will need to install the `oracle-ads` sdk"
]
},
Expand All @@ -55,15 +57,17 @@
"### Policies\n",
"Make sure to have the required [policies](https://docs.oracle.com/en-us/iaas/data-science/using/model-dep-policies-auth.htm#model_dep_policies_auth__predict-endpoint) to access the OCI Data Science Model Deployment endpoint.\n",
"\n",
"## Set up\n",
"After having deployed model, you have to set up **`endpoint`**: The model HTTP endpoint from the deployed model, e.g. `\"https://modeldeployment.us-ashburn-1.oci.customer-oci.com/<MD_OCID>/predict\"` of the `OCIModelDeploymentEndpointEmbeddings` call.\n",
"\n",
"\n",
"## Setup\n",
"After having deployed model, you have to set up **`endpoint`**: The model HTTP endpoint from the deployed model, e.g. `\"https://modeldeployment.us-ashburn-1.oci.customer-oci.com/<MD_OCID>/predict\"` of the `OCIModelDeploymentEndpointEmbeddings` call."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Authentication\n",
"\n",
"You can set authentication through either ads or environment variables. When you are working in OCI Data Science Notebook Session, you can leverage resource principal to access other OCI resources. Check out [here](https://accelerated-data-science.readthedocs.io/en/latest/user_guide/cli/authentication.html) to see more options. \n",
"\n",
"## Example"
"You can set authentication through either ads or environment variables. When you are working in OCI Data Science Notebook Session, you can leverage resource principal to access other OCI resources. Check out [here](https://accelerated-data-science.readthedocs.io/en/latest/user_guide/cli/authentication.html) to see more options. "
]
},
{
Expand All @@ -73,13 +77,28 @@
"outputs": [],
"source": [
"import ads\n",
"from langchain_community.embeddings import OCIModelDeploymentEndpointEmbeddings\n",
"\n",
"# Set authentication through ads\n",
"# Use resource principal are operating within a\n",
"# OCI service that has resource principal based\n",
"# authentication configured\n",
"ads.set_auth(\"resource_principal\")\n",
"ads.set_auth(\"resource_principal\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Direct Usage"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.embeddings import OCIModelDeploymentEndpointEmbeddings\n",
"\n",
"# Create an instance of OCI Model Deployment Endpoint\n",
"# Replace the endpoint uri with your own\n",
Expand All @@ -100,6 +119,15 @@
"documents = [\"This is a sample document\", \"and here is another one\"]\n",
"embeddings.embed_documents(documents)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## API Reference\n",
"\n",
"For detailed documentation on `OCIModelDeploymentEndpointEmbeddings` features and configuration options, please refer to the [API reference](https://python.langchain.com/api_reference/community/embeddings/langchain_community.embeddings.oci_data_science_model_deployment_endpoint.OCIModelDeploymentEndpointEmbeddings.html)."
]
}
],
"metadata": {
Expand Down
4 changes: 2 additions & 2 deletions libs/community/langchain_community/embeddings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
from langchain_community.embeddings.nlpcloud import (
NLPCloudEmbeddings,
)
from langchain_community.embeddings.oci_data_science_model_deployment_endpoint import (
from langchain_community.embeddings.oci_data_science_model_deployment_endpoint import ( # noqa: E501
OCIModelDeploymentEndpointEmbeddings,
)
from langchain_community.embeddings.oci_generative_ai import (
Expand Down Expand Up @@ -389,7 +389,7 @@
"MosaicMLInstructorEmbeddings": "langchain_community.embeddings.mosaicml",
"NLPCloudEmbeddings": "langchain_community.embeddings.nlpcloud",
"NeMoEmbeddings": "langchain_community.embeddings.nemo",
"OCIModelDeploymentEndpointEmbeddings": "langchain_community.embeddings.oci_data_science_model_deployment_endpoint",
"OCIModelDeploymentEndpointEmbeddings": "langchain_community.embeddings.oci_data_science_model_deployment_endpoint", # noqa: E501
"OCIGenAIEmbeddings": "langchain_community.embeddings.oci_generative_ai",
"OctoAIEmbeddings": "langchain_community.embeddings.octoai_embeddings",
"OllamaEmbeddings": "langchain_community.embeddings.ollama",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Any, Dict, List, Optional, Mapping, Callable
from langchain_core.embeddings import Embeddings
from langchain_core.pydantic_v1 import BaseModel, root_validator, Field
from langchain_core.utils import get_from_dict_or_env
from langchain_core.language_models.llms import create_base_retry_decorator
from langchain_core.utils import get_from_dict_or_env
from pydantic import BaseModel, Field, model_validator
import requests
from typing import Any, Callable, Dict, List, Mapping, Optional


DEFAULT_HEADER = {

Check failure on line 9 in libs/community/langchain_community/embeddings/oci_data_science_model_deployment_endpoint.py

View workflow job for this annotation

GitHub Actions / cd libs/community / make lint #3.13

Ruff (I001)

langchain_community/embeddings/oci_data_science_model_deployment_endpoint.py:1:1: I001 Import block is un-sorted or un-formatted

Check failure on line 9 in libs/community/langchain_community/embeddings/oci_data_science_model_deployment_endpoint.py

View workflow job for this annotation

GitHub Actions / cd libs/community / make lint #3.9

Ruff (I001)

langchain_community/embeddings/oci_data_science_model_deployment_endpoint.py:1:1: I001 Import block is un-sorted or un-formatted
Expand Down Expand Up @@ -36,7 +36,7 @@ class OCIModelDeploymentEndpointEmbeddings(BaseModel, Embeddings):
embeddings = OCIModelDeploymentEndpointEmbeddings(
endpoint="https://modeldeployment.us-ashburn-1.oci.customer-oci.com/<md_ocid>/predict",
)
"""
""" # noqa: E501

auth: dict = Field(default_factory=dict, exclude=True)
"""ADS auth dictionary for OCI authentication:
Expand All @@ -59,7 +59,7 @@ class OCIModelDeploymentEndpointEmbeddings(BaseModel, Embeddings):
max_retries: int = 1
"""The maximum number of retries to make when generating."""

@root_validator()
@model_validator(mode="before")
def validate_environment( # pylint: disable=no-self-argument
cls, values: Dict
) -> Dict:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def test_embedding_call(mocker: MockerFixture) -> None:
responses.POST,
endpoint,
json={
"embeddings": expected_output,
"data": [
{
"embedding": expected_output
}
],
},
status=200,
)
Expand Down

0 comments on commit c53ac9b

Please sign in to comment.