Skip to content

Commit 9bc802e

Browse files
authored
Update ADS LLM/Guardrail documentation (#479)
2 parents 7801722 + 584307f commit 9bc802e

File tree

11 files changed

+551
-14
lines changed

11 files changed

+551
-14
lines changed

docs/source/ads.llm.guardrails.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
ads.llm.guardrails package
2+
==========================
3+
4+
.. toctree::
5+
:maxdepth: 3
6+
7+
ads.llm.guardrails
8+
9+
10+
Submodules
11+
----------
12+
13+
ads.llm.guardrails.base module
14+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15+
16+
.. automodule:: ads.llm.guardrails.base
17+
:members:
18+
:undoc-members:
19+
:show-inheritance:
20+
:inherited-members:
21+
22+
ads.llm.guardrails.huggingface module
23+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24+
25+
.. automodule:: ads.llm.guardrails.huggingface
26+
:members:
27+
:undoc-members:
28+
:show-inheritance:
29+
:inherited-members:
30+
31+
Module contents
32+
---------------
33+
34+
.. automodule:: ads.llm.guardrails
35+
:members:
36+
:undoc-members:
37+
:show-inheritance:
38+
:inherited-members:
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
ads.llm.langchain.plugins package
2+
=================================
3+
4+
.. toctree::
5+
:maxdepth: 3
6+
7+
ads.llm.langchain.plugins
8+
9+
10+
Submodules
11+
----------
12+
13+
ads.llm.langchain.plugins.base module
14+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15+
16+
.. automodule:: ads.llm.langchain.plugins.base
17+
:members:
18+
:undoc-members:
19+
:show-inheritance:
20+
:inherited-members:
21+
22+
ads.llm.langchain.plugins.contant module
23+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24+
25+
.. automodule:: ads.llm.langchain.plugins.contant
26+
:members:
27+
:undoc-members:
28+
:show-inheritance:
29+
:inherited-members:
30+
31+
ads.llm.langchain.plugins.embeddings module
32+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33+
34+
.. automodule:: ads.llm.langchain.plugins.embeddings
35+
:members:
36+
:undoc-members:
37+
:show-inheritance:
38+
:inherited-members:
39+
40+
ads.llm.langchain.plugins.llm\_gen\_ai module
41+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42+
43+
.. automodule:: ads.llm.langchain.plugins.llm_gen_ai
44+
:members:
45+
:undoc-members:
46+
:show-inheritance:
47+
:inherited-members:
48+
49+
ads.llm.langchain.plugins.llm\_md module
50+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51+
52+
.. automodule:: ads.llm.langchain.plugins.llm_md
53+
:members:
54+
:undoc-members:
55+
:show-inheritance:
56+
:inherited-members:
57+
58+
Module contents
59+
---------------
60+
61+
.. automodule:: ads.llm.langchain.plugins
62+
:members:
63+
:undoc-members:
64+
:show-inheritance:
65+
:inherited-members:

docs/source/ads.llm.langchain.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ads.llm.langchain package
2+
=========================
3+
4+
.. toctree::
5+
:maxdepth: 3
6+
7+
ads.llm.langchain
8+
9+
10+
Subpackages
11+
-----------
12+
13+
.. toctree::
14+
:maxdepth: 3
15+
16+
ads.llm.langchain.plugins
17+
18+
Module contents
19+
---------------
20+
21+
.. automodule:: ads.llm.langchain
22+
:members:
23+
:undoc-members:
24+
:show-inheritance:
25+
:inherited-members:

docs/source/ads.llm.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
ads.llm package
2+
===============
3+
4+
.. toctree::
5+
:maxdepth: 3
6+
7+
ads.llm
8+
9+
10+
Subpackages
11+
-----------
12+
13+
.. toctree::
14+
:maxdepth: 3
15+
16+
ads.llm.guardrails
17+
ads.llm.langchain
18+
ads.llm.serializers
19+
20+
Submodules
21+
----------
22+
23+
ads.llm.chain module
24+
~~~~~~~~~~~~~~~~~~~~
25+
26+
.. automodule:: ads.llm.chain
27+
:members:
28+
:undoc-members:
29+
:show-inheritance:
30+
:inherited-members:
31+
32+
ads.llm.deploy module
33+
~~~~~~~~~~~~~~~~~~~~~
34+
35+
.. automodule:: ads.llm.deploy
36+
:members:
37+
:undoc-members:
38+
:show-inheritance:
39+
:inherited-members:
40+
41+
ads.llm.serialize module
42+
~~~~~~~~~~~~~~~~~~~~~~~~
43+
44+
.. automodule:: ads.llm.serialize
45+
:members:
46+
:undoc-members:
47+
:show-inheritance:
48+
:inherited-members:
49+
50+
Module contents
51+
---------------
52+
53+
.. automodule:: ads.llm
54+
:members:
55+
:undoc-members:
56+
:show-inheritance:
57+
:inherited-members:

docs/source/ads.llm.serializers.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
ads.llm.serializers package
2+
===========================
3+
4+
.. toctree::
5+
:maxdepth: 3
6+
7+
ads.llm.serializers
8+
9+
10+
Submodules
11+
----------
12+
13+
ads.llm.serializers.retrieval\_qa module
14+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15+
16+
.. automodule:: ads.llm.serializers.retrieval_qa
17+
:members:
18+
:undoc-members:
19+
:show-inheritance:
20+
:inherited-members:
21+
22+
ads.llm.serializers.runnable\_parallel module
23+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24+
25+
.. automodule:: ads.llm.serializers.runnable_parallel
26+
:members:
27+
:undoc-members:
28+
:show-inheritance:
29+
:inherited-members:
30+
31+
Module contents
32+
---------------
33+
34+
.. automodule:: ads.llm.serializers
35+
:members:
36+
:undoc-members:
37+
:show-inheritance:
38+
:inherited-members:

docs/source/user_guide/large_language_model/deploy_langchain_application.rst

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,56 @@
22
Deploy LangChain Application
33
############################
44

5-
Oracle ADS SDK now supports the deployment of LangChain application to OCI data science model deployment and you can easily do so just by writing a couple lines of code.
5+
Oracle ADS supports the deployment of LangChain application to OCI data science model deployment and you can easily do so just by writing a few lines of code.
66

77
.. versionadded:: 2.9.1
88

9+
.. admonition:: Installation
10+
:class: note
11+
12+
It is important to note that for ADS to serialize and deploy the LangChain application, all components used to build the application must be serializable. For more information regarding LLMs model serialization, see `here <https://python.langchain.com/docs/modules/model_io/llms/llm_serialization>`_.
13+
914
Configuration
1015
*************
1116

1217
Ensure that you have created the necessary `policies, authentication, and authorization for model deployments <https://docs.oracle.com/en-us/iaas/data-science/using/model-dep-policies-auth.htm#model_dep_policies_auth>`_.
13-
Here we're using the ``resource_principal`` as auth type and you can configure the policy as below.
18+
For example, the following policy allows the dynamic group to use ``resource_principal`` to create model deployment.
1419

1520
.. code-block:: shell
1621
1722
allow dynamic-group <dynamic-group-name> to manage data-science-model-deployments in compartment <compartment-name>
1823
19-
Create LangChain Application
20-
****************************
24+
LangChain Application
25+
*********************
2126

22-
Create a simple LangChain application that links prompt and cohere model as below. Remember to replace the ``<cohere_api_key>`` with the actual cohere api key.
27+
Following is a simple LangChain application that build with a prompt template and large language model API. Here the ``Cohere`` model is used as an example. You may replace it with any other LangChain compatible LLM, including OCI Generative AI service.
2328

2429
.. code-block:: python3
2530
2631
import os
2732
from langchain.llms import Cohere
2833
from langchain.chains import LLMChain
2934
from langchain.prompts import PromptTemplate
35+
# Remember to replace the ``<cohere_api_key>`` with the actual cohere api key.
3036
os.environ["COHERE_API_KEY"] = "<cohere_api_key>"
3137
3238
cohere = Cohere()
3339
prompt = PromptTemplate.from_template("Tell me a joke about {subject}")
3440
llm_chain = LLMChain(prompt=prompt, llm=cohere, verbose=True)
3541
36-
Now you have a LangChain object ``llm_chain``. Try running it with the prompt ``{"subject": "animals"}`` and it should give you the corresponding result.
42+
Now you have a LangChain object ``llm_chain``. Try running it with the input ``{"subject": "animals"}`` and it should return a joke about animals.
3743

3844
.. code-block:: python3
3945
40-
llm_chain.run({"subject": "animals"})
46+
llm_chain.invoke({"subject": "animals"})
4147
4248
Initialize the ChainDeployment
4349
******************************
4450

45-
Initialize class ``ChainDeployment`` from ADS SDK and pass the LangChain object ``llm_chain`` from previous step as parameter.
46-
The ``artifact_dir`` is an optional parameter which points to the folder where the model artifacts will be put locally.
47-
In this example, we're using a temporary folder generated by ``tempfile``.
51+
ADS provides the ``ChainDeployment`` to handle the deployment of LangChain applications.
52+
You can initialize ``ChainDeployment`` with the LangChain object ``llm_chain`` from previous section as parameter.
53+
The ``artifact_dir`` is an optional parameter which points to the folder where the model artifacts will be put locally.
54+
In this example, we're using a temporary folder generated by ``tempfile.mkdtemp()``.
4855

4956
.. code-block:: python3
5057
@@ -75,7 +82,7 @@ Here, replace ``custom_conda_environment_uri`` with your conda environment uri t
7582
inference_python_version="<python_version>",
7683
)
7784
78-
Below is the ``chain.yaml`` file that was saved from ``llm_chain`` object. For more information regarding LLMs model serialization, see `here <https://python.langchain.com/docs/modules/model_io/llms/llm_serialization>`_.
85+
Below is the ``chain.yaml`` file that was saved from ``llm_chain`` object.
7986

8087
.. code-block:: YAML
8188
@@ -110,6 +117,16 @@ Below is the ``chain.yaml`` file that was saved from ``llm_chain`` object. For m
110117
tags: null
111118
verbose: true
112119
120+
Verify the Serialized Application
121+
*********************************
122+
123+
Verify the serialized application by calling ``verify()`` to make sure it is working as expected.
124+
There will be error if your application is not fully serializable.
125+
126+
.. code-block:: python3
127+
128+
chain_deployment.verify({"subject": "animals"})
129+
113130
Save Artifacts to OCI Model Catalog
114131
***********************************
115132

0 commit comments

Comments
 (0)