Connection Error When Running Langflow with Docker via python api #3238
-
Hi,
And this is my function for running langflow:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
To resolve the connection error when calling the Langflow API from a Python script in a Docker Compose setup, ensure that your Docker Compose file is correctly configured to expose the necessary ports and that your Python script is targeting the correct host and port. Here is an example of how you can set up your version: '3.8'
services:
langflow:
image: langflowai/langflow:1.0-alpha
ports:
- "7860:7860"
command: ["uvicorn", "--host", "0.0.0.0", "--port", "7860", "--factory", "langflow.main:create_app"] In your Python script, you should then target import requests
BASE_API_URL = "http://localhost:7860"
def run_flow(message: str,
endpoint: str,
output_type: str = "chat",
input_type: str = "chat",
tweaks: Optional[dict] = None,
api_key: Optional[str] = None,
session_id: Optional[str] = None) -> dict:
api_url = f"{BASE_API_URL}/api/v1/run/{endpoint}"
payload = {
"input_value": message,
"output_type": output_type,
"input_type": input_type,
"session_id": session_id,
}
headers = None
if tweaks:
payload["tweaks"] = tweaks
if api_key:
headers = {"x-api-key": api_key}
response = requests.post(api_url, json=payload, headers=headers)
return response.json() Make sure to replace |
Beta Was this translation helpful? Give feedback.
-
Change your python api BASE_URL as below: |
Beta Was this translation helpful? Give feedback.
Change your python api BASE_URL as below:
BASE_API_URL = "http://host.docker.internal:7860"