chore: fix pre commit format and pipeline issue (#1144)

This commit is contained in:
Wendong-Fan 2026-02-04 00:06:29 +00:00 committed by GitHub
parent 2256497dff
commit 893f51fc82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
970 changed files with 11235 additions and 9533 deletions

View file

@ -12,20 +12,21 @@
# limitations under the License.
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
from fastapi import APIRouter, Depends, HTTPException
import logging
from typing import Any, cast
import requests
from exa_py import Exa
from fastapi import APIRouter, Depends, HTTPException
from app.component.auth import key_must
from app.component.environment import env_not_empty
from app.model.mcp.proxy import ExaSearch
from typing import Any, cast
import requests
import logging
logger = logging.getLogger("server_proxy_controller")
from app.model.user.key import Key
router = APIRouter(prefix="/proxy", tags=["Mcp Servers"])
@ -41,18 +42,26 @@ def exa_search(search: ExaSearch, key: Key = Depends(key_must)):
if search.include_text is not None and len(search.include_text) > 0:
if len(search.include_text) > 1:
logger.warning("Invalid exa search parameter", extra={"param": "include_text", "reason": "more than 1 string"})
logger.warning(
"Invalid exa search parameter", extra={"param": "include_text", "reason": "more than 1 string"}
)
raise ValueError("include_text can only contain 1 string")
if len(search.include_text[0].split()) > 5:
logger.warning("Invalid exa search parameter", extra={"param": "include_text", "reason": "exceeds 5 words"})
logger.warning(
"Invalid exa search parameter", extra={"param": "include_text", "reason": "exceeds 5 words"}
)
raise ValueError("include_text string cannot be longer than 5 words")
if search.exclude_text is not None and len(search.exclude_text) > 0:
if len(search.exclude_text) > 1:
logger.warning("Invalid exa search parameter", extra={"param": "exclude_text", "reason": "more than 1 string"})
logger.warning(
"Invalid exa search parameter", extra={"param": "exclude_text", "reason": "more than 1 string"}
)
raise ValueError("exclude_text can only contain 1 string")
if len(search.exclude_text[0].split()) > 5:
logger.warning("Invalid exa search parameter", extra={"param": "exclude_text", "reason": "exceeds 5 words"})
logger.warning(
"Invalid exa search parameter", extra={"param": "exclude_text", "reason": "exceeds 5 words"}
)
raise ValueError("exclude_text string cannot be longer than 5 words")
exa = Exa(EXA_API_KEY)
@ -87,7 +96,10 @@ def exa_search(search: ExaSearch, key: Key = Depends(key_must)):
)
result_count = len(results.get("results", [])) if "results" in results else 0
logger.info("Exa search completed", extra={"query": search.query, "search_type": search.search_type, "result_count": result_count})
logger.info(
"Exa search completed",
extra={"query": search.query, "search_type": search.search_type, "result_count": result_count},
)
return results
except ValueError as e:
@ -112,7 +124,7 @@ def google_search(query: str, search_type: str = "web", key: Key = Depends(key_m
search_language = "en"
# How many pages to return
num_result_pages = 10
# Constructing the URL
# Doc: https://developers.google.com/custom-search/v1/using_rest
base_url = (
@ -127,7 +139,7 @@ def google_search(query: str, search_type: str = "web", key: Key = Depends(key_m
url = base_url
responses = []
try:
# Make the GET request
result = requests.get(url)
@ -194,15 +206,20 @@ def google_search(query: str, search_type: str = "web", key: Key = Depends(key_m
"url": link,
}
responses.append(response)
logger.info("Google search completed", extra={"query": query, "search_type": search_type, "result_count": len(responses)})
logger.info(
"Google search completed",
extra={"query": query, "search_type": search_type, "result_count": len(responses)},
)
else:
error_info = data.get("error", {})
logger.error("Google search API error", extra={"query": query, "api_error": error_info})
raise HTTPException(status_code=500, detail="Internal server error")
except Exception as e:
logger.error("Google search failed", extra={"query": query, "search_type": search_type, "error": str(e)}, exc_info=True)
logger.error(
"Google search failed", extra={"query": query, "search_type": search_type, "error": str(e)}, exc_info=True
)
raise HTTPException(status_code=500, detail="Internal server error")
return responses
return responses