Skip to content
Closed
Changes from all commits
Commits
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
35 changes: 27 additions & 8 deletions libs/langchain/langchain/llms/anyscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from langchain.llms.utils import enforce_stop_tokens
from langchain.utils import get_from_dict_or_env

ANYSCALE_ENDPOINT = "https://console.endpoints.anyscale.com"


class Anyscale(LLM):
"""Anyscale Service models.
Expand Down Expand Up @@ -110,14 +112,31 @@ def _call(
f"{self.anyscale_service_url}{self.anyscale_service_route}"
)
headers = {"Authorization": f"Bearer {self.anyscale_service_token}"}
body = {"prompt": prompt}
resp = requests.post(anyscale_service_endpoint, headers=headers, json=body)

if resp.status_code != 200:
raise ValueError(
f"Error returned by service, status code {resp.status_code}"
)
text = resp.text

if self.anyscale_service_url.startswith(ANYSCALE_ENDPOINT):
body = {
"model": "meta-llama/Llama-2-70b-chat-hf",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is a chat model should be implemented as ChatModel. can create a ChatAnyscale(ChatModel) class. happy to help if needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggest. I will close this PR for now and will work on it later

"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt},
],
"temperature": 0.7,
}
resp = requests.post(anyscale_service_endpoint, headers=headers, json=body)
if resp.status_code != 200:
raise ValueError(f"Error returned by service")
resp_json = resp.json()
text = resp_json["choices"][0]["message"]["content"]

else:
body = {"prompt": prompt}
resp = requests.post(anyscale_service_endpoint, headers=headers, json=body)

if resp.status_code != 200:
raise ValueError(
f"Error returned by service, status code {resp.status_code}"
)
text = resp.text

if stop is not None:
# This is a bit hacky, but I can't figure out a better way to enforce
Expand Down