From 3ced372ca2d8cf4571f16f75967794401ddfb9be Mon Sep 17 00:00:00 2001 From: Krish Dholakia Date: Mon, 14 Aug 2023 19:32:02 -0700 Subject: [PATCH 1/2] adding support for Palm, Cohere, HF Inference Endpoints, Replicate --- realtime_ai_character/llm/openai_llm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/realtime_ai_character/llm/openai_llm.py b/realtime_ai_character/llm/openai_llm.py index ef736345b..7798e45b8 100644 --- a/realtime_ai_character/llm/openai_llm.py +++ b/realtime_ai_character/llm/openai_llm.py @@ -5,7 +5,7 @@ if os.getenv('OPENAI_API_TYPE') == 'azure': from langchain.chat_models import AzureChatOpenAI else: - from langchain.chat_models import ChatOpenAI + from langchain.chat_models import ChatLiteLLM from langchain.schema import BaseMessage, HumanMessage from realtime_ai_character.database.chroma import get_chroma @@ -28,7 +28,7 @@ def __init__(self, model): streaming=True ) else: - self.chat_open_ai = ChatOpenAI( + self.chat_open_ai = ChatLiteLLM( model=model, temperature=0.5, streaming=True From 789a091c7404fe5aa23a88f0cf07efae1b0884f8 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Sat, 2 Sep 2023 14:37:30 -0700 Subject: [PATCH 2/2] Update Readme with usage instructions --- README.md | 12 +++++++++++- realtime_ai_character/llm/__init__.py | 4 ++-- realtime_ai_character/llm/openai_llm.py | 7 ++++--- requirements.txt | 1 + 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 617ed0ee5..ed437e378 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ Note if you want to remotely connect to a RealChar server, SSL set up is require
-## πŸ†•! Anyscale and LangSmith integration +## πŸ†•! Anyscale, LangSmith, LiteLLM integrations
πŸ‘‡click me ### Anyscale @@ -265,6 +265,16 @@ LANGCHAIN_PROJECT=YOUR_LANGCHAIN_PROJECT ``` And it should work out of the box. + +### LiteLLM +Use any model from Replicate, Cohere, AI21, Huggingface, TogetherAI, Aleph Alpha, and more - https://docs.litellm.ai/docs/completion/supported + +in your .env, just set the `LITELLM_API_KEY` to be the one for any of the providers you want to use +``` +LITELLM_API_KEY="" # this is the api key for any of the providers supported by litellm +``` + +and this will be passed to litellm to use!

diff --git a/realtime_ai_character/llm/__init__.py b/realtime_ai_character/llm/__init__.py index 8c557b302..436083304 100644 --- a/realtime_ai_character/llm/__init__.py +++ b/realtime_ai_character/llm/__init__.py @@ -1,8 +1,8 @@ from realtime_ai_character.llm.base import AsyncCallbackAudioHandler, AsyncCallbackTextHandler, LLM - +import litellm def get_llm(model='gpt-3.5-turbo-16k') -> LLM: - if model.startswith('gpt'): + if model.startswith('gpt') or model in litellm.model_list or model.split("/")[0] in litellm.provider_list: from realtime_ai_character.llm.openai_llm import OpenaiLlm return OpenaiLlm(model=model) elif model.startswith('claude'): diff --git a/realtime_ai_character/llm/openai_llm.py b/realtime_ai_character/llm/openai_llm.py index ef736345b..7b658b225 100644 --- a/realtime_ai_character/llm/openai_llm.py +++ b/realtime_ai_character/llm/openai_llm.py @@ -5,7 +5,7 @@ if os.getenv('OPENAI_API_TYPE') == 'azure': from langchain.chat_models import AzureChatOpenAI else: - from langchain.chat_models import ChatOpenAI + from langchain.chat_models import ChatLiteLLM from langchain.schema import BaseMessage, HumanMessage from realtime_ai_character.database.chroma import get_chroma @@ -28,10 +28,11 @@ def __init__(self, model): streaming=True ) else: - self.chat_open_ai = ChatOpenAI( + self.chat_open_ai = ChatLiteLLM( model=model, temperature=0.5, - streaming=True + streaming=True, + api_key=os.getenv("LITELLM_API_KEY") ) self.config = { "model": model, diff --git a/requirements.txt b/requirements.txt index 2802037d9..2a9a2ee03 100644 --- a/requirements.txt +++ b/requirements.txt @@ -36,3 +36,4 @@ typing uvicorn websockets google-auth +litellm \ No newline at end of file