Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/Add LLMs Integration For Oracle Cloud Infrastructure(OCI) Data Science Model Deployment Endpoint #14250

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a429921
added llm integration for oci data science model deployment
mingkang111 Nov 27, 2023
acb4b0a
added import for oci data science model deployment
mingkang111 Nov 27, 2023
9fa8360
added documentation for oci data science model deployment
mingkang111 Nov 27, 2023
bbb4b21
added authentication section in doc
mingkang111 Nov 28, 2023
43e5083
fixed by comments
mingkang111 Nov 28, 2023
0d95592
fixed lint warning
mingkang111 Nov 30, 2023
8ef1a8e
fixed by comments: fetch endpoint from env var
mingkang111 Dec 1, 2023
3e4b167
resolved conflict
mingkang111 Dec 1, 2023
27442d4
fixed bugs
mingkang111 Dec 1, 2023
aacacb6
udpated documentation
mingkang111 Dec 1, 2023
589690a
fixed bugs
mingkang111 Dec 1, 2023
21ea7ab
added exclude field to accept more session based fields while validat…
mingkang111 Dec 4, 2023
e3b9a53
added test for oci model deployment endpoint llm
mingkang111 Dec 4, 2023
50a2089
fixed lint
mingkang111 Dec 4, 2023
0e95260
fixed tests
mingkang111 Dec 4, 2023
5c397e0
Merge branch 'master' of github.com:mingkang111/langchain into featur…
mingkang111 Dec 4, 2023
504c1c5
added type hint for kwargs argument
mingkang111 Dec 6, 2023
5a1b1e8
fixed lint
mingkang111 Dec 6, 2023
45a39ed
format
efriis Dec 6, 2023
119b49d
docs nits
efriis Dec 6, 2023
79bd280
moved model params out of Base
mingkang111 Dec 14, 2023
becd236
pop requests kwargs
mingkang111 Dec 14, 2023
2905511
Merge branch 'feature/add_llms_integration_for_oci_datascience_model_…
mingkang111 Dec 14, 2023
7439275
fixed merge confict
mingkang111 Dec 14, 2023
eafd7e1
move to langchain community
mingkang111 Dec 15, 2023
27f6089
fixed doc
mingkang111 Dec 15, 2023
e6f4157
fixed oci model deployment endpoint integration tests
mingkang111 Dec 16, 2023
2efa89d
removed BaseOCILLM
mingkang111 Dec 16, 2023
31e945d
reverted sorting
mingkang111 Dec 16, 2023
81eb0fd
fixed lint
mingkang111 Dec 16, 2023
54b555a
fixed format
mingkang111 Dec 16, 2023
bc9c7df
fixed lint
mingkang111 Dec 16, 2023
ed2d07d
fixed failed tests
mingkang111 Dec 16, 2023
9420069
fixed pydoc
mingkang111 Dec 16, 2023
7ffb5e4
fixed doc preview
mingkang111 Dec 16, 2023
6fb33d2
fixed test for serialization
mingkang111 Dec 16, 2023
7b938a1
Merge branch 'master' into feature/add_llms_integration_for_oci_datas…
mingkang111 Dec 16, 2023
1114bf6
Merge branch 'master' into feature/add_llms_integration_for_oci_datas…
mingkang111 Dec 17, 2023
6f16ba7
Merge branch 'master' into feature/add_llms_integration_for_oci_datas…
mingkang111 Dec 18, 2023
0b85851
Merge branch 'master' into feature/add_llms_integration_for_oci_datas…
mingkang111 Dec 19, 2023
406bfb6
fixed comments
mingkang111 Dec 19, 2023
4763d76
Fixed CI check
mingkang111 Dec 19, 2023
c5d72c5
reverted change in libs/langchain
mingkang111 Dec 19, 2023
c892b6a
dep
efriis Dec 19, 2023
41ab646
lock extra
efriis Dec 19, 2023
80b6504
test bug
efriis Dec 19, 2023
38287b2
resolved conflict
mingkang111 Dec 20, 2023
1cf9ca1
lock extra
mingkang111 Dec 20, 2023
43c2eee
test bugs
mingkang111 Dec 20, 2023
985181f
lock
efriis Dec 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions docs/docs/integrations/llms/oci_model_deployment_endpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# OCI Data Science Model Deployment Endpoint\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 LLM hosted on a [OCI Data Science Model Deployment](https://docs.oracle.com/en-us/iaas/data-science/using/model-dep-about.htm).\n",
"\n",
"To authenticate, [oracle-ads](https://accelerated-data-science.readthedocs.io/en/latest/user_guide/cli/authentication.html) has been used to automatically load credentials for invoking endpoint."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip3 install oracle-ads"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Prerequisite\n",
"\n",
"### Deploy model\n",
"Check [Oracle GitHub samples repository](https://github.com/oracle-samples/oci-data-science-ai-samples/tree/main/model-deployment/containers/llama2) on how to deploy your llm on OCI Data Science Model deployment.\n",
"\n",
"### 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",
"\n",
"### vLLM\n",
"After having deployed model, you have to set up following required parameters of the `OCIModelDeploymentVLLM` call:\n",
"\n",
"- **`endpoint`**: The model HTTP endpoint from the deployed model, e.g. `https://<MD_OCID>/predict`. \n",
"- **`model`**: The location of the model.\n",
"\n",
"### Text generation inference (TGI)\n",
"You have to set up following required parameters of the `OCIModelDeploymentTGI` call:\n",
"\n",
"- **`endpoint`**: The model HTTP endpoint from the deployed model, e.g. `https://<MD_OCID>/predict`. \n",
"\n",
"### 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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ads\n",
"from langchain_community.llms import OCIModelDeploymentVLLM\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",
"\n",
"# Create an instance of OCI Model Deployment Endpoint\n",
"# Replace the endpoint uri and model name with your own\n",
"llm = OCIModelDeploymentVLLM(endpoint=\"https://<MD_OCID>/predict\", model=\"model_name\")\n",
"\n",
"# Run the LLM\n",
"llm.invoke(\"Who is the first president of United States?\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"from langchain_community.llms import OCIModelDeploymentTGI\n",
"\n",
"# Set authentication through environment variables\n",
"# Use API Key setup when you are working from a local\n",
"# workstation or on platform which does not support\n",
"# resource principals.\n",
"os.environ[\"OCI_IAM_TYPE\"] = \"api_key\"\n",
"os.environ[\"OCI_CONFIG_PROFILE\"] = \"default\"\n",
"os.environ[\"OCI_CONFIG_LOCATION\"] = \"~/.oci\"\n",
"\n",
"# Set endpoint through environment variables\n",
"# Replace the endpoint uri with your own\n",
"os.environ[\"OCI_LLM_ENDPOINT\"] = \"https://<MD_OCID>/predict\"\n",
"\n",
"# Create an instance of OCI Model Deployment Endpoint\n",
"llm = OCIModelDeploymentTGI()\n",
"\n",
"# Run the LLM\n",
"llm.invoke(\"Who is the first president of United States?\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "langchain",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
24 changes: 24 additions & 0 deletions libs/community/langchain_community/llms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,22 @@ def _import_nlpcloud() -> Any:
return NLPCloud


def _import_oci_md_tgi() -> Any:
from langchain_community.llms.oci_data_science_model_deployment_endpoint import (
OCIModelDeploymentTGI,
)

return OCIModelDeploymentTGI


def _import_oci_md_vllm() -> Any:
from langchain_community.llms.oci_data_science_model_deployment_endpoint import (
OCIModelDeploymentVLLM,
)

return OCIModelDeploymentVLLM


def _import_octoai_endpoint() -> Any:
from langchain_community.llms.octoai_endpoint import OctoAIEndpoint

Expand Down Expand Up @@ -631,6 +647,10 @@ def __getattr__(name: str) -> Any:
return _import_mosaicml()
elif name == "NLPCloud":
return _import_nlpcloud()
elif name == "OCIModelDeploymentTGI":
return _import_oci_md_tgi()
elif name == "OCIModelDeploymentVLLM":
return _import_oci_md_vllm()
elif name == "OctoAIEndpoint":
return _import_octoai_endpoint()
elif name == "Ollama":
Expand Down Expand Up @@ -761,6 +781,8 @@ def __getattr__(name: str) -> Any:
"Nebula",
"NIBittensorLLM",
"NLPCloud",
"OCIModelDeploymentTGI",
"OCIModelDeploymentVLLM",
"Ollama",
"OpenAI",
"OpenAIChat",
Expand Down Expand Up @@ -848,6 +870,8 @@ def get_type_to_cls_dict() -> Dict[str, Callable[[], Type[BaseLLM]]]:
"nebula": _import_symblai_nebula,
"nibittensor": _import_bittensor,
"nlpcloud": _import_nlpcloud,
"oci_model_deployment_tgi_endpoint": _import_oci_md_tgi,
"oci_model_deployment_vllm_endpoint": _import_oci_md_vllm,
"ollama": _import_ollama,
"openai": _import_openai,
"openlm": _import_openlm,
Expand Down
Loading
Loading