diff --git a/README.md b/README.md index 21cafd017..038a8efce 100644 --- a/README.md +++ b/README.md @@ -259,7 +259,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 @@ -279,6 +279,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 32feddfd8..d07ca851c 100644 --- a/realtime_ai_character/llm/__init__.py +++ b/realtime_ai_character/llm/__init__.py @@ -1,13 +1,8 @@ -import os -from functools import cache +from realtime_ai_character.llm.base import AsyncCallbackAudioHandler, AsyncCallbackTextHandler, LLM +import litellm -from langchain.chat_models.base import BaseChatModel - -from realtime_ai_character.llm.base import LLM - - -def get_llm(model="gpt-3.5-turbo-16k") -> LLM: - if model.startswith('gpt'): +def get_llm(model='gpt-3.5-turbo-16k') -> LLM: + 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 72173354f..a7d6d8339 100644 --- a/realtime_ai_character/llm/openai_llm.py +++ b/realtime_ai_character/llm/openai_llm.py @@ -31,7 +31,8 @@ def __init__(self, model): 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 ab3cccf7a..871f0a7e4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -38,3 +38,4 @@ typing uvicorn websockets google-auth +litellm \ No newline at end of file