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

Update LangChain LLMs and Add Chat Models Support #953

Merged
merged 28 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
73a42cf
Add new LangChain llm module.
qiuosier Sep 23, 2024
42859cf
Add LangChain chat model module.
qiuosier Sep 23, 2024
1494347
Remove LangChain plugins for OCI generative AI.
qiuosier Sep 23, 2024
1ff5374
Remove old versions of llm plugins.
qiuosier Sep 23, 2024
f37d14c
Remove RetrievalQA from serialize.
qiuosier Sep 23, 2024
96e16ca
Update to support pydantic v2
qiuosier Sep 23, 2024
9dbbe5f
Add copyrights.
qiuosier Sep 23, 2024
d9721b9
Add chat template.
qiuosier Sep 23, 2024
6d3ed30
Add tool calling for vLLM.
qiuosier Sep 23, 2024
845c5e4
Add chat template for hermes model.
qiuosier Sep 24, 2024
ce6d4e5
Update test for LangChain LLMs.
qiuosier Sep 25, 2024
3d9ecfd
Update tests.
qiuosier Sep 25, 2024
bee6a92
Add tests for chat model.
qiuosier Sep 26, 2024
2e2ee0e
Update tests.
qiuosier Sep 26, 2024
3eca98a
Remove extra print statements.
qiuosier Sep 26, 2024
f6a5248
Skip tests that needs to be updated.
qiuosier Sep 26, 2024
a423f75
Update dependency and licenses.
qiuosier Sep 26, 2024
56bc9a7
Update dependency to langchain>=0.2
qiuosier Sep 26, 2024
fad5185
Merge branch 'main' into feature/langchain
qiuosier Sep 26, 2024
5a32624
Add langchain_openai as dependency for LangChain integration.
qiuosier Sep 26, 2024
5e6cd8c
Merge remote-tracking branch 'origin/feature/langchain' into feature/…
qiuosier Sep 26, 2024
777400e
Update docs for LangChain.
qiuosier Sep 26, 2024
97f5364
Skip LangChain test for Python 3.8.
qiuosier Sep 26, 2024
d3b9aeb
Add python 3.9 requirement to LangChain docs.
qiuosier Sep 26, 2024
8b84923
Update LangChain docs.
qiuosier Sep 26, 2024
7ad8616
Skip guardrail test for python<=3.8
qiuosier Sep 27, 2024
8cec512
Update copyright info in tests.
qiuosier Sep 27, 2024
ecbc0c8
Skip guardrail tests on python 3.8
qiuosier Sep 30, 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
12 changes: 12 additions & 0 deletions THIRD_PARTY_LICENSES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ langchain
* Source code: https://github.com/langchain-ai/langchain
* Project home: https://www.langchain.com/

langchain-community
* Copyright (c) 2023 LangChain, Inc.
* License: MIT license
* Source code: https://github.com/langchain-ai/langchain/tree/master/libs/community
* Project home: https://github.com/langchain-ai/langchain/tree/master/libs/community

langchain-openai
* Copyright (c) 2023 LangChain, Inc.
* License: MIT license
* Source code: https://github.com/langchain-ai/langchain/tree/master/libs/partners/openai
* Project home: https://github.com/langchain-ai/langchain/tree/master/libs/partners/openai

lightgbm
* Copyright (c) 2023 Microsoft Corporation
* License: MIT license
Expand Down
14 changes: 10 additions & 4 deletions ads/llm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@

try:
import langchain
from ads.llm.langchain.plugins.llm_gen_ai import GenerativeAI
from ads.llm.langchain.plugins.llm_md import ModelDeploymentTGI
from ads.llm.langchain.plugins.llm_md import ModelDeploymentVLLM
from ads.llm.langchain.plugins.embeddings import GenerativeAIEmbeddings
from ads.llm.langchain.plugins.llms.oci_data_science_model_deployment_endpoint import (
OCIModelDeploymentVLLM,
OCIModelDeploymentTGI,
)
from ads.llm.langchain.plugins.chat_models.oci_data_science import (
ChatOCIModelDeployment,
ChatOCIModelDeploymentVLLM,
ChatOCIModelDeploymentTGI,
)
from ads.llm.chat_template import ChatTemplates
except ImportError as ex:
if ex.name == "langchain":
raise ImportError(
Expand Down
31 changes: 31 additions & 0 deletions ads/llm/chat_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*--

# Copyright (c) 2023 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/


import os


class ChatTemplates:
"""Contains chat templates."""

@staticmethod
def _read_template(filename):
with open(
os.path.join(os.path.dirname(__file__), "templates", filename),
mode="r",
encoding="utf-8",
) as f:
return f.read()

@staticmethod
def mistral():
"""Chat template for auto tool calling with Mistral model deploy with vLLM."""
return ChatTemplates._read_template("tool_chat_template_mistral_parallel.jinja")

@staticmethod
def hermes():
"""Chat template for auto tool calling with Hermes model deploy with vLLM."""
return ChatTemplates._read_template("tool_chat_template_hermes.jinja")
5 changes: 3 additions & 2 deletions ads/llm/guardrails/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from typing import Any, List, Dict, Tuple
from langchain.schema.prompt import PromptValue
from langchain.tools.base import BaseTool, ToolException
from langchain.pydantic_v1 import BaseModel, root_validator
from pydantic import BaseModel, model_validator


class RunInfo(BaseModel):
Expand Down Expand Up @@ -190,7 +190,8 @@ class Config:
This is used by the ``apply_filter()`` method.
"""

@root_validator
@model_validator(mode="before")
@classmethod
def default_name(cls, values):
"""Sets the default name of the guardrail."""
if not values.get("name"):
Expand Down
2 changes: 1 addition & 1 deletion ads/llm/guardrails/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


import evaluate
from langchain.pydantic_v1 import root_validator
from pydantic.v1 import root_validator
from .base import Guardrail


Expand Down
118 changes: 0 additions & 118 deletions ads/llm/langchain/plugins/base.py

This file was deleted.

5 changes: 5 additions & 0 deletions ads/llm/langchain/plugins/chat_models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*--

# Copyright (c) 2023 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
Loading
Loading