mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-24 04:47:23 +08:00
docs: build OpenAPI spec and cut version 1.10 (#13537)
* build-api * bump-version-to-1.10 * fix-broken-links
This commit is contained in:
2
docs/versioned_docs/version-1.10.0/API-Reference/python-examples/.gitignore
vendored
Normal file
2
docs/versioned_docs/version-1.10.0/API-Reference/python-examples/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
__pycache__/
|
||||
*.pyc
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/build/{os.getenv('JOB_ID', '')}/events"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,18 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
job_id = os.environ.get("JOB_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
# Use the API's `event_delivery` query param to avoid keeping a streaming connection open.
|
||||
# For local smoke tests, polling returns a finite JSON response.
|
||||
url = f"{base}/api/v1/build/{job_id}/events?event_delivery=polling"
|
||||
|
||||
headers = {"accept": "application/json", "x-api-key": api_key}
|
||||
|
||||
response = requests.get(url, headers=headers, timeout=60)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,18 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/build/{os.getenv('FLOW_ID', '')}/flow"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
payload = {"inputs": {"input_value": "Tell me a story"}}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, json=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/build/{os.getenv('FLOW_ID', '')}/flow"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
payload = {
|
||||
"data": {"nodes": [], "edges": []},
|
||||
"inputs": {"input_value": "Your custom input here", "session": "session_id"},
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, json=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,18 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/build/{os.getenv('FLOW_ID', '')}/flow"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
payload = {"stop_component_id": "OpenAIModel-Uksag"}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, json=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v2/files"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("DELETE", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,17 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = (
|
||||
f"{os.getenv('LANGFLOW_URL', '')}/api/v1/files/delete/{os.getenv('FLOW_ID', '')}/2024-12-30_15-19-43_your_file.txt"
|
||||
)
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("DELETE", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v2/files/{os.getenv('FILE_ID', '')}"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("DELETE", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,35 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
fixtures = Path(__file__).resolve().parents[2] / "fixtures"
|
||||
upload_path = Path(os.environ.get("SAMPLE_UPLOAD_FILE", str(fixtures / "sample-upload.txt")))
|
||||
|
||||
headers = {"accept": "application/json", "x-api-key": api_key}
|
||||
|
||||
upload = requests.post(
|
||||
f"{base}/api/v1/files/upload/{flow_id}",
|
||||
headers=headers,
|
||||
files={"file": (upload_path.name, upload_path.read_bytes(), "text/plain")},
|
||||
timeout=30,
|
||||
)
|
||||
upload.raise_for_status()
|
||||
meta = upload.json()
|
||||
file_name = meta["file_path"].split("/")[-1]
|
||||
|
||||
download = requests.get(
|
||||
f"{base}/api/v1/files/download/{flow_id}/{file_name}",
|
||||
headers=headers,
|
||||
timeout=30,
|
||||
)
|
||||
download.raise_for_status()
|
||||
|
||||
out_path = Path("downloaded_file.txt")
|
||||
out_path.write_bytes(download.content)
|
||||
print(json.dumps({"saved_bytes": len(download.content), "path": str(out_path), "upload": meta}))
|
||||
@ -0,0 +1,33 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
fixtures = Path(__file__).resolve().parents[2] / "fixtures"
|
||||
upload_path = Path(os.environ.get("SAMPLE_UPLOAD_FILE", str(fixtures / "sample-upload.txt")))
|
||||
|
||||
headers = {"accept": "application/json", "x-api-key": api_key}
|
||||
|
||||
upload = requests.post(
|
||||
f"{base}/api/v2/files",
|
||||
headers=headers,
|
||||
files={"file": (upload_path.name, upload_path.read_bytes(), "text/plain")},
|
||||
timeout=30,
|
||||
)
|
||||
upload.raise_for_status()
|
||||
file_id = upload.json()["id"]
|
||||
|
||||
download = requests.get(
|
||||
f"{base}/api/v2/files/{file_id}",
|
||||
headers=headers,
|
||||
timeout=30,
|
||||
)
|
||||
download.raise_for_status()
|
||||
|
||||
out_path = Path("downloaded_file.txt")
|
||||
out_path.write_bytes(download.content)
|
||||
print(json.dumps({"saved_bytes": len(download.content), "file_id": str(file_id), "path": str(out_path)}))
|
||||
@ -0,0 +1,30 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from urllib.parse import quote
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
fixtures = Path(__file__).resolve().parents[2] / "fixtures"
|
||||
upload_path = Path(os.environ.get("SAMPLE_UPLOAD_FILE", str(fixtures / "sample-upload.txt")))
|
||||
|
||||
headers = {"accept": "application/json", "x-api-key": api_key}
|
||||
|
||||
upload = requests.post(
|
||||
f"{base}/api/v2/files",
|
||||
headers=headers,
|
||||
files={"file": (upload_path.name, upload_path.read_bytes(), "text/plain")},
|
||||
timeout=30,
|
||||
)
|
||||
upload.raise_for_status()
|
||||
file_id = upload.json()["id"]
|
||||
|
||||
new_name = os.environ.get("RENAMED_FILE_BASENAME", "renamed-sample-upload")
|
||||
url = f"{base}/api/v2/files/{file_id}?name={quote(new_name)}"
|
||||
|
||||
response = requests.put(url, headers=headers, timeout=30)
|
||||
response.raise_for_status()
|
||||
print(json.dumps(response.json()))
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/files/list/{os.getenv('FLOW_ID', '')}"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v2/files"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,24 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/run/{os.getenv('FLOW_ID', '')}"
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
payload = {
|
||||
"input_value": "what do you see?",
|
||||
"output_type": "chat",
|
||||
"input_type": "text",
|
||||
"tweaks": {
|
||||
"Read-File-1olS3": {"path": ["07e5b864-e367-4f52-b647-a48035ae7e5e/3a290013-fe1e-4d3d-a454-cacae81288f3.pdf"]}
|
||||
},
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, json=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,23 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v2/files"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
files = {
|
||||
"file": open(os.getenv("SAMPLE_UPLOAD_FILE", "docs/docs/API-Reference/fixtures/sample-upload.txt"), "rb"),
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, files=files)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
|
||||
for _f in files.values():
|
||||
if hasattr(_f, "close"):
|
||||
_f.close()
|
||||
@ -0,0 +1,23 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/files/upload/{os.getenv('FLOW_ID', '')}"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
files = {
|
||||
"file": open(os.getenv("SAMPLE_UPLOAD_FILE", "docs/docs/API-Reference/fixtures/sample-upload.txt"), "rb"),
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, files=files)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
|
||||
for _f in files.values():
|
||||
if hasattr(_f, "close"):
|
||||
_f.close()
|
||||
@ -0,0 +1,23 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v2/files"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
files = {
|
||||
"file": open(os.getenv("SAMPLE_UPLOAD_FILE", "docs/docs/API-Reference/fixtures/sample-upload.txt"), "rb"),
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, files=files)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
|
||||
for _f in files.values():
|
||||
if hasattr(_f, "close"):
|
||||
_f.close()
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/users/whoami"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,26 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
fixtures = Path(__file__).resolve().parents[2] / "fixtures"
|
||||
image_path = Path(os.environ.get("SAMPLE_IMAGE_FILE", str(fixtures / "sample-upload.png")))
|
||||
|
||||
headers = {"accept": "application/json", "x-api-key": api_key}
|
||||
|
||||
upload = requests.post(
|
||||
f"{base}/api/v1/files/upload/{flow_id}",
|
||||
headers=headers,
|
||||
files={"file": (image_path.name, image_path.read_bytes(), "image/png")},
|
||||
timeout=30,
|
||||
)
|
||||
upload.raise_for_status()
|
||||
|
||||
listed = requests.get(f"{base}/api/v1/files/list/{flow_id}", headers=headers, timeout=30)
|
||||
listed.raise_for_status()
|
||||
print(json.dumps({"upload": upload.json(), "list": listed.json()}))
|
||||
@ -0,0 +1,22 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/files/upload/{os.getenv('FLOW_ID', '')}"
|
||||
|
||||
headers = {
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
files = {
|
||||
"file": open(os.getenv("SAMPLE_IMAGE_FILE", "docs/docs/API-Reference/fixtures/sample-upload.png"), "rb"),
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, files=files)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
|
||||
for _f in files.values():
|
||||
if hasattr(_f, "close"):
|
||||
_f.close()
|
||||
@ -0,0 +1,24 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": api_key,
|
||||
"X-LANGFLOW-GLOBAL-VAR-USER_ID": "user123",
|
||||
"X-LANGFLOW-GLOBAL-VAR-ENVIRONMENT": "production",
|
||||
}
|
||||
|
||||
payload = {
|
||||
"input_value": "Tell me about something interesting!",
|
||||
"input_type": "chat",
|
||||
"output_type": "chat",
|
||||
}
|
||||
|
||||
response = requests.post(f"{base}/api/v1/run/{flow_id}", headers=headers, json=payload, timeout=60)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
@ -0,0 +1,30 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"accept": "application/json",
|
||||
"x-api-key": api_key,
|
||||
}
|
||||
|
||||
payload = {
|
||||
"input_value": "Tell me a story",
|
||||
"input_type": "chat",
|
||||
"output_type": "chat",
|
||||
"output_component": "chat_output",
|
||||
"session_id": "chat-123",
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
f"{base}/api/v1/run/{flow_id}?stream=false",
|
||||
headers=headers,
|
||||
json=payload,
|
||||
timeout=60,
|
||||
)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
@ -0,0 +1,26 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
url = f"{base}/api/v1/run/{flow_id}"
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": api_key,
|
||||
}
|
||||
|
||||
payload = {
|
||||
"input_value": "Tell me about something interesting!",
|
||||
"session_id": "chat-123",
|
||||
"input_type": "chat",
|
||||
"output_type": "chat",
|
||||
"output_component": "",
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=payload, timeout=60)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
@ -0,0 +1,18 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_SERVER_URL', '')}/api/v1/run/{os.getenv('FLOW_ID', '')}?stream=true"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
payload = {"message": "Tell me something interesting!", "session_id": "chat-123"}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, json=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,23 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": api_key,
|
||||
}
|
||||
|
||||
payload = {"data": "example-data"}
|
||||
|
||||
response = requests.post(
|
||||
f"{base}/api/v1/webhook/{flow_id}",
|
||||
headers=headers,
|
||||
json=payload,
|
||||
timeout=60,
|
||||
)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
@ -0,0 +1,30 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/flows/"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
payload = {
|
||||
"name": "string2",
|
||||
"description": "string",
|
||||
"icon": "string",
|
||||
"icon_bg_color": "#FF0000",
|
||||
"gradient": "string",
|
||||
"data": {},
|
||||
"is_component": False,
|
||||
"updated_at": "2024-12-30T15:48:01.519Z",
|
||||
"webhook": False,
|
||||
"endpoint_name": "string",
|
||||
"tags": ["string"],
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, json=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,28 @@
|
||||
import os
|
||||
import uuid
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
folder_id = (os.environ.get("PROJECT_ID") or os.environ.get("FOLDER_ID") or "").strip()
|
||||
|
||||
headers = {"accept": "application/json", "Content-Type": "application/json", "x-api-key": api_key}
|
||||
|
||||
|
||||
def _flow_doc(suffix: str) -> dict:
|
||||
doc = {
|
||||
"name": f"batch-flow-{uuid.uuid4().hex[:8]}",
|
||||
"description": f"Docs batch example {suffix}",
|
||||
"data": {"nodes": [], "edges": []},
|
||||
}
|
||||
if folder_id:
|
||||
doc["folder_id"] = folder_id
|
||||
return doc
|
||||
|
||||
|
||||
payload = {"flows": [_flow_doc("A"), _flow_doc("B")]}
|
||||
|
||||
response = requests.post(f"{base}/api/v1/flows/batch/", headers=headers, json=payload, timeout=30)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
@ -0,0 +1,25 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
headers = {"accept": "application/json", "Content-Type": "application/json", "x-api-key": api_key}
|
||||
|
||||
create = requests.post(
|
||||
f"{base}/api/v1/flows/",
|
||||
headers=headers,
|
||||
json={
|
||||
"name": "docs-example-delete-me",
|
||||
"description": "Temporary flow for delete-flow example",
|
||||
"data": {"nodes": [], "edges": []},
|
||||
},
|
||||
timeout=30,
|
||||
)
|
||||
create.raise_for_status()
|
||||
flow_id = create.json()["id"]
|
||||
|
||||
delete = requests.delete(f"{base}/api/v1/flows/{flow_id}", headers=headers, timeout=30)
|
||||
delete.raise_for_status()
|
||||
print(delete.text)
|
||||
@ -0,0 +1,40 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
folder_id = os.environ.get("PROJECT_ID") or os.environ.get("FOLDER_ID", "")
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": api_key,
|
||||
}
|
||||
|
||||
# Export needs at least two flows to return a ZIP; a single id returns JSON.
|
||||
extra = requests.post(
|
||||
f"{base}/api/v1/flows/",
|
||||
headers=headers,
|
||||
json={
|
||||
"name": "docs-export-temp-flow",
|
||||
"description": "Temporary second flow for export example",
|
||||
"data": {"nodes": [], "edges": []},
|
||||
**({"folder_id": folder_id} if folder_id else {}),
|
||||
},
|
||||
timeout=30,
|
||||
)
|
||||
extra.raise_for_status()
|
||||
extra_id = extra.json()["id"]
|
||||
|
||||
payload = [flow_id, extra_id]
|
||||
|
||||
response = requests.post(f"{base}/api/v1/flows/download/", headers=headers, json=payload, timeout=60)
|
||||
response.raise_for_status()
|
||||
|
||||
with open("langflow-flows.zip", "wb") as f:
|
||||
f.write(response.content)
|
||||
print("Saved response to langflow-flows.zip")
|
||||
|
||||
requests.delete(f"{base}/api/v1/flows/{extra_id}", headers=headers, timeout=30)
|
||||
@ -0,0 +1,23 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/flows/upload/?folder_id={os.getenv('FOLDER_ID', '')}"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
files = {
|
||||
"file": open(os.getenv("FLOW_IMPORT_FILE", "docs/docs/API-Reference/fixtures/flow-import.json"), "rb"),
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, files=files)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
|
||||
for _f in files.values():
|
||||
if hasattr(_f, "close"):
|
||||
_f.close()
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/flows/{os.getenv('FLOW_ID', '')}"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/flows/?remove_example_flows=true&components_only=false&get_all=false&project_id={os.getenv('PROJECT_ID', '')}&header_flows=false&page=1&size=1"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/flows/?remove_example_flows=false&components_only=false&get_all=true&header_flows=false&page=1&size=50"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/flows/basic_examples/"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,20 @@
|
||||
import os
|
||||
import uuid
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
headers = {"accept": "application/json", "Content-Type": "application/json", "x-api-key": api_key}
|
||||
|
||||
payload = {
|
||||
"name": f"docs-example-updated-flow-{uuid.uuid4().hex[:8]}",
|
||||
"description": "Updated via API docs Python example",
|
||||
"locked": False,
|
||||
}
|
||||
|
||||
response = requests.patch(f"{base}/api/v1/flows/{flow_id}", headers=headers, json=payload, timeout=30)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/logs?lines_before=0&lines_after=0×tamp=0"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,27 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
# `/logs-stream` is an SSE endpoint. For doc example stability, only read a small
|
||||
# number of events, then close the connection.
|
||||
url = f"{base}/logs-stream"
|
||||
headers = {"accept": "text/event-stream", "x-api-key": api_key}
|
||||
|
||||
response = requests.get(url, headers=headers, stream=True, timeout=30)
|
||||
response.raise_for_status()
|
||||
|
||||
events_read = 0
|
||||
chunks: list[str] = []
|
||||
for line in response.iter_lines(decode_unicode=True):
|
||||
if line:
|
||||
chunks.append(line)
|
||||
events_read += 1
|
||||
if events_read >= 3:
|
||||
break
|
||||
|
||||
response.close()
|
||||
|
||||
print("\n".join(chunks))
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/monitor/messages/session/different_session_id_2"
|
||||
|
||||
headers = {
|
||||
"accept": "*/*",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("DELETE", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,29 @@
|
||||
import os
|
||||
from uuid import UUID
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
|
||||
headers = {"accept": "*/*", "Content-Type": "application/json", "x-api-key": api_key}
|
||||
|
||||
list_resp = requests.get(
|
||||
f"{base}/api/v1/monitor/messages",
|
||||
headers=headers,
|
||||
params={"flow_id": flow_id},
|
||||
timeout=30,
|
||||
)
|
||||
list_resp.raise_for_status()
|
||||
messages = list_resp.json()
|
||||
if not messages:
|
||||
print("No messages to delete.")
|
||||
raise SystemExit(0)
|
||||
|
||||
ids = [UUID(str(m["id"])) for m in messages[:2]]
|
||||
params = [("message_ids", str(i)) for i in ids]
|
||||
|
||||
response = requests.delete(f"{base}/api/v1/monitor/messages", headers=headers, params=params, timeout=30)
|
||||
response.raise_for_status()
|
||||
print(response.status_code)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/monitor/builds?flow_id={os.getenv('FLOW_ID', '')}"
|
||||
|
||||
headers = {
|
||||
"accept": "*/*",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("DELETE", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,16 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base_url = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "http://127.0.0.1:7860")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
|
||||
response = requests.get(
|
||||
f"{base_url}/api/v1/monitor/traces",
|
||||
params={"flow_id": flow_id, "page": 1, "size": 50},
|
||||
headers={"x-api-key": api_key, "accept": "application/json"},
|
||||
timeout=30,
|
||||
)
|
||||
response.raise_for_status()
|
||||
print(response.json())
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/monitor/messages?flow_id={os.getenv('FLOW_ID', '')}&session_id=01ce083d-748b-4b8d-97b6-33adbb6a528a&sender=Machine&sender_name=AI&order_by=timestamp"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/monitor/messages"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/monitor/transactions?flow_id={os.getenv('FLOW_ID', '')}&page=1&size=50"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/monitor/builds?flow_id={os.getenv('FLOW_ID', '')}"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,33 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
|
||||
headers = {"accept": "application/json", "Content-Type": "application/json", "x-api-key": api_key}
|
||||
|
||||
list_resp = requests.get(
|
||||
f"{base}/api/v1/monitor/messages",
|
||||
headers=headers,
|
||||
params={"flow_id": flow_id},
|
||||
timeout=30,
|
||||
)
|
||||
list_resp.raise_for_status()
|
||||
messages = list_resp.json()
|
||||
if not messages:
|
||||
print("No messages to update.")
|
||||
raise SystemExit(0)
|
||||
|
||||
message_id = messages[0]["id"]
|
||||
payload = {"text": "testing 1234"}
|
||||
|
||||
response = requests.put(
|
||||
f"{base}/api/v1/monitor/messages/{message_id}",
|
||||
headers=headers,
|
||||
json=payload,
|
||||
timeout=30,
|
||||
)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
@ -0,0 +1,33 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
|
||||
headers = {"accept": "application/json", "x-api-key": api_key}
|
||||
|
||||
list_resp = requests.get(
|
||||
f"{base}/api/v1/monitor/messages",
|
||||
headers=headers,
|
||||
params={"flow_id": flow_id},
|
||||
timeout=30,
|
||||
)
|
||||
list_resp.raise_for_status()
|
||||
messages = list_resp.json()
|
||||
if not messages:
|
||||
print("No messages; cannot migrate session id.")
|
||||
raise SystemExit(0)
|
||||
|
||||
old_session_id = messages[0]["session_id"]
|
||||
new_session_id = f"{old_session_id}-migrated"
|
||||
|
||||
response = requests.patch(
|
||||
f"{base}/api/v1/monitor/messages/session/{old_session_id}",
|
||||
headers=headers,
|
||||
params={"new_session_id": new_session_id},
|
||||
timeout=30,
|
||||
)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
@ -0,0 +1,27 @@
|
||||
import os
|
||||
|
||||
from openai import OpenAI
|
||||
|
||||
base = (os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")).rstrip("/")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
|
||||
client = OpenAI(
|
||||
base_url=f"{base}/api/v1/",
|
||||
default_headers={"x-api-key": api_key},
|
||||
api_key="dummy-api-key", # Required by OpenAI SDK but not used by Langflow
|
||||
)
|
||||
|
||||
try:
|
||||
response = client.responses.create(
|
||||
model=flow_id,
|
||||
input="There is an event that happens on the second wednesday of every month. What are the event dates in 2026?",
|
||||
)
|
||||
except Exception as exc:
|
||||
# Empty bootstrap flows return an error body; use a flow with ChatInput + ChatOutput in the UI.
|
||||
print(exc)
|
||||
else:
|
||||
try:
|
||||
print(response.output_text)
|
||||
except Exception:
|
||||
print(response)
|
||||
@ -0,0 +1,29 @@
|
||||
# Continuation requests use the same endpoint; add `previous_response_id` from a prior
|
||||
# response's `id` field. The bootstrap flow is empty; use a Playground flow with ChatInput +
|
||||
# ChatOutput for a full run. Same first message as continue-conversations-with-response-and-session-ids.py.
|
||||
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
url = f"{base}/api/v1/responses"
|
||||
|
||||
headers = {
|
||||
"x-api-key": api_key,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
payload = {
|
||||
"model": flow_id,
|
||||
"input": "Hello, my name is Alice",
|
||||
"stream": False,
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=payload, timeout=120)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,28 @@
|
||||
# Same pattern as continue-conversations-with-response-and-session-ids-2.py; you can pass
|
||||
# `previous_response_id` from the prior turn (or a session id your app stores).
|
||||
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
url = f"{base}/api/v1/responses"
|
||||
|
||||
headers = {
|
||||
"x-api-key": api_key,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
payload = {
|
||||
"model": flow_id,
|
||||
"input": "Hello, my name is Alice",
|
||||
"stream": False,
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=payload, timeout=120)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,25 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
url = f"{base}/api/v1/responses"
|
||||
|
||||
headers = {
|
||||
"x-api-key": api_key,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
payload = {
|
||||
"model": flow_id,
|
||||
"input": "Hello, my name is Alice",
|
||||
"stream": False,
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=payload, timeout=120)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,17 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_SERVER_URL', '')}/api/v1/responses"
|
||||
|
||||
headers = {
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
payload = {"model": "$YOUR_FLOW_ID", "input": "Hello, how are you?", "stream": False}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, json=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,17 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_SERVER_URL', '')}/api/v1/responses"
|
||||
|
||||
headers = {
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
payload = {"model": "$FLOW_ID", "input": "Tell me a story about a robot", "stream": True}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, json=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,20 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_SERVER_URL', '')}/api/v1/responses"
|
||||
|
||||
headers = {
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
"Content-Type": "application/json",
|
||||
"X-LANGFLOW-GLOBAL-VAR-OPENAI_API_KEY": "sk-...",
|
||||
"X-LANGFLOW-GLOBAL-VAR-USER_ID": "user123",
|
||||
"X-LANGFLOW-GLOBAL-VAR-ENVIRONMENT": "production",
|
||||
}
|
||||
|
||||
payload = {"model": "your-flow-id", "input": "Hello"}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, json=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,26 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
url = f"{base}/api/v1/responses"
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": api_key,
|
||||
}
|
||||
|
||||
payload = {
|
||||
"model": flow_id,
|
||||
"input": "Calculate 23 * 15 and show me the result",
|
||||
"stream": False,
|
||||
"include": ["tool_call.results"],
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=payload, timeout=120)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,17 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_SERVER_URL', '')}/api/v1/responses"
|
||||
|
||||
headers = {
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
payload = {"model": "FLOW_ID", "input": "Explain quantum computing in simple terms", "stream": False}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, json=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,23 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/projects/"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
payload = {
|
||||
"name": "new_project_name",
|
||||
"description": "string",
|
||||
"components_list": ["3fa85f64-5717-4562-b3fc-2c963f66afa6"],
|
||||
"flows_list": ["3fa85f64-5717-4562-b3fc-2c963f66afa6"],
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, json=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,17 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/projects/"
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
payload = {"name": "new_project_name", "description": "string", "components_list": [], "flows_list": []}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, json=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,26 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
headers = {"accept": "*/*", "Content-Type": "application/json", "x-api-key": api_key}
|
||||
|
||||
create = requests.post(
|
||||
f"{base}/api/v1/projects/",
|
||||
headers=headers,
|
||||
json={
|
||||
"name": "docs-example-delete-me",
|
||||
"description": "Temporary project",
|
||||
"components_list": [],
|
||||
"flows_list": [],
|
||||
},
|
||||
timeout=30,
|
||||
)
|
||||
create.raise_for_status()
|
||||
project_id = create.json()["id"]
|
||||
|
||||
delete = requests.delete(f"{base}/api/v1/projects/{project_id}", headers=headers, timeout=30)
|
||||
delete.raise_for_status()
|
||||
print(delete.text)
|
||||
@ -0,0 +1,17 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/projects/download/{os.getenv('PROJECT_ID', '')}"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
with open("langflow-project.zip", "wb") as f:
|
||||
f.write(response.content)
|
||||
print("Saved response to langflow-project.zip")
|
||||
@ -0,0 +1,19 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
fixtures = Path(__file__).resolve().parents[2] / "fixtures"
|
||||
default_json = fixtures / "project-import.json"
|
||||
import_path = Path(os.environ.get("PROJECT_IMPORT_JSON", str(default_json)))
|
||||
|
||||
headers = {"accept": "application/json", "x-api-key": api_key}
|
||||
|
||||
files = {"file": (import_path.name, import_path.read_bytes(), "application/json")}
|
||||
response = requests.post(f"{base}/api/v1/projects/upload/", headers=headers, files=files, timeout=60)
|
||||
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/projects/{os.getenv('PROJECT_ID', '')}"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/projects/"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,19 @@
|
||||
import os
|
||||
import uuid
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
project_id = os.environ.get("PROJECT_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
headers = {"accept": "application/json", "Content-Type": "application/json", "x-api-key": api_key}
|
||||
|
||||
payload = {
|
||||
"name": f"docs-example-renamed-project-{uuid.uuid4().hex[:8]}",
|
||||
"description": "Updated via API docs Python example",
|
||||
}
|
||||
|
||||
response = requests.patch(f"{base}/api/v1/projects/{project_id}", headers=headers, json=payload, timeout=30)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
@ -0,0 +1,24 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
url = f"{base}/api/v1/run/{flow_id}?stream=false"
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": api_key,
|
||||
}
|
||||
|
||||
payload = {
|
||||
"input_value": "hello world!",
|
||||
"output_type": "chat",
|
||||
"input_type": "chat",
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=payload, timeout=60)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_SERVER_URL', '')}/api/v1/all"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_SERVER_URL', '')}/api/v1/config"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,14 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_SERVER_URL', '')}/api/v1/version"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,14 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_SERVER_URL', '')}/health_check"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,18 @@
|
||||
import os
|
||||
import uuid
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
headers = {"Content-Type": "application/json", "x-api-key": api_key}
|
||||
|
||||
payload = {
|
||||
"username": f"docsuser_{uuid.uuid4().hex[:12]}",
|
||||
"password": "securepassword123",
|
||||
}
|
||||
|
||||
response = requests.post(f"{base}/api/v1/users/", headers=headers, json=payload, timeout=30)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
@ -0,0 +1,22 @@
|
||||
import os
|
||||
import uuid
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
headers = {"accept": "application/json", "Content-Type": "application/json", "x-api-key": api_key}
|
||||
|
||||
create = requests.post(
|
||||
f"{base}/api/v1/users/",
|
||||
headers=headers,
|
||||
json={"username": f"docsdel_{uuid.uuid4().hex[:12]}", "password": "securepassword123"},
|
||||
timeout=30,
|
||||
)
|
||||
create.raise_for_status()
|
||||
user_id = create.json()["id"]
|
||||
|
||||
delete = requests.delete(f"{base}/api/v1/users/{user_id}", headers=headers, timeout=30)
|
||||
delete.raise_for_status()
|
||||
print(delete.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/users/whoami"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
url = f"{os.getenv('LANGFLOW_URL', '')}/api/v1/users/?skip=0&limit=10"
|
||||
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}",
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
print(response.text)
|
||||
@ -0,0 +1,24 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
headers = {"Content-Type": "application/json", "x-api-key": api_key}
|
||||
|
||||
who = requests.get(f"{base}/api/v1/users/whoami", headers=headers, timeout=30)
|
||||
who.raise_for_status()
|
||||
user_id = who.json()["id"]
|
||||
|
||||
# Must differ from the current password (default superuser is often langflow/langflow).
|
||||
payload = {"password": "DocsExampleResetPass2025!"}
|
||||
|
||||
response = requests.patch(
|
||||
f"{base}/api/v1/users/{user_id}/reset-password",
|
||||
headers=headers,
|
||||
json=payload,
|
||||
timeout=30,
|
||||
)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
@ -0,0 +1,18 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
headers = {"Content-Type": "application/json", "x-api-key": api_key}
|
||||
|
||||
who = requests.get(f"{base}/api/v1/users/whoami", headers=headers, timeout=30)
|
||||
who.raise_for_status()
|
||||
user_id = who.json()["id"]
|
||||
|
||||
payload = {"is_active": True}
|
||||
|
||||
response = requests.patch(f"{base}/api/v1/users/{user_id}", headers=headers, json=payload, timeout=30)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
@ -0,0 +1,226 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ROOT_DIR="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
|
||||
EXAMPLES_DIR="$SCRIPT_DIR"
|
||||
TEST_SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
|
||||
|
||||
MODE="syntax"
|
||||
|
||||
load_repo_env() {
|
||||
local env_file="$ROOT_DIR/.env"
|
||||
if [[ -f "$env_file" ]]; then
|
||||
set -a
|
||||
# shellcheck source=/dev/null
|
||||
source "$env_file"
|
||||
set +a
|
||||
fi
|
||||
}
|
||||
|
||||
print_help() {
|
||||
cat <<'EOF'
|
||||
Usage:
|
||||
test-python-examples.sh [--execute]
|
||||
|
||||
Modes:
|
||||
(default) Syntax check only (py_compile)
|
||||
--execute Execute examples after syntax checks
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--execute)
|
||||
MODE="execute"
|
||||
shift
|
||||
;;
|
||||
--help|-h)
|
||||
print_help
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown argument: $1"
|
||||
print_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
PY_FILES=()
|
||||
while IFS= read -r line; do
|
||||
if [[ "$(basename "$line")" == "$TEST_SCRIPT_NAME" ]]; then
|
||||
continue
|
||||
fi
|
||||
PY_FILES+=("$line")
|
||||
done < <(uv run python - "$EXAMPLES_DIR" <<'PY'
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
root = Path(sys.argv[1])
|
||||
for p in sorted(root.rglob("*.py")):
|
||||
print(p)
|
||||
PY
|
||||
)
|
||||
|
||||
if [[ ${#PY_FILES[@]} -eq 0 ]]; then
|
||||
echo "No .py examples found in $EXAMPLES_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PASS=0
|
||||
FAIL=0
|
||||
SKIP=0
|
||||
PY_TIMEOUT_SECONDS="${PY_TIMEOUT_SECONDS:-45}"
|
||||
|
||||
echo "Testing ${#PY_FILES[@]} Python examples in '$MODE' mode..."
|
||||
if [[ "$MODE" == "execute" ]]; then
|
||||
load_repo_env
|
||||
fi
|
||||
|
||||
has_placeholder_file_inputs() {
|
||||
uv run python - "$1" <<'PY'
|
||||
import sys
|
||||
text = open(sys.argv[1], encoding="utf-8").read()
|
||||
needles = ("FILE_NAME", "PATH/TO/FILE", "<file contents>")
|
||||
print("yes" if any(n in text for n in needles) else "no")
|
||||
PY
|
||||
}
|
||||
|
||||
has_missing_required_env() {
|
||||
uv run python - "$1" <<'PY'
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
text = open(sys.argv[1], encoding="utf-8").read()
|
||||
vars_to_check = ["FLOW_ID", "PROJECT_ID", "FOLDER_ID", "SESSION_ID", "JOB_ID", "USER_ID"]
|
||||
|
||||
for name in vars_to_check:
|
||||
getenv_pat = rf"os\.getenv\(\s*['\"]{name}['\"]"
|
||||
environ_pat = rf"os\.environ\.get\(\s*['\"]{name}['\"]"
|
||||
if (re.search(getenv_pat, text) or re.search(environ_pat, text)) and not os.getenv(name):
|
||||
print(name)
|
||||
raise SystemExit(0)
|
||||
|
||||
print("")
|
||||
PY
|
||||
}
|
||||
|
||||
print_failure_logs() {
|
||||
local out_file="$1"
|
||||
local err_file="$2"
|
||||
if [[ -s "$err_file" ]]; then
|
||||
echo " stderr (last 12 lines):"
|
||||
uv run python - "$err_file" <<'PY'
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
lines = Path(sys.argv[1]).read_text(encoding="utf-8", errors="replace").splitlines()
|
||||
for line in lines[-12:]:
|
||||
print(line)
|
||||
PY
|
||||
fi
|
||||
if [[ -s "$out_file" ]]; then
|
||||
echo " stdout (last 12 lines):"
|
||||
uv run python - "$out_file" <<'PY'
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
lines = Path(sys.argv[1]).read_text(encoding="utf-8", errors="replace").splitlines()
|
||||
for line in lines[-12:]:
|
||||
print(line)
|
||||
PY
|
||||
fi
|
||||
}
|
||||
|
||||
for file in "${PY_FILES[@]}"; do
|
||||
rel="${file#"$ROOT_DIR"/}"
|
||||
|
||||
if ! uv run python -m py_compile "$file"; then
|
||||
echo "FAIL $rel (py_compile)"
|
||||
((FAIL+=1))
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ "$MODE" == "execute" ]]; then
|
||||
# api-openai-responses/* call Langflow's HTTP API (e.g. /api/v1/responses) with x-api-key;
|
||||
# they do not require OPENAI_API_KEY in the environment (same as the JS examples).
|
||||
|
||||
# Streaming / long-running examples: skip in local harness (hang, flaky, or need extra setup).
|
||||
case "$(basename "$file")" in
|
||||
build-flow-and-stream-events-2.py|build-flow-and-stream-events-3.py|stream-llm-token-responses.py|example-streaming-request.py|stream-logs.py)
|
||||
echo "SKIP $rel (streaming/long-running; not run in local harness)"
|
||||
((SKIP+=1))
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "$(basename "$file")" == "retrieve-logs-with-optional-parameters.py" ]]; then
|
||||
echo "SKIP $rel (/logs endpoint not implemented in local server)"
|
||||
((SKIP+=1))
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ "$(basename "$file")" == "reset-password.py" ]]; then
|
||||
echo "SKIP $rel (reset-password may return 500 in local SQLite runs; run manually if needed)"
|
||||
((SKIP+=1))
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ -z "${LANGFLOW_API_KEY:-}" || ( -z "${LANGFLOW_URL:-}" && -z "${LANGFLOW_SERVER_URL:-}" ) ]]; then
|
||||
echo "SKIP $rel (set LANGFLOW_API_KEY and LANGFLOW_URL or LANGFLOW_SERVER_URL to execute)"
|
||||
((SKIP+=1))
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ "$(has_placeholder_file_inputs "$file")" == "yes" ]]; then
|
||||
echo "SKIP $rel (placeholder file input values)"
|
||||
((SKIP+=1))
|
||||
continue
|
||||
fi
|
||||
|
||||
missing_env="$(has_missing_required_env "$file")"
|
||||
if [[ -n "$missing_env" ]]; then
|
||||
echo "SKIP $rel (missing required env: $missing_env)"
|
||||
((SKIP+=1))
|
||||
continue
|
||||
fi
|
||||
|
||||
if ! uv run python - "$file" "$PY_TIMEOUT_SECONDS" >/tmp/langflow-python-example.out 2>/tmp/langflow-python-example.err <<'PY'
|
||||
import runpy
|
||||
import signal
|
||||
import sys
|
||||
|
||||
script_path = sys.argv[1]
|
||||
timeout_seconds = int(sys.argv[2])
|
||||
|
||||
def _handle_timeout(_signum, _frame):
|
||||
raise TimeoutError(f"execution timed out after {timeout_seconds}s")
|
||||
|
||||
signal.signal(signal.SIGALRM, _handle_timeout)
|
||||
signal.alarm(timeout_seconds)
|
||||
try:
|
||||
runpy.run_path(script_path, run_name="__main__")
|
||||
finally:
|
||||
signal.alarm(0)
|
||||
PY
|
||||
then
|
||||
echo "FAIL $rel (execution)"
|
||||
print_failure_logs "/tmp/langflow-python-example.out" "/tmp/langflow-python-example.err"
|
||||
((FAIL+=1))
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "PASS $rel"
|
||||
((PASS+=1))
|
||||
done
|
||||
|
||||
echo
|
||||
echo "Summary: PASS=$PASS FAIL=$FAIL SKIP=$SKIP TOTAL=${#PY_FILES[@]}"
|
||||
|
||||
if [[ $FAIL -gt 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
@ -0,0 +1,20 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
headers = {"Content-Type": "application/json", "x-api-key": api_key}
|
||||
|
||||
payload = {
|
||||
"flow_id": flow_id,
|
||||
"background": True,
|
||||
"stream": False,
|
||||
"inputs": {},
|
||||
}
|
||||
|
||||
response = requests.post(f"{base}/api/v2/workflows", headers=headers, json=payload, timeout=60)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
@ -0,0 +1,26 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
headers = {"Content-Type": "application/json", "x-api-key": api_key}
|
||||
|
||||
start = requests.post(
|
||||
f"{base}/api/v2/workflows",
|
||||
headers=headers,
|
||||
json={"flow_id": flow_id, "background": True, "stream": False, "inputs": {}},
|
||||
timeout=60,
|
||||
)
|
||||
start.raise_for_status()
|
||||
job_id = start.json()["job_id"]
|
||||
|
||||
stop = requests.post(
|
||||
f"{base}/api/v2/workflows/stop",
|
||||
headers=headers,
|
||||
json={"job_id": job_id},
|
||||
timeout=60,
|
||||
)
|
||||
print(stop.status_code, stop.text)
|
||||
@ -0,0 +1,18 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
headers = {"Content-Type": "application/json", "x-api-key": api_key}
|
||||
|
||||
start = requests.post(
|
||||
f"{base}/api/v2/workflows",
|
||||
headers=headers,
|
||||
json={"flow_id": flow_id, "background": True, "stream": False, "inputs": {}},
|
||||
timeout=60,
|
||||
)
|
||||
start.raise_for_status()
|
||||
print(start.text)
|
||||
@ -0,0 +1,24 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")
|
||||
flow_id = os.environ.get("FLOW_ID", "")
|
||||
api_key = os.environ.get("LANGFLOW_API_KEY", "")
|
||||
|
||||
headers = {"Content-Type": "application/json", "x-api-key": api_key}
|
||||
|
||||
payload = {
|
||||
"flow_id": flow_id,
|
||||
"background": False,
|
||||
"stream": False,
|
||||
"inputs": {},
|
||||
"globals": {
|
||||
"FILENAME": "relatório—final.pdf",
|
||||
"OWNER_NAME": "José",
|
||||
},
|
||||
}
|
||||
|
||||
response = requests.post(f"{base}/api/v2/workflows", headers=headers, json=payload, timeout=120)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
Reference in New Issue
Block a user