Skip to content

Commit

Permalink
community[patch]: Remove model limitation on Anyscale LLM (langchain-…
Browse files Browse the repository at this point in the history
…ai#17662)

**Description:** Llama Guard is deprecated from Anyscale public
endpoint.
**Issue:** Change the default model. and remove the limitation of only
use Llama Guard with Anyscale LLMs
Anyscale LLM can also works with all other Chat model hosted on
Anyscale.
Also added `async_client` for Anyscale LLM
  • Loading branch information
kYLe authored and joakimeriksson committed Feb 26, 2024
1 parent 7f4cb28 commit 3f45d50
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions libs/community/langchain_community/llms/anyscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
from langchain_community.utils.openai import is_openai_v1

DEFAULT_BASE_URL = "https://api.endpoints.anyscale.com/v1"
DEFAULT_MODEL = "Meta-Llama/Llama-Guard-7b"

# Completion models support by Anyscale Endpoints
COMPLETION_MODELS = ["Meta-Llama/Llama-Guard-7b"]
DEFAULT_MODEL = "mistralai/Mixtral-8x7B-Instruct-v0.1"


def update_token_usage(
Expand Down Expand Up @@ -113,12 +110,6 @@ def validate_environment(cls, values: Dict) -> Dict:
"MODEL_NAME",
default=DEFAULT_MODEL,
)
if values["model_name"] not in COMPLETION_MODELS:
raise ValueError(
"langchain_community.llm.Anyscale ONLY works \
with completions models.For Chat models, please use \
langchain_community.chat_model.ChatAnyscale"
)

try:
import openai
Expand All @@ -135,7 +126,12 @@ def validate_environment(cls, values: Dict) -> Dict:
# "default_query": values["default_query"],
# "http_client": values["http_client"],
}
values["client"] = openai.OpenAI(**client_params).completions
if not values.get("client"):
values["client"] = openai.OpenAI(**client_params).completions
if not values.get("async_client"):
values["async_client"] = openai.AsyncOpenAI(
**client_params
).completions
else:
values["openai_api_base"] = values["anyscale_api_base"]
values["openai_api_key"] = values["anyscale_api_key"].get_secret_value()
Expand Down

0 comments on commit 3f45d50

Please sign in to comment.