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