chore: polish code with little update (#182)

- Run Docker container as non-root user (appuser) to minimize security risks
- Add Docker HEALTHCHECK for better container orchestration
- Make CORS configurable via ALLOWED_ORIGINS env var with security warning
- Replace assertions with proper error handling (TypeError/ValueError)
- Add 30s timeout to HTTP requests to prevent hanging connections
- Disable auto-reload in production uvicorn settings
This commit is contained in:
Li Yi
2025-10-11 14:49:18 +08:00
committed by GitHub
parent 8177876e5e
commit 9cea7f9314
8 changed files with 46 additions and 21 deletions
+5 -3
View File
@@ -310,7 +310,8 @@ class BedrockModel(BaseChatModel):
if message.role != "system":
# ignore system messages here
continue
assert isinstance(message.content, str)
if not isinstance(message.content, str):
raise TypeError(f"System message content must be a string, got {type(message.content).__name__}")
system_prompts.append({"text": message.content})
return system_prompts
@@ -580,7 +581,8 @@ class BedrockModel(BaseChatModel):
tool_config["toolChoice"] = {"auto": {}}
else:
# Specific tool to use
assert "function" in chat_request.tool_choice
if "function" not in chat_request.tool_choice:
raise ValueError("tool_choice must contain 'function' key when specifying a specific tool")
tool_config["toolChoice"] = {"tool": {"name": chat_request.tool_choice["function"].get("name", "")}}
args["toolConfig"] = tool_config
# add Additional fields to enable extend thinking
@@ -784,7 +786,7 @@ class BedrockModel(BaseChatModel):
return base64.b64decode(image_data), content_type.group(1)
# Send a request to the image URL
response = requests.get(image_url)
response = requests.get(image_url, timeout=30)
# Check if the request was successful
if response.status_code == 200:
content_type = response.headers.get("Content-Type")