Skip to content

Commit c3dc6d7

Browse files
committed
EnglishComment
1 parent 0a750a8 commit c3dc6d7

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

script/agent-cloudformation/bedrock-agent.yaml

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ Resources:
8989
9090
def lambda_handler(event, context):
9191
"""
92-
Bedrock을 활용한 의미 기반 영상 검색
92+
Semantic video search using Bedrock
9393
"""
9494
95-
print(f"📥 받은 이벤트: {json.dumps(event, default=str)}")
95+
print(f"📥 Received event: {json.dumps(event, default=str)}")
9696
9797
try:
9898
api_path = event.get('apiPath', '')
@@ -115,7 +115,7 @@ Resources:
115115
query = prop.get('value', '')
116116
break
117117
118-
print(f"🔎 사용자 질문: {query}")
118+
print(f"🔎 User query: {query}")
119119
result = search_with_bedrock(dynamodb, bedrock, query)
120120
121121
else:
@@ -139,13 +139,13 @@ Resources:
139139
}
140140
}
141141
142-
print(f"📤 반환 응답: {json.dumps(response, ensure_ascii=False, default=str)}")
142+
print(f"📤 Return response: {json.dumps(response, ensure_ascii=False, default=str)}")
143143
return response
144144
145145
except Exception as e:
146-
print(f"❌ 오류 발생: {str(e)}")
146+
print(f"❌ Error occurred: {str(e)}")
147147
import traceback
148-
print(f"📋 스택 트레이스: {traceback.format_exc()}")
148+
print(f"📋 Stack trace: {traceback.format_exc()}")
149149
150150
return {
151151
'messageVersion': '1.0',
@@ -163,51 +163,51 @@ Resources:
163163
}
164164
165165
def search_with_bedrock(dynamodb, bedrock, query):
166-
"""Bedrock Nova Pro로 질문 이해 후 DynamoDB 검색"""
166+
"""Understand question with Bedrock Nova Pro and search DynamoDB"""
167167
168168
table_name = os.environ['DYNAMODB_TABLE_NAME']
169169
170170
try:
171-
# 1. DynamoDB에서 모든 활성 강의 가져오기
171+
# 1. Get all active courses from DynamoDB
172172
table = dynamodb.Table(table_name)
173173
response = table.scan(
174174
FilterExpression=Attr('class_flag').ne(10) & (Attr('class_flag').eq(0) | Attr('class_flag').not_exists())
175175
)
176176
177177
all_courses = response.get('Items', [])
178-
print(f"📊 전체 강의 수: {len(all_courses)}")
178+
print(f"📊 Total courses: {len(all_courses)}")
179179
180180
if not all_courses:
181181
return {
182182
'statusCode': 200,
183183
'body': json.dumps({
184184
'courses_found': 0,
185185
'courses': [],
186-
'message': '등록된 강의가 없습니다.'
186+
'message': 'No courses registered.'
187187
}, ensure_ascii=False)
188188
}
189189
190-
# 2. 강의 목록을 텍스트로 변환 (최대 50개)
190+
# 2. Convert course list to text (max 50)
191191
courses_text = "\n\n".join([
192-
f"강의 {i+1}:\n제목: {c.get('name', '')}\n설명: {c.get('description', '')}\n난이도: {c.get('difficulty', 'intermediate')}"
192+
f"Course {i+1}:\nTitle: {c.get('name', '')}\nDescription: {c.get('description', '')}\nDifficulty: {c.get('difficulty', 'intermediate')}"
193193
for i, c in enumerate(all_courses[:50])
194194
])
195195
196-
# 3. Bedrock Nova Pro 프롬프트
197-
prompt = f"""사용자 질문: {query}
196+
# 3. Bedrock Nova Pro prompt
197+
prompt = f"""User question: {query}
198198
199-
다음은 사용할 수 있는 AWS 강의 목록입니다:
199+
Here is the list of available AWS courses:
200200
201201
{courses_text}
202202
203-
위 강의 중에서 사용자 질문에 가장 적합한 강의를 최대 3개 선택하고, 각 강의 번호만 JSON 배열로 반환하세요.
204-
예시: {{"selected": [1, 3, 5]}}
203+
Select up to 3 courses that best match the user's question from the above list, and return only the course numbers as a JSON array.
204+
Example: {{"selected": [1, 3, 5]}}
205205
206-
만약 적합한 강의가 없다면 빈 배열을 반환하세요: {{"selected": []}}
206+
If no suitable courses are found, return an empty array: {{"selected": []}}
207207
208-
JSON만 반환하고 다른 설명은 하지 마세요."""
208+
Return only JSON without any other explanation."""
209209
210-
# 4. Bedrock Nova Pro 호출
210+
# 4. Call Bedrock Nova Pro
211211
body = json.dumps({
212212
"messages": [
213213
{
@@ -228,12 +228,12 @@ Resources:
228228
229229
response_body = json.loads(bedrock_response['body'].read())
230230
bedrock_text = response_body['output']['message']['content'][0]['text']
231-
print(f"🤖 Bedrock 응답: {bedrock_text}")
231+
print(f"🤖 Bedrock response: {bedrock_text}")
232232
233-
# 5. JSON 추출
233+
# 5. Extract JSON
234234
selected_indices = json.loads(bedrock_text)['selected']
235235
236-
# 6. 선택된 강의 정보 구성
236+
# 6. Build selected course information
237237
selected_courses = []
238238
for idx in selected_indices:
239239
if 0 < idx <= len(all_courses):
@@ -247,28 +247,28 @@ Resources:
247247
'difficulty': str(course.get('difficulty', 'intermediate'))
248248
})
249249
250-
message = f"'{query}' 관련 강의 {len(selected_courses)}개를 찾았습니다." if selected_courses else f"'{query}' 관련 강의를 찾지 못했습니다."
250+
message = f"Found {len(selected_courses)} courses related to '{query}'." if selected_courses else f"No courses found related to '{query}'."
251251
252252
result_data = {
253253
'courses_found': len(selected_courses),
254254
'courses': selected_courses,
255255
'message': message,
256256
'traces': [
257-
{'type': 'preprocessing', 'content': f"🔍 '{query}' 검색 시작", 'timestamp': ''},
258-
{'type': 'function_call', 'content': f'⚡ Bedrock Nova Pro로 {len(all_courses)}개 강의 분석', 'timestamp': ''},
259-
{'type': 'observation', 'content': f'✅ {len(selected_courses)}개 강의 선택 완료', 'timestamp': ''}
257+
{'type': 'preprocessing', 'content': f"🔍 Started searching for '{query}'", 'timestamp': ''},
258+
{'type': 'function_call', 'content': f'⚡ Analyzing {len(all_courses)} courses with Bedrock Nova Pro', 'timestamp': ''},
259+
{'type': 'observation', 'content': f'✅ Completed selection of {len(selected_courses)} courses', 'timestamp': ''}
260260
]
261261
}
262262
263-
print(f"✅ 검색 완료: {len(selected_courses)}개 강의 발견")
263+
print(f"✅ Search completed: {len(selected_courses)} courses found")
264264
265265
return {
266266
'statusCode': 200,
267267
'body': json.dumps(result_data, ensure_ascii=False)
268268
}
269269
270270
except Exception as e:
271-
print(f"❌ 검색 오류: {str(e)}")
271+
print(f"❌ Search Error: {str(e)}")
272272
import traceback
273273
print(traceback.format_exc())
274274
return {

0 commit comments

Comments
 (0)