Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a link typo /-/route -> /-/routes. and change endpoint format #6186

Merged
merged 4 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "9597802c",
"metadata": {},
Expand All @@ -9,7 +10,9 @@
"\n",
"[Anyscale](https://www.anyscale.com/) is a fully-managed [Ray](https://www.ray.io/) platform, on which you can build, deploy, and manage scalable AI and Python applications\n",
"\n",
"This example goes over how to use LangChain to interact with `Anyscale` [service](https://docs.anyscale.com/productionize/services-v2/get-started)"
"This example goes over how to use LangChain to interact with `Anyscale` [service](https://docs.anyscale.com/productionize/services-v2/get-started). \n",
"\n",
"It will send the requests to Anyscale Service endpoint, which is concatenate `ANYSCALE_SERVICE_URL` and `ANYSCALE_SERVICE_ROUTE`, with a token defined in `ANYSCALE_SERVICE_TOKEN`"
]
},
{
Expand Down Expand Up @@ -96,6 +99,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "42f05b34-1a44-4cbd-8342-35c1572b6765",
"metadata": {},
Expand Down
9 changes: 7 additions & 2 deletions langchain/llms/anyscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,17 @@ def validate_environment(cls, values: Dict) -> Dict:
anyscale_service_token = get_from_dict_or_env(
values, "anyscale_service_token", "ANYSCALE_SERVICE_TOKEN"
)
if anyscale_service_url.endswith("/"):
anyscale_service_url = anyscale_service_url[:-1]
if not anyscale_service_route.startswith("/"):
anyscale_service_route = "/" + anyscale_service_route
try:
anyscale_service_endpoint = f"{anyscale_service_url}/-/route"
anyscale_service_endpoint = f"{anyscale_service_url}/-/routes"
headers = {"Authorization": f"Bearer {anyscale_service_token}"}
requests.get(anyscale_service_endpoint, headers=headers)
except requests.exceptions.RequestException as e:
raise ValueError(e)

values["anyscale_service_url"] = anyscale_service_url
values["anyscale_service_route"] = anyscale_service_route
values["anyscale_service_token"] = anyscale_service_token
Expand Down Expand Up @@ -102,7 +107,7 @@ def _call(
"""

anyscale_service_endpoint = (
f"{self.anyscale_service_url}/{self.anyscale_service_route}"
f"{self.anyscale_service_url}{self.anyscale_service_route}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens if the user provides a URL with no trailing slash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Even though the provided anyscale_service_url and anyscale_service_service format should have correct format, I'm adding some validation code to ensure it

)
headers = {"Authorization": f"Bearer {self.anyscale_service_token}"}
body = {"prompt": prompt}
Expand Down