Skip to content

Commit 55d00da

Browse files
authored
fix: added support for google vertexAI (#252)
added support for llm, chat and embeddings ```py from langchain.llms import VertexAI from langchain.chat_models import ChatVertexAI from ragas.llms import LangchainLLM from ragas.metrics import faithfulness llm = VertexAI(credentials=creds) chat = ChatVertexAI(credentials=creds) ragas_llm = LangchainLLM(llm) faithfulness.llm = ragas_llm ``` if your looking to change the embeddings as well ```py from langchain.embeddings import VertexAIEmbeddings from ragas.metrics import AnswerRelevancy embeddings = VertexAIEmbeddings(credentials=creds) ar = AnswerRelevancy(embeddings=embeddings) # now you can use it as normal r = evaluate(fiqa_eval.select(range(3)), metrics=[ar]) ```
1 parent e86f951 commit 55d00da

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/ragas/llms/base.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import typing as t
55
from abc import ABC, abstractmethod
66

7-
from langchain.chat_models import AzureChatOpenAI, ChatOpenAI, BedrockChat
7+
from langchain.chat_models import AzureChatOpenAI, BedrockChat, ChatOpenAI, ChatVertexAI
88
from langchain.chat_models.base import BaseChatModel
9-
from langchain.llms import AzureOpenAI, OpenAI, Bedrock
9+
from langchain.llms import AzureOpenAI, Bedrock, OpenAI, VertexAI
1010
from langchain.llms.base import BaseLLM
1111
from langchain.schema import LLMResult
1212

@@ -20,13 +20,22 @@
2020
def isOpenAI(llm: BaseLLM | BaseChatModel) -> bool:
2121
return isinstance(llm, OpenAI) or isinstance(llm, ChatOpenAI)
2222

23+
2324
def isBedrock(llm: BaseLLM | BaseChatModel) -> bool:
2425
return isinstance(llm, Bedrock) or isinstance(llm, BedrockChat)
2526

27+
2628
# have to specify it twice for runtime and static checks
27-
MULTIPLE_COMPLETION_SUPPORTED = [OpenAI, ChatOpenAI, AzureOpenAI, AzureChatOpenAI]
29+
MULTIPLE_COMPLETION_SUPPORTED = [
30+
OpenAI,
31+
ChatOpenAI,
32+
AzureOpenAI,
33+
AzureChatOpenAI,
34+
ChatVertexAI,
35+
VertexAI,
36+
]
2837
MultipleCompletionSupportedLLM = t.Union[
29-
OpenAI, ChatOpenAI, AzureOpenAI, AzureChatOpenAI
38+
OpenAI, ChatOpenAI, AzureOpenAI, AzureChatOpenAI, ChatVertexAI, VertexAI
3039
]
3140

3241

0 commit comments

Comments
 (0)