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

community: Update OCI data science integration #27083

Merged
merged 87 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
95dce88
llm streaming support
mingkang111 Jun 14, 2024
7a0ee2a
llm async invoke support
mingkang111 Jun 21, 2024
da3261a
improvement on odsc llm integration
mingkang111 Jun 28, 2024
03eaa7e
improvement on odsc llm integration
mingkang111 Jun 28, 2024
87154d9
added ChatOCIModelDeploymentEndpoint
mingkang111 Jul 10, 2024
bec5e09
poc tool calling
mingkang111 Jul 10, 2024
b89e692
with_structured_output support
mingkang111 Jul 11, 2024
32efb77
added framework specific plugin
mingkang111 Jul 11, 2024
a2d7fcd
added framework specific plugin
mingkang111 Jul 11, 2024
f31efff
improvement on odsc llm integration
mingkang111 Jul 11, 2024
fc0b29d
clean up
mingkang111 Jul 11, 2024
03f2102
fixed by comments: improved error messages and added docstring
mingkang111 Jul 12, 2024
89d1f48
improvement on docstrings
mingkang111 Jul 12, 2024
58a920e
added test cases
mingkang111 Jul 12, 2024
f8b88f3
added test import
mingkang111 Jul 12, 2024
d2d125f
improvement on notebook example
mingkang111 Jul 12, 2024
6607755
improvement on notebook example
mingkang111 Jul 12, 2024
a1abbff
improvement on notebook example
mingkang111 Jul 16, 2024
6e989ad
improvement on notebook example, added sample return
mingkang111 Jul 16, 2024
8adc8dc
improvement on notebook example, added structured output
mingkang111 Jul 16, 2024
4366304
improvement on notebook example, added structured output
mingkang111 Jul 16, 2024
dcb8ade
clean code
mingkang111 Jul 19, 2024
5978c74
clean code
mingkang111 Jul 19, 2024
2f1bdb4
clean code
mingkang111 Jul 19, 2024
8a787a6
create base class for invoking
mingkang111 Jul 19, 2024
6ceaaf6
fixed by comments
mingkang111 Jul 19, 2024
a492c91
backward compatibility for TGI class
mingkang111 Jul 19, 2024
aebcd45
modified argument name
mingkang111 Jul 19, 2024
77c8dd9
fixed by comments
mingkang111 Jul 19, 2024
31f5c3c
fixed by comments
mingkang111 Jul 19, 2024
b72122a
fixed by comments
mingkang111 Jul 19, 2024
2d7a5b7
fixed by comments
mingkang111 Jul 19, 2024
8245a9b
fixed by comments
mingkang111 Jul 19, 2024
3ccdf44
changed error type
mingkang111 Jul 19, 2024
c52e9f5
added more pydoc
mingkang111 Jul 22, 2024
ad67b58
added example of customized usage
mingkang111 Jul 22, 2024
39ac70f
Merge pull request #1 from mingkang111/oci_integration_update
mingkang111 Jul 22, 2024
0505a52
Merge branch 'odsc_integration_improvement' of github.com:mingkang111…
mingkang111 Jul 22, 2024
4f00e4d
made improvement on chatmodel
mingkang111 Jul 22, 2024
35dcd72
added tgi chat model
mingkang111 Jul 23, 2024
7cce776
added tgi chat model
mingkang111 Jul 23, 2024
cd9d29f
improvements on documentation
mingkang111 Jul 24, 2024
fe4bbbb
renamed files
mingkang111 Jul 24, 2024
631d75d
renamed files
mingkang111 Jul 24, 2024
2fa1630
renamed files
mingkang111 Jul 24, 2024
a638dac
fixed by comments
mingkang111 Jul 24, 2024
1ece89e
Merge pull request #3 from mingkang111/chatmodel_plugin
mingkang111 Jul 25, 2024
e9ce071
resolved conflicts
mingkang111 Jul 30, 2024
51a65ac
clean code
mingkang111 Jul 30, 2024
48ac568
Merge remote-tracking branch 'mingkang111_langchain/odsc_integration_…
mrDzurb Aug 22, 2024
8020fc2
Merge branch 'master' of github.com:langchain-ai/langchain into langc…
qiuosier Sep 30, 2024
08e8743
Update LLM and Chat Model.
qiuosier Sep 30, 2024
5311bc1
Add tests.
qiuosier Sep 30, 2024
05fb9f5
Update notebooks.
qiuosier Sep 30, 2024
01c499b
Update imports from langchain-openai.
qiuosier Sep 30, 2024
b9209c0
Merge pull request #1 from mrDzurb/qq/updates
qiuosier Oct 1, 2024
1998369
Fix typo in docstring.
qiuosier Oct 1, 2024
c18d5a7
Require langchain-openai for chat model tests.
qiuosier Oct 1, 2024
20ef517
Add Oracle copyright
qiuosier Oct 2, 2024
b6a98ee
Update chat model test.
qiuosier Oct 2, 2024
0bf8f7c
Merge remote-tracking branch 'origin/master' into qq/oci_data_science
qiuosier Oct 2, 2024
eb78ae6
Update chat model docstring.
qiuosier Oct 2, 2024
f5b82ff
Update docstring.
qiuosier Oct 3, 2024
805530e
Update API docs.
qiuosier Oct 3, 2024
4248f42
Use model_validator instead of pre_init.
qiuosier Oct 3, 2024
529d03a
Update imports.
qiuosier Oct 3, 2024
3fa79b2
Reduce current_count to 127 in check_pydantic.sh
qiuosier Oct 3, 2024
4059ef3
Remove extra blank lines.
qiuosier Oct 3, 2024
9589318
Update import and docstrings.
qiuosier Oct 3, 2024
7ac26e6
Update imports.
qiuosier Oct 3, 2024
5cac14c
Update imports.
qiuosier Oct 3, 2024
4ffdde9
Update docstring.
qiuosier Oct 3, 2024
d4cdbac
Add langchain_openai as test dependency.
qiuosier Oct 3, 2024
542063b
Format tests.
qiuosier Oct 3, 2024
13f8398
Update typing in tests.
qiuosier Oct 3, 2024
64e9c8d
Update typing in tests.
qiuosier Oct 3, 2024
8852e49
Update tests.
qiuosier Oct 3, 2024
d107d3d
Update typing in tests.
qiuosier Oct 3, 2024
b21fa0b
Update docs.
qiuosier Oct 3, 2024
fa03e75
Merge branch 'master' into qq/oci_data_science
qiuosier Oct 3, 2024
e8dcf84
Replace region with placeholder.
qiuosier Oct 3, 2024
9a0de2a
Merge branch 'master' into qq/oci_data_science
qiuosier Oct 4, 2024
c224193
Merge branch 'master' into qq/oci_data_science
qiuosier Oct 4, 2024
f32b0f0
Merge branch 'master' into qq/oci_data_science
qiuosier Oct 8, 2024
e346bd7
Merge remote-tracking branch 'origin/master' into qq/oci_data_science
qiuosier Oct 11, 2024
7784005
Move is_lc_serializable() to OCI base class.
qiuosier Oct 11, 2024
5e57604
Merge branch 'master' into qq/oci_data_science
efriis Oct 15, 2024
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
460 changes: 460 additions & 0 deletions docs/docs/integrations/chat/oci_data_science.ipynb

Large diffs are not rendered by default.

105 changes: 92 additions & 13 deletions docs/docs/integrations/llms/oci_model_deployment_endpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"\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",
"> For the latest updates, examples and experimental features, please see [ADS LangChain Integration](https://accelerated-data-science.readthedocs.io/en/latest/user_guide/large_language_model/langchain_models.html).\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."
"For authentication, the [oracle-ads](https://accelerated-data-science.readthedocs.io/en/latest/user_guide/cli/authentication.html) library is used to automatically load credentials required for invoking the endpoint."
]
},
{
Expand All @@ -29,29 +31,52 @@
"## 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",
"You can easily deploy, fine-tune, and evaluate foundation models using the [AI Quick Actions](https://docs.oracle.com/en-us/iaas/data-science/using/ai-quick-actions.htm) on OCI Data Science Model deployment. For additional deployment examples, please visit the [Oracle GitHub samples repository](https://github.com/oracle-samples/oci-data-science-ai-samples/blob/main/ai-quick-actions/llama3-with-smc.md). \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",
"After having deployed model, you have to set up following required parameters of the call:\n",
"\n",
"### Text generation inference (TGI)\n",
"You have to set up following required parameters of the `OCIModelDeploymentTGI` call:\n",
"- **`endpoint`**: The model HTTP endpoint from the deployed model, e.g. `https://modeldeployment.<region>.oci.customer-oci.com/<md_ocid>/predict`. \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"
"## Examples"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ads\n",
"from langchain_community.llms import OCIModelDeploymentLLM\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",
"# Using generic class as entry point, you will be able\n",
"# to pass model parameters through model_kwargs during\n",
"# instantiation.\n",
"llm = OCIModelDeploymentLLM(\n",
" endpoint=\"https://modeldeployment.<region>.oci.customer-oci.com/<md_ocid>/predict\",\n",
" model=\"odsc-llm\",\n",
")\n",
"\n",
"# Run the LLM\n",
"llm.invoke(\"Who is the first president of United States?\")"
]
},
{
Expand All @@ -71,7 +96,11 @@
"\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",
"# Using framework specific class as entry point, you will\n",
"# be able to pass model parameters in constructor.\n",
"llm = OCIModelDeploymentVLLM(\n",
" endpoint=\"https://modeldeployment.<region>.oci.customer-oci.com/<md_ocid>/predict\",\n",
")\n",
"\n",
"# Run the LLM\n",
"llm.invoke(\"Who is the first president of United States?\")"
Expand All @@ -97,14 +126,64 @@
"\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",
"os.environ[\"OCI_LLM_ENDPOINT\"] = (\n",
" \"https://modeldeployment.<region>.oci.customer-oci.com/<md_ocid>/predict\"\n",
")\n",
"\n",
"# Create an instance of OCI Model Deployment Endpoint\n",
"# Using framework specific class as entry point, you will\n",
"# be able to pass model parameters in constructor.\n",
"llm = OCIModelDeploymentTGI()\n",
"\n",
"# Run the LLM\n",
"llm.invoke(\"Who is the first president of United States?\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Asynchronous calls"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"await llm.ainvoke(\"Tell me a joke.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Streaming calls"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for chunk in llm.stream(\"Tell me a joke.\"):\n",
" print(chunk, end=\"\", flush=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## API reference\n",
"\n",
"For comprehensive details on all features and configurations, please refer to the API reference documentation for each class:\n",
"\n",
"* [OCIModelDeploymentLLM](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.oci_data_science_model_deployment_endpoint.OCIModelDeploymentLLM.html)\n",
"* [OCIModelDeploymentVLLM](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.oci_data_science_model_deployment_endpoint.OCIModelDeploymentVLLM.html)\n",
"* [OCIModelDeploymentTGI](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.oci_data_science_model_deployment_endpoint.OCIModelDeploymentTGI.html)"
]
}
],
"metadata": {
Expand Down
10 changes: 4 additions & 6 deletions docs/docs/integrations/providers/oci.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,18 @@ from langchain_community.embeddings import OCIGenAIEmbeddings
> as an OCI Model Deployment Endpoint using the
> [OCI Data Science Model Deployment Service](https://docs.oracle.com/en-us/iaas/data-science/using/model-dep-about.htm).

If you deployed a LLM with the VLLM or TGI framework, you can use the
`OCIModelDeploymentVLLM` or `OCIModelDeploymentTGI` classes to interact with it.

To use, you should have the latest `oracle-ads` python SDK installed.

```bash
pip install -U oracle-ads
```

See [usage examples](/docs/integrations/llms/oci_model_deployment_endpoint).
See [chat](/docs/integrations/chat/oci_data_science) and [complete](/docs/integrations/llms/oci_model_deployment_endpoint) usage examples.


```python
from langchain_community.llms import OCIModelDeploymentVLLM
from langchain_community.chat_models import ChatOCIModelDeployment

from langchain_community.llms import OCIModelDeploymentTGI
from langchain_community.llms import OCIModelDeploymentLLM
```

1 change: 1 addition & 0 deletions libs/community/extended_testing_deps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jinja2>=3,<4
jq>=1.4.1,<2
jsonschema>1
keybert>=0.8.5
langchain_openai>=0.2.1
litellm>=1.30,<=1.39.5
lxml>=4.9.3,<6.0
markdownify>=0.11.6,<0.12
Expand Down
11 changes: 11 additions & 0 deletions libs/community/langchain_community/chat_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@
from langchain_community.chat_models.moonshot import (
MoonshotChat,
)
from langchain_community.chat_models.oci_data_science import (
ChatOCIModelDeployment,
ChatOCIModelDeploymentTGI,
ChatOCIModelDeploymentVLLM,
)
from langchain_community.chat_models.oci_generative_ai import (
ChatOCIGenAI, # noqa: F401
)
Expand Down Expand Up @@ -211,6 +216,9 @@
"ChatMlflow",
"ChatNebula",
"ChatOCIGenAI",
"ChatOCIModelDeployment",
"ChatOCIModelDeploymentVLLM",
"ChatOCIModelDeploymentTGI",
"ChatOllama",
"ChatOpenAI",
"ChatPerplexity",
Expand Down Expand Up @@ -272,6 +280,9 @@
"ChatNebula": "langchain_community.chat_models.symblai_nebula",
"ChatOctoAI": "langchain_community.chat_models.octoai",
"ChatOCIGenAI": "langchain_community.chat_models.oci_generative_ai",
"ChatOCIModelDeployment": "langchain_community.chat_models.oci_data_science",
"ChatOCIModelDeploymentVLLM": "langchain_community.chat_models.oci_data_science",
"ChatOCIModelDeploymentTGI": "langchain_community.chat_models.oci_data_science",
"ChatOllama": "langchain_community.chat_models.ollama",
"ChatOpenAI": "langchain_community.chat_models.openai",
"ChatPerplexity": "langchain_community.chat_models.perplexity",
Expand Down
Loading
Loading