From 76a1265eee946709211308a575893a693707e009 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 19 Jun 2023 12:37:33 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20docs(README.md):=20update=20Lang?= =?UTF-8?q?flow=20API=20usage=20example=20and=20add=20tweaks=20parameter?= =?UTF-8?q?=20The=20Langflow=20API=20usage=20example=20has=20been=20update?= =?UTF-8?q?d=20to=20reflect=20the=20new=20API=20endpoint=20URL.=20Addition?= =?UTF-8?q?ally,=20a=20new=20optional=20`tweaks`=20parameter=20has=20been?= =?UTF-8?q?=20added=20to=20the=20`run=5Fflow`=20function=20to=20allow=20cu?= =?UTF-8?q?stomization=20of=20the=20flow.=20The=20example=20code=20has=20b?= =?UTF-8?q?een=20updated=20to=20demonstrate=20how=20to=20use=20the=20`twea?= =?UTF-8?q?ks`=20parameter.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index bd377896c..8e3930997 100644 --- a/README.md +++ b/README.md @@ -50,11 +50,11 @@ Alternatively, click the **"Open in Cloud Shell"** button below to launch Google Langflow integrates with langchain-serve to provide a one-command deployment to Jina AI Cloud. -Start by installing `langchain-serve` with +Start by installing `langchain-serve` with ```bash pip install -U langchain-serve -``` +``` Then, run: @@ -109,24 +109,38 @@ You can use Langflow directly on your browser, or use the API endpoints on Jina Show API usage (with python) ```python - import json - import requests +import requests - FLOW_PATH = "Time_traveller.json" +BASE_API_URL = "https://langflow-e3dd8820ec.wolf.jina.ai/api/v1/predict" +FLOW_ID = "864c4f98-2e59-468b-8e13-79cd8da07468" +# You can tweak the flow by adding a tweaks dictionary +# e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}} +TWEAKS = { + "ChatOpenAI-g4jEr": {}, + "ConversationChain-UidfJ": {} +} - # HOST = 'http://localhost:7860' - HOST = 'https://langflow-f1ed20e309.wolf.jina.ai' - API_URL = f'{HOST}/predict' +def run_flow(message: str, flow_id: str, tweaks: dict = None) -> dict: + """ + Run a flow with a given message and optional tweaks. - def predict(message): - with open(FLOW_PATH, "r") as f: - json_data = json.load(f) - payload = {'exported_flow': json_data, 'message': message} - response = requests.post(API_URL, json=payload) - return response.json() + :param message: The message to send to the flow + :param flow_id: The ID of the flow to run + :param tweaks: Optional tweaks to customize the flow + :return: The JSON response from the flow + """ + api_url = f"{BASE_API_URL}/{flow_id}" + payload = {"message": message} - predict('Take me to 1920s Bangalore') + if tweaks: + payload["tweaks"] = tweaks + + response = requests.post(api_url, json=payload) + return response.json() + +# Setup any tweaks you want to apply to the flow +print(run_flow("Your message", flow_id=FLOW_ID, tweaks=TWEAKS)) ``` ```json