add workflow 客户信息补全【156,dev
This commit is contained in:
parent
3409e5a537
commit
333041ab1b
|
|
@ -34,31 +34,41 @@ class APIClient:
|
|||
Returns:
|
||||
API响应数据
|
||||
"""
|
||||
payload = json.dumps({
|
||||
payload = {
|
||||
"inputs": inputs,
|
||||
"response_mode": "blocking",
|
||||
"user": "admin"
|
||||
})
|
||||
logger.info(f"调用API,payload: {payload}")
|
||||
}
|
||||
logger.info(f"调用API,payload: {json.dumps(payload, ensure_ascii=False)}")
|
||||
|
||||
try:
|
||||
logger.info("调用带inputs参数的API")
|
||||
response = requests.post(
|
||||
self.api_url,
|
||||
headers=self.headers,
|
||||
data=payload,
|
||||
timeout=2400
|
||||
json=payload, # Using json parameter instead of data to let requests handle serialization
|
||||
timeout=300 # Reduced timeout to more reasonable value
|
||||
)
|
||||
|
||||
logger.info(f"API调用完成,状态码: {response.status_code}")
|
||||
logger.info(f"Response content: {response.text[:500]}") # Log first 500 chars of response
|
||||
|
||||
response.raise_for_status()
|
||||
logger.info(f"API调用成功,状态码: {response.status_code}")
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"status_code": response.status_code,
|
||||
"data": response.json()
|
||||
"data": response.json() if response.content else {}
|
||||
}
|
||||
|
||||
except requests.exceptions.HTTPError as e:
|
||||
logger.error(f"HTTP错误: {e.response.status_code} - {e.response.text}")
|
||||
return {
|
||||
"success": False,
|
||||
"error": f"HTTP {e.response.status_code}: {e.response.text}",
|
||||
"status_code": e.response.status_code
|
||||
}
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.error(f"API调用失败: {e}")
|
||||
return {
|
||||
|
|
@ -87,23 +97,33 @@ class APIClient:
|
|||
payload.update(other_params)
|
||||
|
||||
try:
|
||||
logger.info("调用不带inputs参数的API")
|
||||
logger.info(f"调用不带inputs参数的API,payload: {json.dumps(payload, ensure_ascii=False)}")
|
||||
response = requests.post(
|
||||
self.api_url,
|
||||
headers=self.headers,
|
||||
data=json.dumps(payload),
|
||||
timeout=1200
|
||||
json=payload, # Using json parameter instead of data
|
||||
timeout=300 # Reduced timeout to more reasonable value
|
||||
)
|
||||
|
||||
logger.info(f"API调用完成,状态码: {response.status_code}")
|
||||
logger.info(f"Response content: {response.text[:500]}") # Log first 500 chars of response
|
||||
|
||||
response.raise_for_status()
|
||||
logger.info(f"API调用成功,状态码: {response.status_code}")
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"status_code": response.status_code,
|
||||
"data": response.json()
|
||||
"data": response.json() if response.content else {}
|
||||
}
|
||||
|
||||
except requests.exceptions.HTTPError as e:
|
||||
logger.error(f"HTTP错误: {e.response.status_code} - {e.response.text}")
|
||||
return {
|
||||
"success": False,
|
||||
"error": f"HTTP {e.response.status_code}: {e.response.text}",
|
||||
"status_code": e.response.status_code
|
||||
}
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.error(f"API调用失败: {e}")
|
||||
return {
|
||||
|
|
@ -121,31 +141,41 @@ class APIClient:
|
|||
Returns:
|
||||
API响应数据
|
||||
"""
|
||||
payload = json.dumps({
|
||||
payload = {
|
||||
"inputs": {},
|
||||
"query" : query,
|
||||
"response_mode": "streaming",
|
||||
"response_mode": "blocking", # Changed from streaming to blocking for consistency
|
||||
"user": "admin"
|
||||
})
|
||||
}
|
||||
|
||||
try:
|
||||
logger.info("调用带inputs参数的API")
|
||||
logger.info(f"调用带query参数的API,payload: {json.dumps(payload, ensure_ascii=False)}")
|
||||
response = requests.post(
|
||||
self.api_url,
|
||||
headers=self.headers,
|
||||
data=payload,
|
||||
timeout=2400
|
||||
json=payload, # Using json parameter instead of data
|
||||
timeout=300 # Reduced timeout to more reasonable value
|
||||
)
|
||||
|
||||
logger.info(f"API调用完成,状态码: {response.status_code}")
|
||||
logger.info(f"Response content: {response.text[:500]}") # Log first 500 chars of response
|
||||
|
||||
response.raise_for_status()
|
||||
logger.info(f"API调用成功,状态码: {response.status_code}")
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"status_code": response.status_code,
|
||||
"data": response.json()
|
||||
"data": response.json() if response.content else {}
|
||||
}
|
||||
|
||||
except requests.exceptions.HTTPError as e:
|
||||
logger.error(f"HTTP错误: {e.response.status_code} - {e.response.text}")
|
||||
return {
|
||||
"success": False,
|
||||
"error": f"HTTP {e.response.status_code}: {e.response.text}",
|
||||
"status_code": e.response.status_code
|
||||
}
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.error(f"API调用失败: {e}")
|
||||
return {
|
||||
|
|
@ -165,7 +195,7 @@ class APIClient:
|
|||
payload = {
|
||||
"inputs": {},
|
||||
"query":"",
|
||||
"response_mode": "streaming",
|
||||
"response_mode": "blocking", # Changed from streaming to blocking for consistency
|
||||
"user": "admin"
|
||||
}
|
||||
|
||||
|
|
@ -174,23 +204,33 @@ class APIClient:
|
|||
payload.update(other_params)
|
||||
|
||||
try:
|
||||
logger.info("调用不带inputs参数的API")
|
||||
logger.info(f"调用不带query参数的API,payload: {json.dumps(payload, ensure_ascii=False)}")
|
||||
response = requests.post(
|
||||
self.api_url,
|
||||
headers=self.headers,
|
||||
data=json.dumps(payload),
|
||||
timeout=2400
|
||||
json=payload, # Using json parameter instead of data
|
||||
timeout=300 # Reduced timeout to more reasonable value
|
||||
)
|
||||
|
||||
logger.info(f"API调用完成,状态码: {response.status_code}")
|
||||
logger.info(f"Response content: {response.text[:500]}") # Log first 500 chars of response
|
||||
|
||||
response.raise_for_status()
|
||||
logger.info(f"API调用成功,状态码: {response.status_code}")
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"status_code": response.status_code,
|
||||
"data": response.json()
|
||||
"data": response.json() if response.content else {}
|
||||
}
|
||||
|
||||
except requests.exceptions.HTTPError as e:
|
||||
logger.error(f"HTTP错误: {e.response.status_code} - {e.response.text}")
|
||||
return {
|
||||
"success": False,
|
||||
"error": f"HTTP {e.response.status_code}: {e.response.text}",
|
||||
"status_code": e.response.status_code
|
||||
}
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.error(f"API调用失败: {e}")
|
||||
return {
|
||||
|
|
@ -259,6 +299,7 @@ def process_single_item(api_client, item_text, type, item_index, total_count):
|
|||
inputs_data = {
|
||||
'companys': f"{item_text}"
|
||||
}
|
||||
print(inputs_data)
|
||||
|
||||
result = api_client.call_api_with_inputs(inputs_data)
|
||||
|
||||
|
|
@ -308,7 +349,6 @@ def main():
|
|||
|
||||
api_client = APIClient(api_config['url'], api_config['auth_token'])
|
||||
|
||||
type = 'agent'
|
||||
type = 'workflow'
|
||||
|
||||
try:
|
||||
|
|
|
|||
Loading…
Reference in New Issue