refactor langflow calls

This commit is contained in:
phact 2025-12-04 15:16:25 -05:00
parent 50d62c2cc0
commit d33cf7ecc8

View file

@ -568,25 +568,17 @@ class AppClients:
self, name: str, value: str, modify: bool = False
):
"""Create a global variable in Langflow via API"""
api_key = await get_langflow_api_key()
if not api_key:
logger.warning(
"Cannot create Langflow global variable: No API key", variable_name=name
)
return
url = f"{LANGFLOW_URL}/api/v1/variables/"
payload = {
"name": name,
"value": value,
"default_fields": [],
"type": "Credential",
}
headers = {"x-api-key": api_key, "Content-Type": "application/json"}
try:
async with httpx.AsyncClient() as client:
response = await client.post(url, headers=headers, json=payload)
response = await self.langflow_request(
"POST", "/api/v1/variables/", json=payload
)
if response.status_code in [200, 201]:
logger.info(
@ -620,21 +612,9 @@ class AppClients:
async def _update_langflow_global_variable(self, name: str, value: str):
"""Update an existing global variable in Langflow via API"""
api_key = await get_langflow_api_key()
if not api_key:
logger.warning(
"Cannot update Langflow global variable: No API key", variable_name=name
)
return
headers = {"x-api-key": api_key, "Content-Type": "application/json"}
try:
async with httpx.AsyncClient() as client:
# First, get all variables to find the one with the matching name
get_response = await client.get(
f"{LANGFLOW_URL}/api/v1/variables/", headers=headers
)
get_response = await self.langflow_request("GET", "/api/v1/variables/")
if get_response.status_code != 200:
logger.error(
@ -670,10 +650,8 @@ class AppClients:
"default_fields": target_variable.get("default_fields", []),
}
patch_response = await client.patch(
f"{LANGFLOW_URL}/api/v1/variables/{variable_id}",
headers=headers,
json=update_payload,
patch_response = await self.langflow_request(
"PATCH", f"/api/v1/variables/{variable_id}", json=update_payload
)
if patch_response.status_code == 200: