Repository navigation
Expand file tree
/
Copy pathfix_model_codes.py
More file actions
88 lines (67 loc) · 2.74 KB
/
Copy pathfix_model_codes.py
File metadata and controls
88 lines (67 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""Fix script to update model codes from literal names to registry codes.
This script updates the basic_model_code and premium_model_code for coaching topics
that have the old literal model names instead of the new model registry codes.
Migration: claude-3-5-sonnet-20241022 -> CLAUDE_3_5_SONNET_V2
"""
import asyncio
import boto3
from coaching.src.core.config_multitenant import settings
from coaching.src.repositories.topic_repository import TopicRepository
async def fix_model_codes():
"""Update model codes for all coaching topics."""
print("=" * 80)
print("FIX COACHING TOPIC MODEL CODES")
print("=" * 80)
print()
# Initialize DynamoDB
dynamodb_resource = boto3.resource("dynamodb", region_name=settings.aws_region)
topic_repo = TopicRepository(
dynamodb_resource=dynamodb_resource,
table_name=settings.topics_table,
)
# Get all active topics
all_topics = await topic_repo.list_all(include_inactive=False)
# Find topics with old model names
topics_to_fix = []
for t in all_topics:
needs_fix = False
if t.basic_model_code == "claude-3-5-sonnet-20241022":
needs_fix = True
if t.premium_model_code == "claude-3-5-sonnet-20241022":
needs_fix = True
if needs_fix:
topics_to_fix.append(t)
print(f"Found {len(topics_to_fix)} topics to fix:\n")
if not topics_to_fix:
print("No topics need fixing!")
return
for topic in topics_to_fix:
print(f" - {topic.topic_id}: {topic.topic_name}")
print(f" Current basic_model_code: {topic.basic_model_code}")
print(f" Current premium_model_code: {topic.premium_model_code}")
print(" New codes: CLAUDE_3_5_SONNET_V2")
print()
# Auto-confirm for automation
print("Auto-confirming update...")
print()
print()
print("Updating topics...")
for topic in topics_to_fix:
try:
# Update the model codes
if topic.basic_model_code == "claude-3-5-sonnet-20241022":
topic.basic_model_code = "CLAUDE_3_5_SONNET_V2"
if topic.premium_model_code == "claude-3-5-sonnet-20241022":
topic.premium_model_code = "CLAUDE_3_5_SONNET_V2"
await topic_repo.update(topic=topic)
print(f" [SUCCESS] Updated {topic.topic_id}")
except Exception as e:
print(f" [ERROR] Failed to update {topic.topic_id}: {e}")
print()
print("=" * 80)
print("COMPLETE")
print("=" * 80)
print()
print("Please test the coaching session endpoints to verify the fix.")
if __name__ == "__main__":
asyncio.run(fix_model_codes())