From 3a58c4c3a0c6c2e41c30de3f2730b42cbeea3ca7 Mon Sep 17 00:00:00 2001 From: kYLe Date: Tue, 20 Jun 2023 00:05:54 -0500 Subject: [PATCH] Fixed a link typo /-/route -> /-/routes. and change endpoint format (#6186) Fixes a link typo from `/-/route` to `/-/routes`. and change endpoint format from `f"{self.anyscale_service_url}/{self.anyscale_service_route}"` to `f"{self.anyscale_service_url}{self.anyscale_service_route}"` Also adding documentation about the format of the endpoint #### Before submitting #### Who can review? Tag maintainers/contributors who might be interested: --------- Co-authored-by: Harrison Chase --- .../model_io/models/llms/integrations/anyscale.ipynb | 6 +++++- langchain/llms/anyscale.py | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/extras/modules/model_io/models/llms/integrations/anyscale.ipynb b/docs/extras/modules/model_io/models/llms/integrations/anyscale.ipynb index ec2732cf..3f9e2cc0 100644 --- a/docs/extras/modules/model_io/models/llms/integrations/anyscale.ipynb +++ b/docs/extras/modules/model_io/models/llms/integrations/anyscale.ipynb @@ -1,6 +1,7 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "id": "9597802c", "metadata": {}, @@ -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`" ] }, { @@ -96,6 +99,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "42f05b34-1a44-4cbd-8342-35c1572b6765", "metadata": {}, diff --git a/langchain/llms/anyscale.py b/langchain/llms/anyscale.py index 8baa9225..307efd1e 100644 --- a/langchain/llms/anyscale.py +++ b/langchain/llms/anyscale.py @@ -59,12 +59,17 @@ class Anyscale(LLM): 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 @@ -102,7 +107,7 @@ class Anyscale(LLM): """ anyscale_service_endpoint = ( - f"{self.anyscale_service_url}/{self.anyscale_service_route}" + f"{self.anyscale_service_url}{self.anyscale_service_route}" ) headers = {"Authorization": f"Bearer {self.anyscale_service_token}"} body = {"prompt": prompt}