Merge pull request #117 from xpack-ai/feature/1.3-liujian

Bug fixes and prompt optimizations.
This commit is contained in:
Dot.L authored and GitHub committed 2026-01-16 17:12:45 +08:00
commit 875a7bf906
4 files changed
+45 -34

No files matched your search

+2 -2
View File
@@ -78,7 +78,7 @@ def account_login(body: dict = Body(...), auth_service: AuthService = Depends(ge
if token:
return ResponseUtils.success({"user_token": token})
else:
return ResponseUtils.error(message="login failed", code=401)
return ResponseUtils.error(message="login failed, please enter the correct account or password", code=401)
@router.post("/google/sign", response_model=dict)
@@ -95,7 +95,7 @@ def google_login(request: Request, body: dict = Body(...), auth_service: AuthSer
if token:
return ResponseUtils.success({"user_token": token})
else:
return ResponseUtils.error(message=f"login failed: {redirect_uri}", code=401)
return ResponseUtils.error(message=f"login failed, please check the redirect_uri: {redirect_uri}", code=401)
@router.delete("/logout", response_model=dict)
@@ -244,5 +244,5 @@ class AuthService:
return token
except Exception as e:
logger.error(f"Google login failed: {e}")
logger.error(f"Google login failed, error: {e}")
return None
+28 -26
View File
@@ -293,40 +293,42 @@ class HttpRequestBuilder:
"""
if not hasattr(tool_config, 'request_body_schema') or not tool_config.request_body_schema or tool_config.method.value not in ["POST", "PUT", "PATCH"]:
return None
try:
# First try to parse as parameters list (similar to query/path parameters)
request_body = {}
body_params = self._safe_parse_params(tool_config.request_body_schema, 'body')
if body_params:
# If it's a list of parameters, process them like query parameters
request_body = {}
for param in body_params:
if isinstance(param, dict) and "name" in param:
param_name = param["name"]
if param_name in arguments:
request_body[param_name] = arguments[param_name]
if isinstance(param, dict):
name = param.get("name")
if name and name in arguments:
request_body[name] = arguments[name]
else:
t = param.get("type")
if t == "object":
props = param.get("properties")
if isinstance(props, dict):
for prop_name in props.keys():
if prop_name in arguments:
request_body[prop_name] = arguments[prop_name]
if request_body:
# logger.debug(f"Built request body from parameters: {request_body}")
return request_body
else:
# If not a parameters list, try to parse as JSON schema object
try:
body_schema = json.loads(tool_config.request_body_schema)
logger.debug(f"Request body schema: {body_schema}")
if isinstance(body_schema, dict) and "properties" in body_schema:
request_body = {}
for prop_name in body_schema["properties"]:
try:
body_schema = json.loads(tool_config.request_body_schema)
if isinstance(body_schema, dict):
props = body_schema.get("properties")
if isinstance(props, dict):
for prop_name in props.keys():
if prop_name in arguments:
request_body[prop_name] = arguments[prop_name]
if request_body:
# logger.debug(f"Built request body from schema: {request_body}")
return request_body
except json.JSONDecodeError:
logger.warning(f"Failed to parse request body schema as JSON")
else:
for key in body_schema.keys():
if key in arguments:
request_body[key] = arguments[key]
if request_body:
return request_body
except json.JSONDecodeError:
logger.warning(f"Failed to parse request body schema as JSON")
except Exception as e:
logger.warning(f"Request body schema parsing failed: {e}")
+14 -5
View File
@@ -125,6 +125,8 @@ class CacheUtils:
else:
logger.warning(f"Unexpected cache value type for key {cache_key}: {type(cache_value)}")
return None
if isinstance(model_data,list):
return model_data
return SqlalchemyUtils.dict_to_model(model_class, model_data)
return None
except Exception as e:
@@ -145,7 +147,10 @@ class CacheUtils:
bool: True if successful, False otherwise
"""
try:
model_dict = SqlalchemyUtils.model_to_dict(model)
if isinstance(model, list):
return CacheUtils.set_sqlalchemy_list_cache(cache_key, model, expire_time)
else:
model_dict = SqlalchemyUtils.model_to_dict(model)
serialized_data = json.dumps(model_dict, ensure_ascii=False)
redis_client.set(cache_key, serialized_data, ex=expire_time)
return True
@@ -203,11 +208,15 @@ class CacheUtils:
if not isinstance(model_list, list):
logger.error(f"Expected list for cache key {cache_key}, got {type(model_list)}")
return False
model_dict_list = [SqlalchemyUtils.model_to_dict(model) for model in model_list]
serialized_data = json.dumps(model_dict_list, ensure_ascii=False)
data = []
for model in model_list:
if isinstance(model,dict):
data.append(SqlalchemyUtils.model_to_dict(model))
else:
data.append(model)
serialized_data = json.dumps(data, ensure_ascii=False)
redis_client.set(cache_key, serialized_data, ex=expire_time)
return True
except Exception as e:
logger.error(f"Failed to set SQLAlchemy list cache for key {cache_key}: {e}")
logger.error(f"Failed to set SQLAlchemy list cache for key aaa {cache_key}: {e}")
return False