Skip to content
This repository was archived by the owner on Sep 20, 2025. It is now read-only.

Commit 062db2b

Browse files
committed
fix: trailing whitespace
1 parent 8adb70a commit 062db2b

File tree

5 files changed

+42
-42
lines changed

5 files changed

+42
-42
lines changed

src/emd/cfn/sagemaker_async/post_build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def post_build():
4141
use_spot = True
4242
else:
4343
use_spot = False
44-
44+
4545
deploy_ecs_cluster(args.region, vpc_id, subnets, use_spot)
4646

4747

src/emd/cfn/sagemaker_realtime/post_build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def post_build():
4141
use_spot = True
4242
else:
4343
use_spot = False
44-
44+
4545
deploy_ecs_cluster(args.region, vpc_id, subnets, use_spot)
4646

4747

src/emd/cfn/shared/ecs_cluster.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def run_command(cmd):
1313
try:
14-
result = subprocess.run(cmd, shell=True, check=True,
14+
result = subprocess.run(cmd, shell=True, check=True,
1515
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
1616
text=True)
1717
return result.stdout.strip()
@@ -23,15 +23,15 @@ def run_command(cmd):
2323
def build_router_image(region):
2424
repo_name = "emd-openai-api-router"
2525
image_tag = f"{repo_name}:latest"
26-
26+
2727
# Check if repo exists
2828
try:
2929
run_command(f"aws ecr describe-repositories --repository-names {repo_name} --region {region}")
3030
print(f"ECR repository {repo_name} already exists")
3131
except:
3232
print(f"Creating ECR repository: {repo_name}")
3333
run_command(f"aws ecr create-repository --repository-name {repo_name} --region {region}")
34-
34+
3535
# Get ECR login
3636
account_id = json.loads(run_command(f"aws sts get-caller-identity --region {region}"))['Account']
3737
domain = f"dkr.ecr.{region}.amazonaws.com.cn" if region.startswith("cn-") else f"dkr.ecr.{region}.amazonaws.com"
@@ -45,16 +45,16 @@ def build_router_image(region):
4545
f"-t {image_tag} ."
4646
)
4747
run_command(build_cmd)
48-
48+
4949
# Tag and push image
5050
full_image_tag = f"{registry}/{image_tag}"
51-
51+
5252
print(f"Tagging image as: {full_image_tag}")
5353
run_command(f"docker tag {image_tag} {full_image_tag}")
54-
54+
5555
print(f"Pushing image to ECR: {full_image_tag}")
5656
run_command(f"docker push {full_image_tag}")
57-
57+
5858
return full_image_tag
5959

6060
def wait_for_stack_completion(client, stack_name):
@@ -207,23 +207,23 @@ def deploy_ecs_cluster_template(region, vpc_id, subnets, api_router_uri, use_spo
207207

208208
def deploy_ecs_cluster(region, vpc_id=None, subnets=None, use_spot=False):
209209
"""Deploy ECS cluster with specified VPC and subnets.
210-
210+
211211
Args:
212212
region (str): AWS region to deploy to
213213
vpc_id (str, optional): VPC ID to use for deployment. If None, deploys new VPC.
214214
subnets (str, optional): Comma-separated list of subnet IDs. If None, deploys new VPC.
215215
"""
216-
216+
217217
# Deploy new VPC if no vpc_id/subnets provided
218218
if not vpc_id or not subnets:
219219
vpc_id, subnets = deploy_vpc_template(region)
220-
220+
221221
# Update parameters with networking info
222222
update_parameters_file("parameters.json", {"VPCID": vpc_id, "Subnets": subnets})
223-
223+
224224
# Build and push Fargate image to ECR as the OpenAI compatible API router
225225
api_router_uri = build_router_image(region)
226-
226+
227227
# Deploy the ECS cluster
228228
deploy_ecs_cluster_template(region, vpc_id, subnets, api_router_uri, use_spot)
229229

src/emd/cfn/shared/filter_parameters.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,73 +7,73 @@ def read_template_parameters(template_path):
77
"""Read CloudFormation template and extract parameter names"""
88
with open(template_path) as f:
99
content = f.read()
10-
10+
1111
# Find Parameters section (match until next section or end of file)
1212
params_section = re.search(
13-
r'^Parameters:\s*$(.*?)(?=^\w|\Z)',
14-
content,
13+
r'^Parameters:\s*$(.*?)(?=^\w|\Z)',
14+
content,
1515
re.MULTILINE | re.DOTALL
1616
)
1717
if not params_section:
1818
print(f"Warning: No Parameters section found in {template_path}")
1919
return set()
20-
20+
2121
# Extract parameter names (must be valid CloudFormation parameter names)
2222
param_names = re.findall(
2323
r'^\s+([A-Za-z0-9]+)\s*:', # Only allow alphanumeric parameter names
24-
params_section.group(1),
24+
params_section.group(1),
2525
re.MULTILINE
2626
)
27-
27+
2828
if not param_names:
2929
print(f"Warning: Parameters section empty in {template_path}")
30-
30+
3131
print(f"Found parameters in {template_path}: {', '.join(param_names)}")
3232
return set(param_names)
3333

3434
def filter_parameters_file(template_path, parameters_path):
3535
"""Filter parameters.json to only keep parameters defined in the template"""
3636
# Get allowed parameters from template
3737
allowed_params = read_template_parameters(template_path)
38-
38+
3939
# Read current parameters
4040
with open(parameters_path) as f:
4141
params_data = json.load(f)
42-
42+
4343
if 'Parameters' not in params_data:
4444
print(f"Error: {parameters_path} has no 'Parameters' object")
4545
return False
46-
46+
4747
# Filter parameters
4848
original_count = len(params_data['Parameters'])
4949
params_data['Parameters'] = {
50-
k: v for k, v in params_data['Parameters'].items()
50+
k: v for k, v in params_data['Parameters'].items()
5151
if k in allowed_params
5252
}
5353
removed_count = original_count - len(params_data['Parameters'])
54-
54+
5555
# Write cleaned parameters back
5656
with open(parameters_path, 'w') as f:
5757
json.dump(params_data, f, indent=4)
58-
58+
5959
print(f"Removed {removed_count} parameters not in template")
6060
return True
6161

6262
if __name__ == "__main__":
6363
if len(sys.argv) != 3:
6464
print("Usage: python clean_parameters.py <template_path> <parameters_path>")
6565
sys.exit(1)
66-
66+
6767
template_path = Path(sys.argv[1])
6868
parameters_path = Path(sys.argv[2])
69-
69+
7070
if not template_path.exists():
7171
print(f"Error: Template file {template_path} not found")
7272
sys.exit(1)
73-
73+
7474
if not parameters_path.exists():
75-
print(f"Error: Parameters file {parameters_path} not found")
75+
print(f"Error: Parameters file {parameters_path} not found")
7676
sys.exit(1)
77-
77+
7878
success = filter_parameters_file(template_path, parameters_path)
7979
sys.exit(0 if success else 1)

src/emd/cfn/shared/openai_router/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func isPartialJSON(s string) bool {
336336
if strings.HasPrefix(s, "[") && !strings.HasSuffix(s, "]") {
337337
return true
338338
}
339-
339+
340340
// Count open vs close braces
341341
openBraces := strings.Count(s, "{") + strings.Count(s, "[")
342342
closeBraces := strings.Count(s, "}") + strings.Count(s, "]")
@@ -384,7 +384,7 @@ func requestHandler(c *gin.Context) {
384384
var payload struct {
385385
Model string `json:"model"`
386386
}
387-
387+
388388
// Try to parse model from payload
389389
if err := json.Unmarshal(inputBytes, &payload); err == nil && payload.Model != "" {
390390
// Use model from payload if present
@@ -411,13 +411,13 @@ func requestHandler(c *gin.Context) {
411411
c.JSON(400, gin.H{"error": "Invalid JSON payload"})
412412
return
413413
}
414-
414+
415415
// Extract modelID from model field (remove modelTag if present)
416416
if modelVal, ok := payloadData["model"].(string); ok {
417417
modelParts := strings.Split(modelVal, "/")
418418
payloadData["model"] = modelParts[0] // Keep only modelID
419419
}
420-
420+
421421
modifiedBytes, err := json.Marshal(payloadData)
422422
if err != nil {
423423
c.JSON(500, gin.H{"error": "Failed to modify payload"})
@@ -450,7 +450,7 @@ func requestHandler(c *gin.Context) {
450450
// Start streaming in a goroutine
451451
go func() {
452452
defer closeOnce.Do(func() { close(stream) })
453-
453+
454454
ctx, cancel := context.WithTimeout(c.Request.Context(), 5*time.Minute)
455455
defer cancel()
456456

@@ -470,8 +470,8 @@ func requestHandler(c *gin.Context) {
470470

471471
eventStream := resp.GetStream()
472472
defer eventStream.Close()
473-
474-
473+
474+
475475
for event := range eventStream.Events() {
476476
switch e := event.(type) {
477477
case *sagemakerruntime.PayloadPart:
@@ -482,15 +482,15 @@ func requestHandler(c *gin.Context) {
482482

483483
chunk := string(e.Bytes)
484484
log.Printf("[DEBUG] Received chunk: %s", chunk)
485-
485+
486486
// Check for finish_reason=stop to end stream
487-
if strings.Contains(chunk, `"finish_reason":"stop"`) ||
487+
if strings.Contains(chunk, `"finish_reason":"stop"`) ||
488488
strings.Contains(chunk, `"finish_reason": "stop"`) {
489489
log.Printf("[DEBUG] Detected finish_reason=stop, ending stream")
490490
// stream <- []byte("data: " + chunk + "\n\n")
491491
break
492492
}
493-
493+
494494
// Forward chunk as-is in SSE format
495495
stream <- []byte(chunk + "\n\n")
496496
case *sagemakerruntime.InternalStreamFailure:

0 commit comments

Comments
 (0)