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